[BUG] When `ANTHROPIC_API_KEY` env variable is set, Claude shows a conflict warning on startup
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 I set the ANTHROPIC_API_KEY env variable, the following message shows up:
⚠Auth conflict: Both a token (claude.ai) and an API key (ANTHROPIC_API_KEY) are set. This may lead to unexpected behavior.
• Trying to use claude.ai? Unset the ANTHROPIC_API_KEY environment variable, or claude /logout then say "No" to the API key
approval before login.
• Trying to use ANTHROPIC_API_KEY? claude /logout to sign out of claude.ai.
It doesn't make much sense though, since it's not possible to have just the ANTHROPIC_API_KEY set without being logged in.
If you log out, set the variable, and re-launch Claude, it asks you to log in (with either console login or OAuth).
If I own an API key that doesn't belong to my account, I still have to authenticate somehow, so I pick my regular account and log in with OAuth.
What Should Happen?
Claude should allow using an API key (via ANTHROPIC_API_KEY) that doesn't belong to my logged-in account without showing a conflict warning.
Error Messages/Logs
Steps to Reproduce
- Set the
ANTHROPIC_API_KEYenvironment variable (with an API key that doesn't belong to your logged-in account) - Launch/restart Claude
- Log in to Claude via OAuth
- The conflict warning appears on startup
Claude Model
Sonnet (default)
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.0.14
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Other
Additional Information
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗