Shell snapshot uses unguarded $ZSH_VERSION, breaks set -u (nounset)
Resolved 💬 4 comments Opened May 26, 2026 by nelson2005 Closed Jul 3, 2026
Summary
Claude Code's shell snapshot scripts reference $ZSH_VERSION without a default-value guard, which causes set -u (nounset) to fail when running in bash.
Reproduction
- In a Claude Code session, run any Bash tool call that starts with
set -euo pipefail - If the shell snapshot's functions are invoked during initialization, the shell exits with:
/home/<user>/.claude/shell-snapshots/snapshot-bash-<id>.sh: line 129: ZSH_VERSION: unbound variable
- This is intermittent — depends on whether the snapshot functions get triggered during shell init.
Root cause
The snapshot script contains three instances of:
if [[ -n $ZSH_VERSION ]]; then
(lines 93, 111, 129 in the generated snapshot)
In bash, $ZSH_VERSION is never defined. Under normal bash this evaluates to false silently, but under set -u (nounset) it's an error because the variable doesn't exist.
Fix
Replace all three instances with:
if [[ -n ${ZSH_VERSION:-} ]]; then
The :- default-value syntax returns empty string when the variable is unset, satisfying nounset.
Environment
- Claude Code CLI (npm package
@anthropic-ai/claude-code) - bash shell on Linux (WSL2 Ubuntu, kernel 6.6.87.2-microsoft-standard-WSL2)
- The snapshot file is auto-generated at
~/.claude/shell-snapshots/
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗