Manage API key environment variables in Claude Code (original) (raw)
When using Claude Code, it's important to understand how authentication methods are prioritized to avoid unexpected API charges and ensure you're using your intended account.
How authentication works
Best practices
To use Claude Code with your Claude subscription: Keep the ANTHROPIC_API_KEY environment variable unset.
Authentication conflict warnings
Claude Code will notify you when there's a conflict between your authenticated subscription and an environment variable API key:
Check your current configuration
To verify if an API key is set as an environment variable, run /status in Claude Code. This will show you which authentication method is currently active.
To check your environment variable directly, run one of these commands in a terminal (outside of Claude Code):
macOS/Linux:
Windows CMD:
Windows PowerShell:
Set an API key temporarily
If you need to use an API key for the current terminal session only:
macOS/Linux:
Windows CMD:
Windows PowerShell:
Set an API key environment variable permanently
macOS/Linux:
Windows:
Remove an API key environment variable
macOS/Linux (temporary):
macOS (permanent):
Linux (permanent)
Windows CMD:
Windows PowerShell:
Windows (permanent): Delete the variable from System Environment Variables settings.
Common issues to avoid
Related Articles
Use Claude Code with your Pro or Max planClaude Code model configurationClaude Code FAQYour first day in Claude CodeTroubleshoot Claude Code installation and authentication