[Feature] Support CLAUDE_CODE_OAUTH_TOKEN for `claude -p` (print mode)

Resolved 💬 3 comments Opened Jan 27, 2026 by hflier Closed Jan 30, 2026

Summary

claude -p / claude --print mode currently requires an API key (ANTHROPIC_API_KEY) and does not support OAuth token authentication via CLAUDE_CODE_OAUTH_TOKEN.

Current Behavior

# This works (interactive mode with OAuth)
CLAUDE_CODE_OAUTH_TOKEN=<token> claude
# ✅ Authenticates successfully

# This does NOT work (print mode with OAuth)
CLAUDE_CODE_OAUTH_TOKEN=<token> claude -p "hello"
# ❌ Requires ANTHROPIC_API_KEY

Expected Behavior

claude -p should accept CLAUDE_CODE_OAUTH_TOKEN as an alternative to ANTHROPIC_API_KEY, just like interactive mode does.

Rationale

  1. Consistency: Interactive mode supports OAuth, print mode should too
  2. Claude Agent SDK parity: The Claude Agent SDK already supports both authentication methods. claude -p should have feature parity.
  3. Subscription users: Users with Max/Pro subscriptions should be able to use print mode without needing a separate API key
  4. Scripting/automation: Many users want to use print mode for automation while authenticated via their subscription

Proposed Solution

When ANTHROPIC_API_KEY is not set, check for CLAUDE_CODE_OAUTH_TOKEN and use OAuth authentication for the API request, same as interactive mode does.

Environment

  • Claude Code version: 2.1.19
  • Platform: macOS

View original on GitHub ↗

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