Bash tool's zsh shell does not source ~/.zshenv on macOS
Summary
On macOS, Claude Code's Bash tool runs commands in a zsh shell (\\$0=/bin/zsh\, \SHELL=/bin/zsh\), but that shell does not source \~/.zshenv\ at startup. This is contrary to zsh's documented behavior: \.zshenv\ is sourced for every zsh invocation unless \-f\ or \--no-rcs\ is passed.
Impact
Any PATH additions, environment variables, or bootstrap logic placed in \~/.zshenv\ (the canonical place for non-interactive shells) is silently missing from Bash tool commands. This breaks:
- Personal scripts on PATH
- Credential bootstrapping (op service account, \
op inject\, etc.) - Tool wrappers that users put in \
~/.zshenv\specifically for non-interactive contexts - Anything that relied on zsh's documented \"sourced for all invocations\" contract
Repro
- Add to \
~/.zshenv\:
\\\sh\
export PATH=\"\$HOME/bin:\$PATH\"
export MY_TEST_VAR=\"hello\"
\\
- Confirm interactive zsh picks it up: \
zsh -c 'echo \$MY_TEST_VAR'\prints \hello\. - In Claude Code, run a Bash tool call: \
echo \$MY_TEST_VAR\— prints blank. - \
zsh -c 'echo \$MY_TEST_VAR'\inside the Bash tool — prints \hello\correctly, confirming the sub-invocation does source \.zshenv\properly.
Diagnosis
The parent shell Claude Code's Bash tool uses is launched in a way that bypasses \.zshenv\. Spawning a child \zsh -c\ from within that shell works correctly, so the issue is specifically at the parent shell's init.
My theory: the shell is invoked with \--no-rcs\ or \-f\, or its \ZDOTDIR\ is set to a location without a \.zshenv\, or the PATH is reset after \.zshenv\ runs.
Workaround
Prefix commands that need \.zshenv\ state with \source ~/.zshenv && …\ or wrap in \zsh -c '…'\.
Environment
- macOS 26 (Darwin 25.5.0)
- Shell: /bin/zsh (system default)
- Claude Code: Opus 4.7 (1M context) CLI
- \
.zshenv\contains standard PATH augmentation and env bootstrap logic
Suggested Fix
Ensure the parent shell either (a) does not pass \--no-rcs\, (b) sources \.zshenv\ explicitly via \source\, or (c) documents clearly that only explicitly-exported env via the Bash tool wrapper is available, and recommends \~/.bashrc\-style init for Bash compatibility.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗