[BUG] Bash tool fails on every command: "export: not valid in this context: SENTRY-TRACE" (zsh) — recurrence of #70416
Preflight Checklist
- [x] I have searched existing issues
- [x] This is a single bug report
- [x] I am using the latest version of Claude Code
Summary
Every Bash tool invocation fails before the command runs with:
zsh:export:62: not valid in this context: SENTRY-TRACE
exit code 1
This is the same bug as #70416 (which was auto-closed as stale / not_planned by the bot on 2026-08-05 without ever being triaged). Filing a fresh report since it is still occurring on a current version. In my case the failing builtin is export (the original report saw declare), but the root cause is identical.
Root cause (confirmed, same as #70416)
The environment handed to the Bash tool contains an env var whose name has a hyphen: SENTRY-TRACE — Sentry's sentry-trace distributed-tracing header, materialized as an env var by the app's instrumentation. When Claude Code reconstructs that environment for the subshell, it emits export SENTRY-TRACE=… / declare SENTRY-TRACE=…. zsh parses export/declare/typeset arguments as assignments at parse time, and SENTRY-TRACE is not a valid POSIX shell identifier, so the line fails to parse and aborts the entire command preamble → exit 1 before any command runs. bash tolerates this (it ignores the invalid name); zsh fails hard.
Evidence it's the app, not my shell
~/.zshrcline 62 is blank;~/.zshenv,~/.zprofile,~/.zlogindo not exist on this machine.- I have nothing Sentry-related installed or configured — no SDK, no config, no such env var in a normal terminal.
- The variable exists only in shells spawned by the app.
SENTRY-TRACEis a per-request HTTP tracing header, not something present in a user environment.
Expected behavior
Claude Code should not feed env var names that aren't valid POSIX shell identifiers through export/declare/typeset. When generating the shell preamble/snapshot, skip or sanitize names that don't match [A-Za-z_][A-Za-z0-9_]* (or encode them), so a single non-identifier var name can't abort every command.
Steps to Reproduce
- Launch Claude Code via Claude Desktop (macOS).
- Start a session and prompt Claude to run any Bash command (e.g.
echo hello). - Every command fails with
zsh:export:…: not valid in this context: SENTRY-TRACEbefore running.
Note: as in #70416, this appears intermittently — most sessions are fine, but once it starts it persists across new sessions and Claude Desktop restarts.
Environment
- Launched via: Claude Desktop
- OS: macOS (Darwin 24.6.0)
- Shell: zsh
- Model: Opus 4.8
- Same symptom and root cause as #70416
Related
- #70416 (original report, closed stale — not fixed)
- #7490 (feature request: configurable Bash-tool shell; switching to bash is the current workaround)