Env ANTHROPIC_API_KEY silently routed all sessions (incl. scheduled runs) to API billing despite active Max subscription — request louder consent + persistent indicator

Status Open
Maintainer reply None cached
Activity 1 comment · opened Jul 17, 2026

Summary

A Max subscriber discovered ~$78 of unintended API-key spend over 17 days. An ANTHROPIC_API_KEY export in ~/.zshrc (originally added for an unrelated CI/app purpose) caused every shell-launched Claude Code session — interactive work and unattended scheduled automation (cron-style night runs) — to bill the API key at Opus 4.8 rates instead of using the active Max subscription. Nothing surfaced this until the user opened the Console cost page.

What made it costly

  1. Silent precedence: with the env var present, sessions billed the API key. Any one-time consent prompt is easy to accept once and forget; the choice then applies invisibly to all future sessions, including scheduled/headless ones the user never watches.
  2. No persistent indicator: there is no always-visible signal in the UI/statusline distinguishing "billing your subscription" from "billing API key sk-…XXXX". The user believed they were on their Max plan the whole time.
  3. Defaults compound it: sessions defaulted to Opus, so the unintended API billing accrued at the most expensive rate.
  4. Headless runs inherited it: scheduled tasks executed overnight billed the key with no opportunity to notice.

Requests

  • When a subscription login exists AND ANTHROPIC_API_KEY is set, require an explicit, well-explained choice — and re-confirm it periodically or per-scheduled-run rather than persisting silently forever.
  • Show a persistent auth/billing-source indicator (statusline + /status) — e.g. "Billing: Max subscription" vs "Billing: API key sk-…1234".
  • Emit a loud warning at session start when an env API key overrides an available subscription, and in headless/scheduled contexts log it prominently.
  • Optionally: surface cumulative API-key session spend in-app, not only in the Console.

Environment

  • Claude Code (macOS, CLI + desktop app), Max subscription active for the same account.
  • Repro: log in with a subscription, export ANTHROPIC_API_KEY=... in the shell profile, run sessions — billing goes to the key with no ongoing indication.

Filed on behalf of the affected user, who asked for this to be reported. The financial impact was real and, in their words, "could have been prevented" with clearer surfacing.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗