Skip to content

Feature request: Option to prefer subscription auth over ANTHROPIC_API_KEY #12861

Description

@gmelli

Summary

Request native configuration option to prefer subscription auth over environment API key, eliminating the need for env -u ANTHROPIC_API_KEY workaround.

Current Behavior

When ANTHROPIC_API_KEY is set in the environment, Claude Code CLI uses it for authentication instead of the subscription-based OAuth flow.

Problem scenario:

  • User has API key set for other tools (Python scripts, direct API calls)
  • User wants Claude Code to use their Claude subscription auth
  • No native way to tell Claude Code to ignore the env API key

Current workaround:

alias claude='env -u ANTHROPIC_API_KEY /opt/homebrew/bin/claude'

This works but is non-obvious and requires shell knowledge.

Requested Behavior

Add configuration option to prefer subscription auth even when API key is present.

Option A: Config file setting

// ~/.claude/settings.json
{
  "auth": {
    "prefer_subscription": true
  }
}

Option B: CLI flag

claude --prefer-subscription "query"

Option C: Environment variable

export CLAUDE_CODE_PREFER_SUBSCRIPTION=true

Rationale

  1. Common use case: Power users often have API keys for multiple purposes
  2. Subscription benefits: Better rate limits, included in plan, no separate billing
  3. Discoverability: Native config is more discoverable than env -u trick

Acceptance Criteria

  • User can configure Claude Code to prefer subscription auth
  • Configuration persists across sessions
  • Works regardless of ANTHROPIC_API_KEY being set
  • Documentation updated to explain auth precedence

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:authautocloseIssue will be closed automaticallyenhancementNew feature or requesthas reproHas detailed reproduction steps

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions