claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Persistent Warning When Using API Key Directly

Open ratmav opened this issue 5 months ago • 5 comments

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

  1. export ANTHROPIC_API_KEY=redacted
    • alternatively, set via ./claude/settings.json:
      {
        "model": "opus",
        "env": {
          "ANTHROPIC_API_KEY": "redacted"
        }
      }
      
  2. claude
  3. Choose dark mode.
  4. Choose "Anthropic Console account" login method
  5. Sign in via browser (oauth).
  6. "Detected custom API key in your environment...Do you want to use this API key?" Yes.
  7. "Welcome to Claude Code" banner
    • no other text is visible
    • I can't see anything I input.
      • Ctrl-C does seem to work, and I get the "Press Ctrl-C to exit" message.
  8. Press Ctrl-C 2x to exit.
  9. claude
  10. Choose dark mode again.
  11. Press enter to acknowledge security notes.
  12. 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

  1. export ANTHROPIC_API_KEY=redacted
    • alternatively, set via ./claude/settings.json:
      {
        "model": "opus",
        "env": {
          "ANTHROPIC_API_KEY": "your_key_here"
        }
      }
      
  2. claude
  3. Choose dark mode.
  4. Choose the "Use an API key directly" login method
    • New login method.
  5. Press enter to acknowledge security notes.
  6. 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

ratmav avatar Jul 29 '25 21:07 ratmav

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:

  1. Override of valid Max/Pro subscription (as you noted)
  2. Misleading error: "This organization has been disabled"
  3. 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.

Toowiredd avatar Sep 29 '25 01:09 Toowiredd

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

Morriz avatar Nov 30 '25 01:11 Morriz

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...

Morriz avatar Nov 30 '25 02:11 Morriz

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

beyondchojnacki avatar Dec 03 '25 22:12 beyondchojnacki

guys. this is INSANE. vibe it already?

ahoward avatar Dec 10 '25 21:12 ahoward