fix(providers): mirror CLAUDE_API_KEY to ANTHROPIC_API_KEY for the Claude subprocess#1941
Open
uinstinct wants to merge 1 commit into
Open
fix(providers): mirror CLAUDE_API_KEY to ANTHROPIC_API_KEY for the Claude subprocess#1941uinstinct wants to merge 1 commit into
uinstinct wants to merge 1 commit into
Conversation
…aude subprocess CLAUDE_API_KEY is Archon's env var name, but the Claude Code CLI and Agent SDK authenticate only via ANTHROPIC_API_KEY. In the solo .env path, buildSubprocessEnv() returned process.env untranslated, so the key never reached the subprocess: Docker queries failed with a non-retryable auth error, and hosts with `claude /login` silently used subscription auth. Mirror CLAUDE_API_KEY -> ANTHROPIC_API_KEY on the returned env copy, only when CLAUDE_API_KEY is set, ANTHROPIC_API_KEY is not already set, and no CLAUDE_CODE_OAUTH_TOKEN is present. Precedence: explicit ANTHROPIC_API_KEY > CLAUDE_CODE_OAUTH_TOKEN > CLAUDE_API_KEY. Strictly additive: only the currently-broken API-key-alone config changes behavior. Mirrors the per-user delivery.ts path, which already sets both vars. Closes coleam00#1940
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can use oxc to improve the quality of JavaScript and TypeScript code reviews.Add a configuration file to your project to customize how CodeRabbit runs oxc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CLAUDE_API_KEYset in.env(solo path, no per-user credential store) passes Archon's own credential validation but is never translated toANTHROPIC_API_KEY— the only variable the Claude Code CLI / Agent SDK authenticate with. The key never reaches the Claude subprocess.claude /loginstate in the container) every Claude query fails with a non-retryableClaude Code auth error. On hosts whereclaude /loginran, queries silently use subscription auth — the operator thinks they are on metered API billing but consume subscription quota. The Docker deployment doc explicitly offersCLAUDE_API_KEYas "Option B", so the documented path is broken.buildSubprocessEnv()now mirrorsCLAUDE_API_KEY→ANTHROPIC_API_KEYon the returned env copy, but only whenCLAUDE_API_KEYis set,ANTHROPIC_API_KEYis not already set, and noCLAUDE_CODE_OAUTH_TOKENis present. Added 5 unit tests; annotated theCLAUDE_API_KEYentry in.env.example.delivery.ts(the per-user path already sets both vars),process.envis never mutated (only the returned copy),hasExplicitTokens/ log semantics are untouched, and therequestOptions.envmerge order at the call site is unchanged (per-user delivered credentials still override the base env).UX Journey
Before
After
OAuth path unchanged: if
CLAUDE_CODE_OAUTH_TOKENis set, no API key is injected and the subprocess continues to use subscription auth exactly as before.Architecture Diagram
Before
After
Connection inventory:
buildSubprocessEnv()query()options.envANTHROPIC_API_KEYin the API-key-alone caseLabel Snapshot
risk: lowsize: XSproviders(closest available list value; package is@archon/providers)providers:claudeChange Metadata
bugproviders(packages/providers/src/claude)Linked Issue
Validation Evidence (required)
bun run validate(run withNODE_OPTIONS=--max-old-space-size=8192— the ESLint full-repo pass OOMs at the default heap on a low-memory container; this is an environment limit, not a code issue):@archon/providers(the touched package) including the 5 new tests:bun run validateoutput (commands above), targeted provider test run.Security Impact (required)
CLAUDE_API_KEY) to a second key (ANTHROPIC_API_KEY) inside the subprocess env copy only.process.envis not mutated. No secret is logged, transmitted, or persisted; the value already lived in the same process env. The copy is gated so it only occurs when the operator supplied an API key and no OAuth token, i.e. exactly the case where they intend API-key auth.Compatibility / Migration
CLAUDE_CODE_OAUTH_TOKEN, with an explicitANTHROPIC_API_KEY, or with global auth are byte-for-byte unchanged..env.example).Human Verification (required)
sendQuery→ SDKoptions.env(the 5 new tests). Confirmed precedence explicitANTHROPIC_API_KEY>CLAUDE_CODE_OAUTH_TOKEN>CLAUDE_API_KEY. Verified the per-user delivery path (requestOptions.env) still overrides the base env.ANTHROPIC_API_KEYpresent (not clobbered); OAuth token present (no injection); nothing set (no injection);requestOptions.envoverride (wins).options.envhanded toquery()).Side Effects / Blast Radius (required)
packages/providers/src/claude/provider.ts). Every Claude-backed workflow/conversation benefits in the API-key-alone case; all other auth modes unaffected.!ANTHROPIC_API_KEYguard prevents overriding an explicitly chosen key.using_global_auth/using_explicit_tokensboot log; auth failures still surface asClaude Code auth error.Rollback Plan (required)
git revert <commit>(the change is one isolated commit touchingprovider.ts,provider.test.ts,.env.example).ANTHROPIC_API_KEYor useCLAUDE_CODE_OAUTH_TOKEN.Claude Code auth errordespite a validCLAUDE_API_KEYwould indicate regression.Risks and Mitigations
CLAUDE_API_KEYandCLAUDE_CODE_OAUTH_TOKENexpecting API-key billing..env.example. Changing this would silently alter billing for existing deployments, so it is deliberately out of scope.