[BUG] claude --print silently prefers ANTHROPIC_API_KEY over subscription auth
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
- When ANTHROPIC_API_KEY is set in the shell environment (e.g. via .zshrc), claude --print uses API billing instead of subscription auth
- No warning or prompt that billing mode switched
- Discovered after unexpected API spend -- multiple claude --print sessions billed ~$10 to the API console instead of using Max subscription
- The key was originally placed in .zshrc on Claude Code's own recommendation during a setup conversation
What Should Happen?
The CLI should either warn when it detects both auth methods, or at minimum the recommendation should have come with a caveat
about --print mode billing behavior.
Error Messages/Logs
No error messages — the issue is silent. No warning is shown when claude --print
switches from subscription auth to API key billing.
Steps to Reproduce
- Have an active Claude subscription (Max/Pro)
- Export ANTHROPIC_API_KEY in ~/.zshrc (or any shell profile)
- Run: claude --print "Hello world"
- Check API console at console.anthropic.com — the call is billed to the API key, not the subscription
- No warning or indication that billing mode changed
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.79 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
The key was originally added to ~/.zshrc on Claude Code's own recommendation during a setup conversation. This means every shell
process inherits ANTHROPIC_API_KEY, and claude --print silently bills to the API instead of the subscription.
Discovered after ~$10 in unexpected API charges over a week. The API console showed Sonnet 4.6 usage on days where no SDK/API code
was run — only claude --print invocations.
Suggested fix: warn the user when both subscription auth and ANTHROPIC_API_KEY are available, or let the user choose which takes
priority.
Thank you guys! Best, Moritz
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗