Skip to content

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

Description

@fivetran-peixiaolin

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions