SOP: Claude Code Plan Usage vs. API Billing¶
Home / Guides & Runbooks / SOPs / Claude Code Plan vs. API Billing
Purpose — Ensure Claude Code usage bills against the intended source (your subscription plan or your Anthropic API key), and switch between them deliberately.
When to use — Setting up Claude Code, hitting a plan quota limit, or unsure which account is being charged.
Background¶
- Claude Code uses one authentication method at a time.
- There is no automatic fallback from plan to API. When your plan quota runs out, you are blocked until the reset window — it does not silently start charging your API key.
- Switching between plan and API is a manual step (change env, restart).
How auth is chosen¶
Claude Code picks its auth source in this order:
ANTHROPIC_API_KEYis set (env var, or asettings.jsonenvblock) → all usage bills your API key. Your subscription is skipped entirely, even if you're logged in.- No API key set, logged in via subscription (
/login) → all usage counts against your plan. Hit the limit → blocked until reset.
Key point: the API key always wins. If it's set anywhere Claude Code reads,
/login has no effect on billing.
Common gotcha: the key hides in settings.json
An ANTHROPIC_API_KEY in ~/.claude/settings.json is injected into every
session, so you're on API billing without realizing it:
To use your plan, remove that env block and restart Claude Code. Check
which auth is active with /status.
Note
A running Claude Code process keeps whatever env it started with.
Any change (removing the key, unset, etc.) needs a restart to take effect.
Steps¶
Stay on plan (default, recommended)¶
- Make sure
ANTHROPIC_API_KEYis not set: - not in your shell (
echo $ANTHROPIC_API_KEYprints nothing) - not in
~/.claude/settings.json(noenvblock with it) - not in
~/.zshrc/~/.bashrc/~/.zshenv/ profile files /loginwith your subscription account./status→ confirms subscription auth.
Switch to API when the plan runs out¶
- In your terminal:
- Restart Claude Code.
- Now billing goes to the API key.
Switch back to plan¶
unset ANTHROPIC_API_KEY(and remove it from any profile / settings.json).- Restart Claude Code.
Verification¶
| State | Billing | At quota limit |
|---|---|---|
ANTHROPIC_API_KEY set (env or settings.json) |
API key | Keeps working (API rates) |
| No API key + subscription login | Plan | Blocked until reset — no auto-fallback |
Check current auth any time with /status.
Security notes¶
- Never hardcode the API key in
settings.jsonif you can avoid it — it's easy to forget it's there, and it silently overrides plan billing. - Treat the key like a password. If it ever prints to a terminal, gets committed, or lands in editor history, rotate it at https://console.anthropic.com → API keys.
- Prefer setting
ANTHROPIC_API_KEYin your shell only for the session you need it, thenunsetit.