claude-code - 💡(How to fix) Fix Shell snapshot uses unguarded $ZSH_VERSION, breaks set -u (nounset)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

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.

Error Message

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.

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 Action

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.

Code Example

/home/<user>/.claude/shell-snapshots/snapshot-bash-<id>.sh: line 129: ZSH_VERSION: unbound variable

---

if [[ -n $ZSH_VERSION ]]; then

---

if [[ -n ${ZSH_VERSION:-} ]]; then
RAW_BUFFERClick to expand / collapse

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

  1. In a Claude Code session, run any Bash tool call that starts with set -euo pipefail
  2. 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
  1. 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/

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING