Shell snapshot ignores ZDOTDIR — sources hardcoded ~/.zshrc instead of $ZDOTDIR/.zshrc
Bug Description
The shell snapshot generator hardcodes the zsh config path to ~/.zshrc (via path.join(os.homedir(), ".zshrc")), ignoring the ZDOTDIR environment variable. Users with ZDOTDIR set (e.g., to ~/.config/zsh) have their .zshrc at $ZDOTDIR/.zshrc, which Claude Code never sources. This means the snapshot misses all environment setup from the user's actual shell config.
Root Cause
In the compiled source, the config file resolver is:
function hm6(H) {
let _ = H.includes("zsh") ? ".zshrc" : H.includes("bash") ? ".bashrc" : ".profile";
return path.join(os.homedir(), _);
}
This always returns $HOME/.zshrc. It should check process.env.ZDOTDIR first:
function hm6(H) {
let _ = H.includes("zsh") ? ".zshrc" : H.includes("bash") ? ".bashrc" : ".profile";
let dir = H.includes("zsh") && process.env.ZDOTDIR ? process.env.ZDOTDIR : os.homedir();
return path.join(dir, _);
}
Environment
- Claude Code version: 2.1.87 (native binary, macOS arm64)
- OS: macOS 15 (Sequoia), Apple Silicon
- Shell: zsh with
ZDOTDIR=/Users/sauyon/.config/zsh - Config managed by: nix home-manager (sets
ZDOTDIRand places.zshrcat$ZDOTDIR/.zshrc)
Steps to Reproduce
- Set
ZDOTDIRto a custom directory (e.g.,~/.config/zsh) - Place your
.zshrcat$ZDOTDIR/.zshrc(standard zsh behavior) - Start Claude Code
- Inspect the generated snapshot at
~/.claude/shell-snapshots/snapshot-zsh-*.sh - Observe that it does not contain any environment setup from your
.zshrc
Observed Behavior
Debug output shows:
Looking for shell config file: /Users/sauyon/.zshrc
Shell config file not found: /Users/sauyon/.zshrc, creating snapshot with Claude Code defaults only
The snapshot contains only a minimal export PATH=/usr/bin:/bin:/usr/sbin:/sbin and no user environment.
Expected Behavior
Claude Code should check ZDOTDIR when resolving the zsh config path, consistent with how zsh itself resolves it. The snapshot should source $ZDOTDIR/.zshrc and capture the resulting environment.
Impact
All tools installed via the user's shell config (nix-profile, homebrew, mise, cargo, etc.) are unavailable to the Bash tool. This particularly affects nix/home-manager users who commonly use ZDOTDIR for XDG-compliant config layout.
Related Issues
- #11635 — same bug, closed as not planned after auto-close bot
- #31799 — related: snapshot PATH not properly resolved
- #42248 — related: Desktop app ignores PATH from all sources
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗