claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Bash tool pollutes user shell history with internal wrapper commands

Open AdamDrewsTR opened this issue 2 months ago • 2 comments

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Description:

Claude Code's Bash tool pollutes the user's ~/.bash_history with internal command wrapper markers, making shell history essentially unusable across all terminal sessions.

Environment:

  • Claude Code version: v2.0.55
  • Shell: bash
  • OS: macOS (Darwin 23.6.0)

Issue:

When Claude Code executes bash commands, it wraps them with markers like: { echo BEGIN___COMMAND_OUTPUT_MARKER; cd /path && some_command; EC=$?; echo "BEGIN___COMMAND_DONE_MARKER$EC"; }

These wrapped commands are written to ~/.bash_history, causing:

  1. Severe history pollution: 96% of history (480/500 lines) were Claude Code wrappers in my case
  2. System-wide impact: All bash terminals share the same history file, so every terminal session is affected
  3. Unusable history: Ctrl+R search and up-arrow navigation become nearly impossible

What Should Happen?

Expected behavior:

Claude Code's internal command execution should not write to user's personal shell history.

Suggested solutions:

  1. Set HISTFILE=/dev/null before executing wrapped commands
  2. Use set +o history to disable history recording for internal commands
  3. Use a separate history file like ~/.claude_code_history
  4. Unset HISTFILE temporarily during command execution

Workaround:

Users can add this to ~/.bashrc: export HISTIGNORE="BEGIN___COMMAND_OUTPUT_MARKER:BEGIN___COMMAND_DONE_MARKER"

And clean existing pollution with: grep -v "___BEGIN___COMMAND" ~/.bash_history > ~/.bash_history.clean && mv ~/.bash_history.clean ~/.bash_history

Impact: High - affects all Claude Code users with bash shells, severely degrades terminal UX

Error Messages/Logs


Steps to Reproduce

eproduction Steps:

  1. Check your current bash history: wc -l ~/.bash_history grep -c "___BEGIN___COMMAND" ~/.bash_history
  2. Note the baseline numbers.
  3. Start a Claude Code session in any project: cd /path/to/any/project claude
  4. Ask Claude Code to run several bash commands:

Run git status Run ls -la Run grep -r "function" src/ | head -10

  1. Exit Claude Code and check history again: exit wc -l ~/.bash_history grep -c "___BEGIN___COMMAND" ~/.bash_history
  2. Open a new bash terminal and press up-arrow or Ctrl+R: - You'll see Claude Code's wrapper commands instead of your actual command history - Example pollution: { echo BEGIN___COMMAND_OUTPUT_MARKER; cd /path && grep -r "function" src/ | head -10; EC=$?; echo "BEGIN___COMMAND_DONE_MARKER$EC"; }

Expected Result:

  • Only actual user commands in ~/.bash_history
  • Clean, usable command history across all terminals

Actual Result:

  • ~/.bash_history filled with Claude Code wrapper commands
  • In severe cases, 90%+ of history is pollution
  • History search (Ctrl+R) and navigation (up-arrow) become unusable system-wide

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.0.55

Platform

Other

Operating System

macOS

Terminal/Shell

Other

Additional Information

No response

AdamDrewsTR avatar Nov 30 '25 19:11 AdamDrewsTR

Comparison to Similar Tools:

GitHub Copilot CLI has its own history issues (https://github.com/github/gh-copilot/issues/65, https://github.com/github/gh-copilot/issues/99), but does NOT pollute user history with internal execution wrappers. Their issues involve:

  • History corruption/deletion bugs
  • Shell function wrapper compatibility problems

Claude Code's issue is unique: internal command execution mechanics leak into user's personal history and persist indefinitely.

Expected Behavior:

Claude Code's internal command wrappers should:

  1. Never write to ~/.bash_history
  2. Execute in a history-disabled context
  3. Be invisible to the user's shell history across all terminals

Impact: Critical

  • Affects 100% of Claude Code users with bash shells
  • Pollution persists indefinitely, even when not actively using Claude Code
  • Severely degrades terminal UX system-wide (history search, navigation)
  • Can reach 90%+ pollution rate with regular Claude Code usage
  • No automatic cleanup - requires manual intervention

AdamDrewsTR avatar Nov 30 '25 19:11 AdamDrewsTR

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 31 '25 10:12 github-actions[bot]