Persistent Warning When Using API Key Directly
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- 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:
``json``
{
"model": "opus",
"env": {
"ANTHROPIC_API_KEY": "redacted"
}
}
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:
``json``
{
"model": "opus",
"env": {
"ANTHROPIC_API_KEY": "your_key_here"
}
}
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
Showing cached comments. Read the full discussion on GitHub ↗
9 Comments
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_KEYset to a key from a disabled org causes:"This organization has been disabled"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:
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?
When launching the Claude CLI with an explicitly specified settings file, an authentication conflict warning appears, even though the system correctly uses the provided token.
Have a settings file
~/.claude/settings.jsonwith the following content:Launch Claude CLI with the specified settings file:
A warning message appears:
However, authentication via the provided token works correctly — API requests use the specified
ANTHROPIC_AUTH_TOKEN.Expected Result:
--settingsAnything new about this ?
We are having the same problem, trying to logout to use ANTHROPIC_API_KEY but it does not let us use it without login in
Proposed Fix for #4733: Auth Conflict Warning with
ANTHROPIC_API_KEYProblem
Setting
ANTHROPIC_API_KEYwhile an OAuth credential exists produces a persistent, unresolvable warning on every startup:Neither action fixes it —
/logoutforces re-auth and the warning returns; unsetting the key defeats the user's intent.Root Cause
The auth system treats
ANTHROPIC_API_KEY+ OAuth credential as a conflict, rather than recognizing the env var as an intentional override.Proposed Fix
1.
ANTHROPIC_API_KEYshould win silently. When set, skip the OAuth credential check — no warning needed. The user made their choice.2. Add "Use API key" as a login method. Let users explicitly select API key auth during onboarding instead of forcing OAuth first:
3. Add a
suppressAuthConflictWarningsetting for users who need both credentials present. The existingforceLoginMethodworkaround proves users need this control, but it shouldn't require a CLI flag every invocation.Enterprise Impact — Cost Governance Blocker
This isn't just a UX annoyance — it breaks enterprise spend management.
Enterprise workspaces use API keys with spend limits to cap per-team budgets:
The intended flow: admin creates a spend-capped workspace key → distributes to team → team sets
ANTHROPIC_API_KEY→ usage tracks against that workspace's limit.What actually happens: Users set the workspace key, hit the auth conflict warning, can't resolve it, and either give up (reverting to OAuth which draws from the entire org pool with no cap) or deal with the warning on every startup.
The result is a budget leak — enterprise admins cannot enforce workspace spend boundaries because Claude Code actively discourages the configuration that makes them work.
| What admins need | What happens today |
|---|---|
| User uses workspace-scoped API key | Auth conflict warning every startup |
| Usage counts against workspace cap | Users revert to OAuth → org-wide pool, no limits |
| Clean onboarding: "set this env var" | Confusing warning with no working fix |
Why This Matters
I had this issue and it was the result of Claude Code credentials stored in MacOS Keychain. I don't recall ever intentionally storing Claude Code credentials in Keychain so I was surprised when I opened up Keychain Access and saw the entry. I deleted it and now when I log in I'm asked if I want to use the API Key, I select it and I am now logged in without getting routed to the console and the warning is gone.