Persistent Warning When Using API Key Directly
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other:
- Claude CLI version: 1.0.62 (Claude Code)
- Operating System: macOS Sequoia 15.5
- Terminal: Wezterm
Bug Description
╭──────────────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code! │
│ │
│ /help for help, /status for your current setup │
│ │
│ cwd: redacted │
│ │
│ ────────────────────────────────────────────────────── │
│ │
│ Overrides (via env): │
│ │
│ • API Key: redacted │
╰──────────────────────────────────────────────────────────╯
⚠ Auth conflict: Using ANTHROPIC_API_KEY instead of Anthropic Console key. Either unset ANTHROPIC_API_KEY, or run `claude /logout`.
To address the warning, I run claude /logout as requested, then restart claude, but I am forced to log back in, which creates a new API key, and I still see the warning after choosing to use the API key I have set in the environment.
Steps to Reproduce
export ANTHROPIC_API_KEY=redacted- alternatively, set via
./claude/settings.json:{ "model": "opus", "env": { "ANTHROPIC_API_KEY": "redacted" } }
- alternatively, set via
claude- Choose dark mode.
- Choose "Anthropic Console account" login method
- Sign in via browser (oauth).
- "Detected custom API key in your environment...Do you want to use this API key?" Yes.
- "Welcome to Claude Code" banner
- no other text is visible
- I can't see anything I input.
Ctrl-Cdoes seem to work, and I get the "Press Ctrl-C to exit" message.
- Press Ctrl-C 2x to exit.
claude- Choose dark mode again.
- Press enter to acknowledge security notes.
- Get same "⚠ Auth conflict: Using ANTHROPIC_API_KEY instead of Anthropic Console key. Either unset ANTHROPIC_API_KEY, or run
claude /logout." warning message.
Expected Behavior
export ANTHROPIC_API_KEY=redacted- alternatively, set via
./claude/settings.json:{ "model": "opus", "env": { "ANTHROPIC_API_KEY": "your_key_here" } }
- alternatively, set via
claude- Choose dark mode.
- Choose the "Use an API key directly" login method
- New login method.
- Press enter to acknowledge security notes.
- Carry on with Claude code, observe api key override message.
Additional Context
I'm not sure if reproduction steps 7 and 8 are related to my primary concern, which is the persistent warning about an auth conflict due to have the envar set and Claude code clearly expecting to use the key generated on login. However, I listed those steps in an effort to be complete and comprehensive in the case it is useful information.
Ideally, I'd like to be able to set the API key in memory, so that I can use external password managers to load secrets into the environment, and let claude use those.
Related Issues
- https://github.com/anthropics/claude-code/issues/665
- https://github.com/anthropics/claude-code/issues/441
Related Discovery: API Key from Disabled Org Causes Confusing Error
This persistent warning about API keys becomes even more problematic when the API key is from a disabled organization.
I discovered that having ANTHROPIC_API_KEY set to a key from a disabled org causes:
- Override of valid Max/Pro subscription (as you noted)
- Misleading error:
"This organization has been disabled" - No indication that removing the API key would fix it
The error message makes users think their account is disabled, when actually it's just the old API key causing issues.
Full investigation and solution: #8327
Suggestion: When Claude Code detects an API key from a disabled org, the error should explicitly say:
"API key from disabled organization detected.
You have a valid Max subscription.
Remove ANTHROPIC_API_KEY to use your subscription."
This would save hours of debugging for users who don't realize an old work/school API key is overriding their personal subscription.
bump!
Why is there no progress here? This so not 12-factor. Idempotency please! We should be able to circumvent interaction for these things....pffff
Ok, I found out how to do it, by piecing things together:
claude --settings '{"forceLoginMethod": "claudeai"}'
Hope this helps y'all, but I suggest anthropic bots or peeps add it to the troubleshooting/faq...
Do you know the possible values for forceLoginMethod? How did you piece that setting together?
I am trying start claude code with with ANTHROPIC_API_KEY, not with claudeai
guys. this is INSANE. vibe it already?