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

Bash tool misleadingly executes in user's default shell instead of actual bash

Open ashebanow opened this issue 6 months ago • 2 comments

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:

  1. Execute in an isolated bash environment (bash -c "command"), or
  2. 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

  1. Set zsh as default shell on macOS
  2. Add problematic content to .zshenv (e.g., ---@type zsh)
  3. Use Claude Code's "Bash" tool to run any command
  4. 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

ashebanow avatar Jun 22 '25 14:06 ashebanow

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!

daaain avatar Jun 23 '25 23:06 daaain

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

yixiandu-momenta avatar Jun 28 '25 09:06 yixiandu-momenta

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/2902
  2. https://github.com/anthropics/claude-code/issues/2632
  3. 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

github-actions[bot] avatar Aug 16 '25 06:08 github-actions[bot]

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

github-actions[bot] avatar Aug 21 '25 09:08 github-actions[bot]

Your bot closed this as a dup of this other bug, then closed the other bug as a dup of this one!

ashebanow avatar Aug 21 '25 14:08 ashebanow

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.

github-actions[bot] avatar Aug 30 '25 14:08 github-actions[bot]