iai-personal-memory-engine icon indicating copy to clipboard operation
iai-personal-memory-engine copied to clipboard

Subscription check ignores CLAUDE_CODE_OAUTH_TOKEN (setup-token auth), daemon stuck on Tier-0

Open yashiels opened this issue 2 months ago • 0 comments

Summary

verify_credentials_subscription() (src/iai_mcp/claude_cli.py) only recognises a subscription when it finds ~/.claude/.credentials.json or the macOS Keychain item Claude Code-credentials. A machine authenticated with a long-lived token from claude setup-token, exported as CLAUDE_CODE_OAUTH_TOKEN, has neither, so the gate reports credentials_file_missing and the daemon permanently falls back to Tier-0 consolidation (no nightly insight, no reconsolidation critic), even though claude -p authenticates fine on the subscription.

This is the standard setup for headless boxes (servers, always-on Mac minis, CI runners) where an interactive claude /login is not practical.

Reproduction

Version 3.2.3, macOS 15, Claude Code 2.x. No ~/.claude/.credentials.json, no Keychain item, token exported:

$ export CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-EXAMPLE...
$ claude auth status
{
  "loggedIn": true,
  "authMethod": "oauth_token",
  "apiProvider": "firstParty",
  ...
}
$ claude -p "reply with just ok" --max-turns 1
ok
$ iai-mcp doctor
  [WARN] (o) Claude subscription credentials      reason=credentials_file_missing; daemon will fall back to local Tier-0 consolidation (no LLM critic, no nightly insight). Run `claude /login` to restore subscription path.
  [FAIL] (bb) nightly insight mint                3 consecutive nights without a minted insight

Cause

verify_credentials_subscription() reads CREDENTIALS_PATH, then _read_keychain_credentials(), and returns credentials_file_missing when both are absent. It never looks at CLAUDE_CODE_OAUTH_TOKEN, which Claude Code treats as its highest-priority credential. The subprocess side already works: _scrubbed_env() only strips the metered API-key variables (ENV_DENY_LIST), so the OAuth token reaches claude and bills to the subscription. --bare does not read the token, but the existing "Not logged in" retry without --bare already covers that.

Proposed fix

  • In verify_credentials_subscription(), when neither the file nor the Keychain yields credentials and CLAUDE_CODE_OAUTH_TOKEN is set to a non-empty value, return {"ok": True, "source": "oauth_token_env"}.
  • Leave ENV_DENY_LIST unchanged: API keys stay scrubbed, so the C3 "never bill the metered API" guarantee holds.
  • Tests: token set with no file/Keychain passes; empty token still reports credentials_file_missing; an on-disk credentials file keeps precedence (so its tier/scope/expiry checks still apply).

Happy to send the PR.

yashiels avatar Sep 28 '26 09:09 yashiels