Repository navigation
Conversation
ANTHROPIC_API_KEY, when present anywhere in the host environment, takes precedence over the operator's claude.ai login for the nested claude -p call the summarizer spawns -- the CLI resolves credentials in that order. A key with an exhausted or unfunded balance then fails every background summarize silently: save-session.sh --force exits 1 at session end with "Credit balance is too low", while the operator's own interactive sessions keep working fine off the login, so nothing about the failure points at this var without reading the child's own stderr. Reproduced in production: repeated "save-session.sh --force exited 1" warnings traced via the daily narrative log to exactly this cause, compounded once by a genuine rate limit and separately by this auth routing issue. ANTHROPIC_API_KEY was never a "parent session" marker the way CLAUDE_CODE_* is; _child_env() now strips it for the same reason it already strips CLAUDE_PROJECT_DIR -- the child should authenticate as if launched fresh, not inherit a credential the operator did not choose for this subprocess. Adds test_call_haiku_strips_anthropic_api_key alongside the existing parent-session-stripping test. 80/80 tests pass.
…hen it is the only credential @Mega-Therion diagnosed this and the strip itself is theirs; this commit makes it conditional, which is what the review asked for. An unconditional strip does not remove the reported outage, it relocates it: authenticating the CLI with ANTHROPIC_API_KEY alone is normal and documented, and for those installs dropping the key leaves the nested claude -p with no credential at all -- every background save failing silently, the same shape that took the reporter days to trace. So the key is now dropped only when another credential is visible (CLAUDE_CODE_OAUTH_TOKEN, a configured OAuth token, or a login at ~/.claude/.credentials.json) and kept when it is the only one there is. A login held in an OS keychain is invisible to this process, so auto keeps the key for those operators -- todays behaviour, not a new failure -- and the new haiku.anthropic_api_key config key (auto|keep|strip) is how they overrule it. An unrecognised value falls back to auto and says so, rather than grading silently as one of the two behaviours. A failure that looks like a credential failure now names the variable and the config key in the RuntimeError, so it reaches hook-errors.log where the operator is already looking rather than the daily log alone (#694). The marker list is deliberately narrow: a hint on every failure would point unrelated outages at an innocent variable. Tests pair every strip case with its keep twin -- an unconditional strip and an unconditional keep each fail here -- and the failure hint has both a negative control (no key set) and a wrong-cause control (key set, prompt-length failure). Co-Authored-By: Max <noreply>
4 tasks done
CodeQL was right: the warning quoted the rejected config value, and this keys NAME invites an operator to paste an actual API key into it. A typo would then have written that credential to the daily log in clear text -- a leaked secret on disk as the punishment for a misspelling. The warning now names the length and type, the legal values and the fallback, and says explicitly that the value is withheld and why. The test asserts the absence (a pasted key-shaped value must not appear) and gains its positive control: a recognised value warns about nothing, so warns-on-bad-value cannot silently become warns-on-everything. Co-Authored-By: Max <noreply>
Contributor
Author
|
Closing as a duplicate. This existed only because pushing to the author's own branch was blocked at the time; the retry succeeded, so the identical commits now sit on #693, where they belong — @Mega-Therion reported the bug, diagnosed it and wrote the first commit, and their PR should be the one that lands. Same two commits, same tests, no work lost. Continue at #693. [AI-generated] |
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.
Closes #703. Supersedes #693 — the diagnosis and the original patch are @Mega-Therion's, and their commit is the first of the two here, unchanged. What this adds is the condition the review asked for.
Why the strip could not stay unconditional
ANTHROPIC_API_KEYout-ranks aclaude.ailogin in the CLI's credential order, so an ambient key becomes the nested summarizer's credential and an exhausted one fails every background save while the operator's interactive sessions carry on working. That is #703, and dropping the key fixes it.But authenticating the CLI with
ANTHROPIC_API_KEYalone — no login, nosetup-token— is a normal, documented setup, and for those installs a strip leaves the child with no credential at all: every save failing, silently, in the same shape that took the reporter days to trace. The fix and the bug are the same outage pointed at different people.So the key is dropped on evidence:
CLAUDE_CODE_OAUTH_TOKENfrom the hosthaiku.oauth_token/REMEMBER_OAUTH_TOKEN~/.claude/.credentials.json(honoursCLAUDE_CONFIG_DIR)The limit, stated rather than papered over
A
claude.ailogin held in the macOS Keychain is invisible to this process, and probing the keychain would prompt the operator and read a secret we have no business reading. Soautokeeps the key for those operators — today's behaviour, not a new failure — and they say so once:{ "haiku": { "anthropic_api_key": "strip" } }auto(default),keep,strip. An unrecognised value falls back toautoand says so in the daily log, rather than grading silently as one of the two behaviours.Discoverability
The other half of #703 is that nothing named the variable. A failure that looks like a credential failure now carries it into the
RuntimeError, whichsave-session.shsurfaces tohook-errors.log— where the operator is already looking, instead of the daily log alone (#694):The marker list is deliberately narrow. A hint that fires on every failure points unrelated outages at an innocent variable, which is the misdirection this issue is about.
Tests
Every strip case has its keep twin, because this is a repo rule and here it is load-bearing: an unconditional strip and an unconditional keep would each pass half the suite.
CLAUDE_CODE_OAUTH_TOKEN/ when an OAuth token is configured / when a login file existsstripoverrides an invisible login; policykeepoverrides the strip; an unrecognised value warns and falls backThe fixture relocates
HOME,REMEMBER_DIRand the token env vars: without it the decision under test is the developer's own login, and the result flips between a laptop and CI.pytest: 2496 passed, 58 skipped locally (macOS). The Windows and Linux legs are reasoned, not observed, from here — nothing in this change is platform-specific beyondexpanduser, which the fixture pins on both shapes viaHOMEandUSERPROFILE.Docs:
docs/configuration.mdgets the row,config.example.jsonships"anthropic_api_key": "auto", andtests/test_config_contract.pyrecords that this key is read in Python rather than throughconfig().🤖 Generated with Claude Code
[AI-generated]