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

Resolved 💬 4 comments Opened Nov 30, 2025 by AdamDrewsTR Closed Jan 30, 2026

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

  1. Note the baseline numbers.
  2. Start a Claude Code session in any project:

cd /path/to/any/project
claude

  1. 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

  1. 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_

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗