Skip to content

[Enhancement] Add flag to ignore ANTHROPIC_API_KEY when using subscription authentication #9880

Description

@gmelli

Summary

Add a command-line flag or configuration option to allow Claude Code to ignore the ANTHROPIC_API_KEY environment variable when users want to authenticate with their Claude Max/Pro subscription instead.

Use Case

I'm a Claude Max Pro subscriber who also develops custom agents (e.g., private-llm-manager-aget) that make direct API calls to Claude using the official SDK. These agents legitimately need ANTHROPIC_API_KEY set in my environment.

However, when I run Claude Code, I encounter this warning:

⚠Auth conflict: Both a token (claude.ai) and an API key (ANTHROPIC_API_KEY) are set. 
This may lead to unexpected behavior.

Current Workarounds

  1. Unsetting the variable - Doesn't work because my agents need it
  2. Shell alias - alias claude='env -u ANTHROPIC_API_KEY /opt/homebrew/bin/claude' works but is hacky
  3. Modifying agent code - If agents spawn Claude Code as subprocess, need to remove the env var programmatically

Proposed Solutions

Option 1: Command-line Flag

claude --use-subscription  # Ignore ANTHROPIC_API_KEY
claude --ignore-env-api-key  # Alternative naming

Option 2: Environment Variable

CLAUDE_CODE_AUTH_METHOD=subscription claude

Option 3: Configuration File

{
  "authPrecedence": "subscription",
  "ignoreEnvApiKey": true
}

Option 4: Smart Detection

Automatically prefer subscription auth when user is logged in with Max/Pro and only show warning if subscription auth fails.

Related Issues

Benefits

  • Allows legitimate multi-tool workflows (Claude Code + custom agents)
  • Cleaner than shell aliases/wrappers
  • Gives users explicit control over authentication precedence
  • Reduces confusion for Max/Pro subscribers

Additional Context

As a Max Pro subscriber, Claude Code usage is included in my subscription (/cost confirms this), but the presence of ANTHROPIC_API_KEY for other tooling creates unnecessary friction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions