[BUG] Bash tool fails on every command with declare: not valid in this context: SENTRY-TRACE when launched from Claude Desktop
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?
Environment
Claude Code launched via Claude Desktop (macOS, Darwin 24.6.0)
Shell: zsh
Symptom
Every Bash tool invocation fails before the command runs — even echo hello:
zsh: declare: 43: not valid in this context: SENTRY-TRACE
exit code 1
Root cause
The shell environment that Claude Desktop hands to the Bash tool contains an environment variable whose name has a hyphen: SENTRY-TRACE (this is Sentry's sentry-trace distributed-tracing header, evidently materialized as an env var by the app's instrumentation). When Claude Code reconstructs that environment for the subshell, it emits an assignment like declare SENTRY-TRACE=… / export SENTRY-TRACE=…. zsh parses declare/export/typeset arguments as assignments at parse time, and SENTRY-TRACE is not a valid shell identifier, so the line fails to parse and aborts the entire command preamble.
Evidence it's the app, not my shell
grep -rn 'SENTRY-TRACE' across ~/.zshrc, ~/.zshenv, ~/.zprofile, ~/.zlogin, /etc/*, and ~/.claude/shell-snapshots/ → no matches.
env | grep -i sentry in a normal terminal → empty. The variable exists only in shells spawned by Claude Desktop.
Note
This doesn't happen with every session. Claude Code will work for awhile then intermittently you will face this. Once it happens, it will persist through new sessions and through Claude Desktop restarts. Switching to bash instead of zsh seems to fix the issue since bash just ignores existing invalid env vars while zsh fails aggressively
What Should Happen?
Claude Code should not feed environment variables with names that aren't valid POSIX shell identifiers through declare/export/typeset. Either skip/sanitize such names when generating the shell preamble/snapshot, or quote/encode them so they don't abort the shell.
Error Messages/Logs
zsh: declare: 43: not valid in this context: SENTRY-TRACE
Steps to Reproduce
- Start Claude Desktop
- Create a new Claude Code session
- Prompt Claude (any prompt)
- Claude struggles to perform any commands due to:
- zsh: declare: 43: not valid in this context: SENTRY-TRACE
Note: This happens intermittently. Most days new sessions work without issue. I do not know what triggers this to happen.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.178 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Other
Additional Information
_No response_