Skip to content

fix(claude): keep CLAUDE_CODE_OAUTH_TOKEN in the spawned agent env - #587

Open
thereisnotime wants to merge 1 commit into
openagents-org:developfrom
thereisnotime:fix/claude-oauth-token-env
Open

fix(claude): keep CLAUDE_CODE_OAUTH_TOKEN in the spawned agent env#587
thereisnotime wants to merge 1 commit into
openagents-org:developfrom
thereisnotime:fix/claude-oauth-token-env

Conversation

@thereisnotime

Copy link
Copy Markdown

The claude adapter strips CLAUDE_* variables so the spawned claude does not think it is running under an SDK harness and fall onto the org-scoped auth path. That is correct, but the allowlist misses CLAUDE_CODE_OAUTH_TOKEN.

It is a credential, not a harness marker. It is what claude setup-token writes, and it is the normal way to pass subscription auth. With it stripped, a spawned agent can only authenticate via an API key or credentials already on disk. On a headless host or in a container there is neither: no interactive login to fall back on, and no credentials file.

The allowlist already carves out exactly this category (CLAUDE_API_KEY, Vertex, Bedrock), so this looks like an omission rather than intent. Grepping the repo, the name does not appear anywhere else.

Repro

export CLAUDE_CODE_OAUTH_TOKEN=...
agn create x --type claude
agn up

The agent starts unauthenticated. The variable is gone from its environment.

Changes

  • Add CLAUDE_CODE_OAUTH_TOKEN to CLAUDE_ENV_KEEP.
  • Extract the set and the strip loop into sanitizeClaudeEnv() at module scope so the behaviour is testable. No change to what gets stripped otherwise.
  • New test/claude-env.test.js: harness markers still stripped, existing allowlist entries preserved, OAuth token preserved, unrelated vars untouched, input not mutated.

Testing

node --test in packages/agent-connector: 5 new tests pass, 43 adjacent tests still pass.

The adapter strips CLAUDE_* variables so the spawned `claude` doesn't think
it's running under an SDK harness and fall onto the org-scoped auth path. The
allowlist already carves out the vars the child genuinely needs (Vertex,
Bedrock, model, API key, max turns), but it misses CLAUDE_CODE_OAUTH_TOKEN.

That one is a credential, not a harness marker. It's what `claude setup-token`
writes and it's the normal way to pass subscription auth. Dropping it means an
agent that can only authenticate with an API key or with credentials already on
disk, so a container or a headless host has no way in at all: there's no
interactive login to fall back on and no file to read.

Added it to the allowlist. Also pulled the set and the loop out into
sanitizeClaudeEnv() at module scope so the behaviour is testable, with no
change to what gets stripped otherwise.

Tests cover the harness markers still being removed, the existing allowlist
entries surviving, the OAuth token surviving, unrelated vars being untouched,
and the input not being mutated.
@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

@thereisnotime is attempting to deploy a commit to the Raphael's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant