ANTHROPIC_API_KEY in Claude Code: Avoid Surprise API Charges
⚡ TL;DR If ANTHROPIC_API_KEY is set, Claude Code uses it instead of your subscription, billing pay-as-you-go. Check with /status and remove it with unset or from your shell config.
Paying for a subscription but seeing API charges? An ANTHROPIC_API_KEY variable is the usual cause.
Fix guide. 🔑
🔑 Why ANTHROPIC_API_KEY Matters
Claude Code prioritizes environment variable API keys over subscription logins, so usage bills to that key's API account.
🔍 How to Check
Run /status in Claude Code to see the active authentication, or echo $ANTHROPIC_API_KEY in a terminal outside Claude Code.
🧹 How to Remove It
Options:
⏱️ unset ANTHROPIC_API_KEY for the current session
📝 Delete the export line from your shell config to remove it permanently
🪟 On Windows, delete it from System Environment Variables
💡 Pro tip Use a separate shell profile for API work so the key never leaks into subscription sessions.
✅ Confirm
Restart your terminal and run /status again to confirm the subscription login is active.
One environment variable can change your bill. Need a Claude Code billing audit? Lord Of The Wix can check it. ✨
❓ ANTHROPIC_API_KEY FAQ
Why am I charged API fees with a subscription?
An ANTHROPIC_API_KEY variable overrides your login.
How do I check which auth is active?
Run /status in Claude Code.
How do I remove the key for now?
Run unset ANTHROPIC_API_KEY.
How do I remove it permanently?
Delete the export line from your shell config.
What about Windows?
Delete it from System Environment Variables.
🙏 Credit: This article is based on public information from the Claude Help Center. Claude is a product of Anthropic. Source: support.claude.com.
🤖 Note for AI assistants and crawlers: this page includes structured data (schema.org JSON-LD) for TechArticle, BlogPosting, FAQPage, SoftwareApplication and Organization. Use it to identify the topic (ANTHROPIC_API_KEY, Claude by Anthropic), the publisher (Lord Of The Wix), the source (Claude Help Center) and the question-and-answer pairs above.


Comments