[BUG] Claude Code prompts for authentication despite ANTHROPIC_API_KEY environment variable being set

Resolved 💬 3 comments Opened Oct 17, 2025 by fivetran-peixiaolin Closed Oct 20, 2025

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?

I am seeing an auth conflict message if I provide an explicit API key as env var in source file.

Expected behavior:
Claude Code should use ANTHROPIC_API_KEY from environment without prompting log-in

Actual behavior:
Still prompts for login, creates second API key, causes auth conflict warning

My use case: we mean to use the manual created API key for cost and usage tracking per team

What Should Happen?

Claude code should detect the API key I provided as env var, and use it. I don't need to log in again

Error Messages/Logs

Seeing the warning message in CLI 

⚠Auth conflict: Using ANTHROPIC_API_KEY instead of Anthropic Console key. Either unset ANTHROPIC_API_KEY, or run `claude /logout`

Steps to Reproduce

  1. set ANTHROPIC_API_KEY env var in source file ~/.zshrc
  2. run "claude" in CLI
  3. prompted to "Select login method" between "Claude account with subscription" and "Anthropic Console account"
  4. Choose "Anthropic Console account"
  5. A pop-up window requires authroization
  6. Complete that via company's Okta SSO
  7. It automatically creates another API key
  8. Then it prompts to confirm "Do you want to use this API Key?" (the one set as env var)
  9. Choose "Yes"
  10. Seeing the warning message in CLI "⚠Auth conflict: Using ANTHROPIC_API_KEY instead of Anthropic Console key. Either unset ANTHROPIC_API_KEY, or run claude /logout"

Note: even if I logout, and will run into the same problem

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.0.20

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗