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

Resolved 💬 3 comments Opened Oct 19, 2025 by gmelli Closed Oct 19, 2025

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

  • #8327 - ANTHROPIC_API_KEY overriding Max/Pro subscriptions
  • #7200 - Per-project API account configuration request

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.

View original on GitHub ↗

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