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_SCRUB is not set in the environment or in any settings file

Steps to reproduce

Use dummy values and presence checks only.

  1. Export CLAUDE_CODE_OAUTH_TOKEN, ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN and a control variable such as FOO_PROBE=1 with dummy values.
  2. Start claude -p with a SessionStart hook (via --settings) and a stdio MCP server (via --mcp-config). Each of them records whether each variable is present.
  3. 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 parent claude process does have it.
  • ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN and 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_SCRUB and "What the subprocess environment scrub removes" ("The Claude Code process keeps the credentials for its own API calls.")
  • authentication: CLAUDE_CODE_OAUTH_TOKEN and authentication precedence

View original on GitHub ↗