[BUG] Shell snapshot captures compdef function but not _comps associative array, breaking zsh commands
Resolved 💬 3 comments Opened Mar 4, 2026 by tohrxyz Closed Mar 8, 2026
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 using zsh, Claude Code's shell snapshot serializes the compdef function (created by compinit) but does not capture the associative arrays it depends on (_comps,
_services, _patcomps, _postpatcomps).
When a command triggers compdef in the restored snapshot environment, it fails with:
compdef:153: _comps: assignment to invalid subscript range
Exit code 126 — the actual command never executes
What Should Happen?
Either:
- Snapshot should also capture the associative arrays that compdef depends on, or
- Snapshot should skip capturing compdef entirely (it's not useful in a non-interactive context)
Possible root cause:
- compinit creates the compdef function and declares typeset -gA _comps _services ...
- The shell snapshot (.claude/shell-snapshots/snapshot-zsh-*.sh) captures compdef but not the associative arrays
- When compdef runs in the snapshot environment, _comps is an unset variable, so _comps[$cmd]="$func" is interpreted as a string subscript range, which fails
Error Messages/Logs
compdef:153: _comps: assignment to invalid subscript range
Exit code 126 — the actual command never executes.
Steps to Reproduce
- Use zsh as default shell
- Have compinit in .zshrc (standard zsh setup)
- Run any command via Claude Code's Bash tool (e.g. npm run test)
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.68
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Warp
Additional Information
Ive solved it using workaround
Set CLAUDE_CODE_SHELL=/bin/bash to bypass zsh entirely.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗