fix(claude-code): drop ANTHROPIC_API_KEY to avoid CLI auth conflict#357
fix(claude-code): drop ANTHROPIC_API_KEY to avoid CLI auth conflict#357BjoernSchotte wants to merge 1 commit into
Conversation
The claude-code harness sets both ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY to the same LITELLM_API_KEY value. Current claude CLI versions warn: Auth conflict: Both a token (ANTHROPIC_AUTH_TOKEN) and an API key (ANTHROPIC_API_KEY) are set. This may lead to unexpected behavior. When pointing at a LiteLLM gateway the correct mechanism is AUTH_TOKEN (it is what gets sent as 'Authorization: Bearer <key>', which is what LiteLLM expects). ANTHROPIC_API_KEY sends the legacy 'X-API-Key' header and is the wrong contract for a proxy. Setting both makes the CLI pick one in a version-dependent way and emit the warning above on every boot. Drop ANTHROPIC_API_KEY from the env explicitly so even if it was inherited from the container environment the harness comes up clean.
Greptile SummaryThis fix resolves a Claude CLI startup warning caused by setting both
Confidence Score: 5/5Safe to merge — the change is a targeted two-line fix with a clear, well-documented rationale and no behavioral side-effects for non-LiteLLM deployments. The change removes a redundant env-var assignment and adds a delete call that only runs when LITELLM_API_KEY is present. Containers not using LiteLLM are completely unaffected. The fix brings the harness in line with the claude-agent-sdk harness and eliminates a real CLI startup warning. No auth logic, PTY management, or platform-compat routing is touched. No files require special attention.
|
| Filename | Overview |
|---|---|
| harnesses/claude-code/server.js | Removes the duplicate ANTHROPIC_API_KEY assignment and adds an explicit delete so only ANTHROPIC_AUTH_TOKEN is set when routing through LiteLLM, eliminating the Claude CLI auth-conflict warning. |
Reviews (1): Last reviewed commit: "fix(claude-code): drop ANTHROPIC_API_KEY..." | Re-trigger Greptile
Summary
The
claude-codeharness sets bothANTHROPIC_AUTH_TOKENandANTHROPIC_API_KEYto the sameLITELLM_API_KEYvalue when proxying through a LiteLLM gateway. CurrentclaudeCLI versions print this on every boot:Behavior beyond the warning is version-dependent (CLI picks one of the two).
Why AUTH_TOKEN is correct here
LiteLLM expects
Authorization: Bearer <key>, which is whatANTHROPIC_AUTH_TOKENproduces.ANTHROPIC_API_KEYproduces the legacyX-API-Keyheader, which LiteLLM does not consume for auth. SoAUTH_TOKENis unambiguously the right contract for a proxy setup.Change
In
harnesses/claude-code/server.js, keepANTHROPIC_AUTH_TOKEN = LITELLM_API_KEYanddelete process.env.ANTHROPIC_API_KEY— even if the operator passes one in viaCONTAINER_ENV_ANTHROPIC_API_KEYthe harness env stays clean.harnesses/claude-agent-sdk/src/server.ts(referenced by the existing code comment) already uses only AUTH_TOKEN, so this aligns the two harnesses.Test plan
claude-code-sandbox:devlocally on arm64 and spawned a session via kindANTHROPIC_AUTH_TOKENset, noANTHROPIC_API_KEY