[BUG] Shell snapshot generates unquoted PATH on macOS with spaces in home directory
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When the macOS user's home directory path contains spaces (e.g., /Users/Nan's document), Claude Code generates shell snapshot files with unquoted PATH export statements, causing all Bash tool invocations to fail with "command not found" errors.
The generated snapshot file at ~/.claude/shell-snapshots/snapshot-zsh-*.sh contains:
export PATH=/Users/Nans document/Library/pnpm:/Users/Nans document/.npm-global/bin:...
This causes the shell to fail parsing the export statement because paths with spaces are not quoted, resulting in:
/Users/Nan's document/.claude/shell-snapshots/snapshot-zsh-*.sh:export:25: not valid in this context: document/Library/pnpm:/Users/Nans
Impact: All Bash tool invocations fail - commands like openclaw, npm, gh, rm, head cannot be executed. This completely breaks Claude Code's ability to run any shell commands.
What Should Happen?
The PATH export statement in the snapshot file should be properly quoted:
export PATH="/Users/Nan's document/Library/pnpm:/Users/Nan's document/.npm-global/bin:..."
This would allow the shell to correctly parse paths containing spaces and special characters.
Error Messages/Logs
/Users/Nan's document/.claude/shell-snapshots/snapshot-zsh-1773371788164-6ea15a.sh:export:25: not valid in this context: document/Library/pnpm:/Users/Nans
(eval):1: command not found: openclaw
(eval):1: command not found: rm
(eval):1: command not found: head
Error Messages/Logs
Steps to Reproduce
- Create a macOS user account with a space in the username (e.g., "John Doe" or "Nan's document")
- The home directory becomes
/Users/John Doeor/Users/Nan's document - Install and run Claude Code
- Try to execute any Bash command (e.g., ask Claude to run
lsor any file operation) - Observe that all commands fail with "command not found"
- Check
~/.claude/shell-snapshots/snapshot-zsh-*.shline 25 - Observe the unquoted PATH export statement
Note: The user's ~/.zshrc correctly quotes all PATH additions:
export PATH="/Users/Nan's document/.antigravity/antigravity/bin:$PATH"
export PATH="$HOME/.npm-global/bin:$PATH"
export PNPM_HOME="/Users/Nan's document/Library/pnpm"
But the snapshot generation logic doesn't preserve these quotes when writing to the snapshot file.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.74 (VSCode extension: anthropic.claude-code-2.1.74-darwin-arm64)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
Root Cause
The shell snapshot generation logic reads the current $PATH from the shell environment and writes it to the snapshot file without quoting, causing paths with spaces to be split into multiple arguments during shell parsing.
Workaround
Manually edit the snapshot file to add quotes around the PATH value:
# Before (broken)
export PATH=/Users/Nans document/Library/pnpm:...
# After (fixed)
export PATH="/Users/Nan's document/Library/pnpm:..."
However, this is tedious because the snapshot file gets regenerated with the same bug on every new shell session.
Related Issues
- #16451 - Similar issue on Windows with spaces in username path (closed as duplicate)
- #4999 - Malformed alias in shell snapshot (Windows + zsh)
However, this is a macOS-specific variant that hasn't been reported yet.
Suggested Fix
When generating shell snapshot files, ensure that the PATH export statement is properly quoted:
export PATH="$PATH"
Or properly escape/quote individual path components before concatenating them into the export statement.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗