ServicesAboutNotesContact Get in touch →
EN FR
Note

Claude Code Authentication Options

The two ways to authenticate Claude Code — subscription OAuth and API keys — when to use each, and the precedence rule that trips people up

Planted
claude codeai

Claude Code supports two authentication methods. The choice affects billing, rate limits, and suitability for automated workflows. The subscription path is simpler for interactive use; API keys are required for CI/CD and non-interactive automation.

Option A: Claude Pro or Max Subscription (OAuth)

Run claude in your terminal and it opens your browser for OAuth. Sign in with your Anthropic account, and you’re authenticated. The credentials persist across sessions — you don’t need to sign in again unless your token expires or you explicitly sign out.

This is the right starting point for most analytics engineers. You get the full Claude Code experience — Sonnet and Opus models, all tools, no per-token billing — bundled into your existing subscription. There’s no API billing setup, no environment variable management, no risk of surprise charges from a long debugging session.

The subscription tiers matter for how much you can use Claude Code:

  • Pro gives you access to Claude Code with usage limits. For learning and light daily use, this is sufficient. You’ll hit the limit if you’re doing heavy work (full-day refactoring sessions, large codebase onboarding).
  • Max significantly increases the usage cap. If Claude Code becomes a daily tool in your workflow, Max is where most analytics engineers land. The higher limit means you can run extended sessions without throttling.

To check your current usage against your plan’s limits, run /usage inside a Claude Code session.

Option B: API Key

Set the ANTHROPIC_API_KEY environment variable in your shell:

Terminal window
export ANTHROPIC_API_KEY=sk-ant-...

Add it to your shell profile (~/.zshrc or ~/.bashrc) to persist across terminal sessions.

API key authentication bills per token — you pay for exactly what you use, with no monthly ceiling. This makes it the right choice for:

  • CI/CD pipelines where Claude Code runs non-interactively (claude -p "run tests and report" in a GitHub Action)
  • Team automation where multiple processes need Claude Code access
  • Cost tracking when you need per-project billing attribution
  • High-volume usage that exceeds subscription limits

For a first session, API key setup adds unnecessary friction. You need to create the key in the Anthropic console, configure billing, set the environment variable, and manage the secret. None of that helps you learn the tool faster.

The Precedence Rule

This is the detail that trips people up: if ANTHROPIC_API_KEY is set in your environment, it takes precedence over your subscription. Claude Code uses the API key and bills accordingly, even if you have an active Pro or Max plan.

This means if you set up an API key for a CI/CD experiment and forget to unset it, your interactive sessions silently switch to per-token billing. You’re paying by the token when you thought you were using your subscription.

To check which authentication method is active:

Terminal window
echo $ANTHROPIC_API_KEY

If this returns a value and you want to use your subscription instead, unset it:

Terminal window
unset ANTHROPIC_API_KEY

For analytics engineers who work across multiple client projects, this precedence rule interacts with tools like direnv. If one client project has an .envrc that sets ANTHROPIC_API_KEY for their billing, navigating into that directory silently switches your Claude Code billing. Useful when intentional, confusing when not.

Practical Recommendation

Start with your subscription. Learn the tool, develop your CLAUDE.md, build comfort with the CLI basics. When you’re ready to integrate Claude Code into automation — hooks, CI/CD, scheduled tasks — switch to an API key for those specific workflows.

The two methods coexist cleanly. Use your subscription for interactive sessions (daily development work) and an API key for non-interactive automation (where claude -p runs in a pipeline). Just be deliberate about which one is active in each context.