CLAUDE_CODE_OAUTH_TOKEN is removed from all subprocesses (Bash tool, subagents, hooks, MCP) without CLAUDE_CODE_SUBPROCESS_ENV_SCRUB; undocumented
Status Open
Reported on v2.1.296
Maintainer reply None cached
Activity 0 comments · opened Oct 13, 2026
Summary
Claude Code removes CLAUDE_CODE_OAUTH_TOKEN from the environment of every subprocess it starts, even when CLAUDE_CODE_SUBPROCESS_ENV_SCRUB is unset. The documentation describes credential removal only for the opt-in scrub, so this behavior is undocumented.
Environment
- Claude Code 2.1.296 (native), macOS, Darwin arm64
CLAUDE_CODE_SUBPROCESS_ENV_SCRUBis not set in the environment or in any settings file
Steps to reproduce
Use dummy values and presence checks only.
- Export
CLAUDE_CODE_OAUTH_TOKEN,ANTHROPIC_API_KEY,ANTHROPIC_AUTH_TOKENand a control variable such asFOO_PROBE=1with dummy values. - Start
claude -pwith aSessionStarthook (via--settings) and a stdio MCP server (via--mcp-config). Each of them records whether each variable is present. - Separately, start an authenticated session and run a presence check from the Bash tool and from a subagent's Bash tool.
Observed
CLAUDE_CODE_OAUTH_TOKEN: absent in Bash tool shells, subagent Bash shells, hook processes and stdio MCP server processes, including after--continue. The parentclaudeprocess does have it.ANTHROPIC_API_KEY,ANTHROPIC_AUTH_TOKENand the control variable: present in all of them.
Expected
Either pass the variable through, as for other credentials when the scrub is off, or document the unconditional removal. A script launched from a tool shell that needs the token (for example a nested claude -p used as a reviewer) cannot authenticate, and the cause is not discoverable from the docs.
Docs consulted
- env-vars:
CLAUDE_CODE_SUBPROCESS_ENV_SCRUBand "What the subprocess environment scrub removes" ("The Claude Code process keeps the credentials for its own API calls.") - authentication:
CLAUDE_CODE_OAUTH_TOKENand authentication precedence