Shell spawned as non-login shell, missing PATH from .zprofile/.bash_profile
Problem
Claude Code spawns shells in non-login mode. On macOS, this means ~/.zprofile (zsh) and ~/.bash_profile (bash) are not sourced, so environment variables set there — most notably PATH — are missing.
This is a common source of confusion: commands that work fine in Terminal.app or iTerm2 (which default to login shells) fail in Claude Code with "command not found".
Reproduction
- Install any tool via Homebrew (e.g.
brew install gauche) - Confirm it works in Terminal:
gosh -V→ works - In Claude Code, run the same command →
gosh not found - Check PATH in Claude Code: only
/usr/bin:/bin:/usr/sbin:/sbin
Root cause
Homebrew's installer writes eval "$(/opt/homebrew/bin/brew shellenv)" to ~/.zprofile by default. This is the standard macOS convention — login-time environment setup goes in .zprofile/.bash_profile, not .zshrc/.bashrc.
macOS terminal emulators (Terminal.app, iTerm2, Ghostty, etc.) all default to spawning login shells for this reason.
Claude Code spawns a non-login shell, so .zprofile is never read.
Impact
This affects not just Homebrew, but any tool that follows the standard macOS convention:
- Homebrew (
/opt/homebrew/bin) - pyenv / nvm / rbenv (often initialized in
.zprofile) - cargo / go / other language toolchains
Users must manually duplicate their .zprofile setup into .zshrc as a workaround.
Expected behavior
Claude Code should spawn login shells (or equivalent) on macOS so that the user's full environment is available, consistent with how terminal emulators behave.
Workaround
Add the following to ~/.zshrc:
if [[ ":$PATH:" != *":/opt/homebrew/bin:"* ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
Environment
- macOS (Apple Silicon)
- Shell: zsh
- Claude Code (CLI)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗