From 1171d965e83e02365a31b0b5fc21bb2db6698786 Mon Sep 17 00:00:00 2001 From: Henrik Jess Nielsen Date: Thu, 29 Oct 2026 22:12:24 +0100 Subject: [PATCH] fix(score): strip ANTHROPIC_API_KEY from CLI subprocess env With ANTHROPIC_API_KEY also present in the environment, the claude CLI does API-key auth and ignores CLAUDE_CODE_OAUTH_TOKEN, failing with 401 Invalid API key when that key is invalid/out of credit. Strip it from the subprocess env so the subscription token is used; the api backend still reads it from os.environ. --- score.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/score.py b/score.py index 560b732..7321335 100644 --- a/score.py +++ b/score.py @@ -88,9 +88,15 @@ def _call_cli(prompt: str) -> tuple[str, int, int, float]: "--max-turns", str(CLI_MAX_TURNS), "--disallowed-tools", "Bash,Edit,Write,Read,WebSearch,WebFetch", ] + # ANTHROPIC_API_KEY in the env takes precedence over the OAuth token and makes + # the CLI do API-key auth (401 "Invalid API key"). Strip it so the subscription + # token is used; the api backend still sees it via os.environ. + cli_env = {k: v for k, v in os.environ.items() if k != "ANTHROPIC_API_KEY"} + last_err = "" for attempt in range(CLI_RETRIES): - proc = subprocess.run(cmd, input=prompt, capture_output=True, text=True, timeout=CLI_TIMEOUT) + proc = subprocess.run(cmd, input=prompt, capture_output=True, text=True, + timeout=CLI_TIMEOUT, env=cli_env) if proc.returncode != 0 or not proc.stdout.strip(): last_err = f"exit {proc.returncode}: {(proc.stderr or proc.stdout)[:300]}" continue