Shell snapshot parse errors from captured zsh function definitions
Description
Claude Code's shell snapshot mechanism captures zsh function definitions that contain quoting patterns incompatible with being re-sourced. Every shell command executed through Claude Code prints parse errors to stderr like:
/Users/.../.claude/shell-snapshots/snapshot-zsh-....sh:2873: parse error near `<'
The errors are cosmetic (commands still execute correctly), but they appear on every single tool invocation.
Root Cause
When Claude Code snapshots the zsh shell state, it serializes function bodies verbatim. Several common zsh functions contain syntax that breaks when the snapshot file is later sourced:
compdef(zsh completion system) — contains<widget>angle brackets in aprintstatement that get interpreted as redirections:
````
print -u2 "$0: compdef -K requires <widget> <comp-widget> <key>"
- nvm functions — nested command substitutions with escaped backticks inside double quotes:
``|'//g"
command sed -e 's/^\ *//g' -Ee "s/\
```
- User-defined functions with multi-line strings — functions containing heredoc-like constructs or multi-line double-quoted strings with embedded escaped quotes (e.g., emacsclient calls with Lisp code).
Deleting the snapshot and letting it regenerate produces the same errors, since the same functions get captured the same way.
Environment
- macOS (Darwin 25.1.0, arm64)
- zsh 5.9
- Shell plugins: prezto, zinit, powerlevel10k, nvm, fzf, pyenv
- Claude Code using zsh shell snapshots
Expected Behavior
Shell snapshots should re-source without parse errors, either by properly escaping captured function bodies or by excluding functions from the zsh completion system and other sources that are known to contain problematic quoting patterns.
Workaround
None permanent. Manual edits to the snapshot file are overwritten on regeneration. The errors don't affect command execution.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗