[Bug] Claude Code overrides user default SHELL environment variable
Bug Description
Claude Code overrides user default SHELL
Environment Info
- Platform: darwin
- Terminal: iTerm.app
- Version: 2.1.37
- Feedback ID: 09397305-34ef-462a-9b70-204f85b7b9bd
Claude Code Shell Investigation
Problem
Claude Code sessions were using /bin/zsh despite the developer machine being configured entirely for bash.
Environment
- Login shell (dscl):
/opt/homebrew/bin/bash(GNU Bash 5.3.9) /etc/shells:/opt/homebrew/bin/bashis listed- User's actual shell usage: Always bash, never zsh
- Claude Code session shell:
/bin/zsh(5.9)
Root Cause
Claude Code has its own shell detection logic that does not simply read the user's login shell from dscl or honor $SHELL as set by the login process. Its automatic detection was resolving to /bin/zsh — likely because macOS defaults to zsh since Catalina, and Claude Code's detection logic may prioritize the system default over the user's configured login shell.
Fix
Added CLAUDE_CODE_SHELL to ~/.claude/settings.json:
{
"env": {
"CLAUDE_CODE_SHELL": "/opt/homebrew/bin/bash"
}
}
This environment variable explicitly tells Claude Code which shell to use for all Bash tool invocations, overriding the automatic detection.
Implications
- The current session (at time of fix) continues using zsh — restart required
- All future sessions will use
/opt/homebrew/bin/bash - Shell-specific syntax differences (e.g.,
shoptin bash vssetoptin zsh, array indexing,BASH_SOURCEvsZSH_EVAL_CONTEXT) may have caused subtle issues in prior sessions - The
BASH_ENVsetting insettings.json(pointing to~/.config/bash/functions.sh) was likely not being sourced correctly under zsh, sinceBASH_ENVis a bash-specific variable
Related Settings
| Variable | Purpose |
|----------|---------|
| CLAUDE_CODE_SHELL | Override shell binary for Bash tool |
| CLAUDE_CODE_SHELL_PREFIX | Wrap all bash commands with a prefix |
| CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR | Return to project dir after each command |
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗