Bash tool misleadingly executes in user's default shell instead of actual bash
Description:
Summary
The "Bash" tool in Claude Code claims to execute bash commands but actually runs commands in the user's default shell environment, triggering shell initialization files and potentially causing unexpected behavior.
Expected Behavior
When using the "Bash" tool, commands should either:
- Execute in an isolated bash environment (bash -c "command"), or
- The tool should be renamed/described accurately (e.g., "Shell" tool)
Actual Behavior
- Tool is named "Bash" and descriptions reference "bash commands"
- Commands actually execute in user's default shell (zsh in this case)
- Shell initialization files like .zshenv are sourced during execution
- This can cause errors unrelated to the intended command
Steps to Reproduce
- Set zsh as default shell on macOS
- Add problematic content to .zshenv (e.g., ---@type zsh)
- Use Claude Code's "Bash" tool to run any command
- Observe that .zshenv gets executed and produces errors
Evidence
⏺ Bash(rm /path/to/file) ⎿ /Users/user/.zshenv:1: command not found: ---@type
The error shows .zshenv was executed despite claiming to use bash.
Environment
- Platform: macOS
- Default shell: zsh
- Claude Code version: [current]
Suggested Fix
Either:
- Execute commands with bash -c "command" for true bash isolation
- Rename tool to "Shell" and update descriptions to be accurate
I think I like that it's using the default shell and has the same environment as I do (to mitigate a lot of mysterious hard to debug errors), but 100% agree that it should be called Shell tool and Claude should be made aware what is the user's default shell in case it's not zsh!
but I noted that Claude Code's bash environment differs from mine.
Claude Code could run rg command which is not installed in my env
Found 3 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/2902
- https://github.com/anthropics/claude-code/issues/2632
- https://github.com/anthropics/claude-code/issues/1872
This issue will be automatically closed as a duplicate in 3 days.
- If your issue is a duplicate, please close it and 👍 the existing issue instead
- To prevent auto-closure, add a comment or 👎 this comment
🤖 Generated with Claude Code
This issue has been automatically closed as a duplicate of #2902.
If this is incorrect, please re-open this issue or create a new one.
🤖 Generated with Claude Code
Your bot closed this as a dup of this other bug, then closed the other bug as a dup of this one!
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.