Shell snapshot hardcodes process.env.PATH instead of capturing shell's PATH
Bug
When Claude Code is launched from the macOS desktop app, the Bash tool has a minimal PATH (/usr/bin:/bin:/usr/sbin:/sbin). Commands like npm, node, pnpm, brew, gh, and bun are not found.
Version: 2.1.87 (desktop app)
Platform: macOS (Darwin 25.3.0)
Likely Root Cause
This appears to be a shell snapshot bug.
Claude Code creates a shell snapshot using a login shell, and the snapshot does contain functions and aliases from shell startup files. However, the final snapshot still hardcodes the minimal GUI PATH instead of preserving the login shell’s enriched PATH.
Based on inspection of the installed binary, the snapshot generator appears to use the parent app process’s PATH rather than the PATH produced inside the login shell after startup files are sourced.
Evidence
The generated snapshot file ends with:
export PATH=/usr/bin\:/bin\:/usr/sbin\:/sbin
Yet the same snapshot also contains functions and aliases from .zshrc such as oh-my-zsh aliases and an nvm wrapper, which strongly suggests the login shell startup files were sourced.
Outside Claude Code, running:
zsh -lc 'echo $PATH'
returns the expected full PATH including Homebrew, NVM, Bun, Cargo, etc.
Inside Claude Code, running:
echo $PATH
returns:
/usr/bin:/bin:/usr/sbin:/sbin
and then:
npm --version
pnpm --version
both fail with command not found.
Expected Behavior
The shell snapshot should record the PATH as it exists inside the login shell after startup files have been sourced, not the minimal GUI app PATH.
Suggested Fix
When writing the snapshot, capture $PATH from within the shell session that generated the snapshot, instead of using the parent process environment.
Reproduction
- Launch Claude Code from the macOS desktop app
- Open a session
- Run
echo $PATHin the Bash tool - Observe:
/usr/bin:/bin:/usr/sbin:/sbin - Run
npm --version - Observe:
command not found
Additional Context
- Deleting
~/.claude/shell-snapshots/and restarting does not fix it. A freshly regenerated snapshot still contains the same minimal PATH. - The generated snapshot still includes shell functions and aliases, so this does not look like a complete failure to load shell config.
- Outside Claude Code, a normal
zsh -lcresolvesnode,npm,pnpm,npx,brew, andghcorrectly. - Current workaround: a
PreToolUsehook that detects the minimal PATH case and prepends a correct login-shell PATH before Bash commands run. - I do not believe
CLAUDE_CODE_SHELL_PREFIXaffects snapshot generation based on inspection of the installed binary, but I have not confirmed that from source.
Notes
This does not appear to be a stale snapshot corruption issue, because the bug reproduces immediately with a brand-new snapshot after deleting the old snapshot cache.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗