Authentication, Plans & Access

Pro, Max, Team, Console, and CI tokens

Beginner 13 minBuilderDecision-maker
What you'll be able to do
  • Log in to Claude Code three different ways and verify which account is active
  • Choose the right plan or billing model — Pro, Max, Team, or API pay-as-you-go
  • Predict which credential Claude Code uses by walking the six-step auth precedence chain
  • Handle API keys and credentials securely, avoiding the shell-profile and precedence traps
  • Generate a long-lived OAuth token and wire it into a CI pipeline
At a glance

Claude Code needs a paid plan — there is no free tier — so this lesson gets you logged in the right way, explains which subscription or API billing fits you, and demystifies the six-step credential precedence chain that decides who Claude Code talks to. You will also learn how to store secrets safely and mint a one-year token for CI.

  1. 1The mental model: identity, not install
  2. 2Three ways to log in
  3. 3The auth precedence chain
  4. 4Plans and billing: what to buy
  5. 5Handling credentials securely
  6. 6Tokens for CI and automation

The mental model: identity, not install

Installing Claude Code is the easy part. The thing that actually decides whether you can run it — and whose usage you spend — is authentication: which identity Claude Code presents when it calls Anthropic.

There are two billing worlds, and you pick one:

  • Subscription (OAuth) — you log in with your Claude.ai account (Pro, Max, Team, or Enterprise). Usage counts against your plan's limits. This is what most individual developers want.
  • API (pay-as-you-go) — you authenticate with a key from the Claude Console and pay per token. This suits teams that already bill through the API, or anyone who wants metered, per-token cost.

The single most important fact: Claude Code is not on the free tier. A free Claude.ai account cannot run it at all. You need Pro, Max, Team, Enterprise, or a Console (API) account.

The second most important fact: when several credentials exist on one machine, Claude Code follows a strict precedence order to decide which one wins. Most "why is it billing the wrong thing?" confusion comes from not knowing that order — so we'll make it concrete.

Watch out

No free Claude Code

Free Claude.ai accounts cannot use Claude Code, full stop. Every paid plan — Pro, Max, Team (both Standard and Premium seats), and Enterprise — includes Claude Code; the tiers differ in usage limits, not access. If claude greets you with an upgrade prompt, you're on a free account. See claude.com/pricing for the current lineup.

Three ways to log in

There are three entry points to authentication. Pick whichever fits your situation.

1. Browser login (the default). Run claude in any project directory. On first launch it opens a browser to sign in with your Claude.ai account. If the browser doesn't open, press c to copy the login URL and paste it manually. If sign-in shows you a login code instead of redirecting back, paste that code at the terminal's Paste code here if prompted prompt — this is normal in WSL2, SSH sessions, and containers where the local callback can't be reached.

2. Inside a session. Already running? Type /login to authenticate or switch accounts, and /logout to sign out and re-authenticate.

3. An environment variable. Set ANTHROPIC_API_KEY (a Console key) and Claude Code uses it without any browser flow — handy for scripts and CI, but read the security section first, because this variable has sharp edges.

Claude Code also ships dedicated auth subcommands for scripting:

bash
claude auth login              # browser/OAuth login
claude auth login --console    # log in with Claude Console credentials
claude auth login --email      # email-based login flow
claude auth login --sso        # single sign-on flow
claude auth logout             # sign out
claude auth status             # machine-readable JSON; exit 0 if logged in, 1 if not
claude auth status --text      # human-readable status

Inside a session, /status tells you which authentication method is currently active — the fastest way to confirm you're spending the account you think you are.

Tip

Confirm before you spend

After any login change, run /status (in-session) or claude auth status (in a script). The auth status exit code — 0 for logged-in, 1 for not — makes it a clean precondition check at the top of a CI job.

The auth precedence chain

When more than one credential is present, Claude Code does not merge or guess — it walks a fixed list top to bottom and uses the first one it finds. Internalize this order and surprise billing disappears.

#SourceTrigger / headerUse it for
1Cloud provider credsCLAUDE_CODE_USE_BEDROCK / CLAUDE_CODE_USE_VERTEX / CLAUDE_CODE_USE_FOUNDRY setBedrock, Vertex AI, or Microsoft Foundry
2ANTHROPIC_AUTH_TOKENsent as Authorization: BearerLLM gateways / proxies that use bearer tokens
3ANTHROPIC_API_KEYsent as X-Api-KeyDirect Anthropic API access (Console key)
4apiKeyHelpersettings.json script outputDynamic / rotating creds (e.g. vault-issued)
5CLAUDE_CODE_OAUTH_TOKENlong-lived OAuth tokenCI pipelines, scripts without browser login
6Subscription OAuthcredentials from /loginDefault for Pro / Max / Team / Enterprise

Read it as a fall-through: if no cloud-provider flag is set, Claude Code checks ANTHROPIC_AUTH_TOKEN; if that's empty it checks ANTHROPIC_API_KEY; and so on down to your subscription login, which is the catch-all default.

Two distinctions trip people up:

  • ANTHROPIC_AUTH_TOKEN is not ANTHROPIC_API_KEY. The auth token is a bearer token (Authorization: Bearer …) for gateways; the API key is an Anthropic Console key (X-Api-Key). Different headers, different purposes, different precedence rank.
  • A Console API key (step 3) outranks your subscription login (step 6). So if you have both a Pro subscription and ANTHROPIC_API_KEY exported, the API key wins — even though you'd probably rather spend the subscription.

Key insight

First match wins — it's a waterfall, not a merge

Claude Code never combines credentials. The instant it finds a populated source going down the list, it stops and uses that one. Debugging "wrong account" issues is just asking: what is the highest-ranked source currently set on this machine?

Plans and billing: what to buy

Here's the full landscape so you can pick deliberately. Prices are monthly, per the official pricing page.

PlanPriceClaude Code?Best for
Free$0NoNot usable with Claude Code
Pro$20/moYesMost individual developers
Maxfrom $100/moYesSeveral usage tiers above Pro — heavy daily to all-day power use
Team Standardper-seatYesTeams; includes Claude Code, central billing
Team Premiumper-seat (higher tier)YesTeams wanting more usage headroom per seat
API (Console)pay-as-you-goYesMetered per-token billing — see pricing page for current rates

How to choose:

  • Solo dev, predictable bill? Start with Pro. If you hit limits often, step up to a Max tier — same subscription auth, more headroom. Check claude.com/pricing for current Max usage tiers and prices.
  • A team? A Team plan gives you central billing; both Standard and Premium seats include Claude Code, with Premium seats getting more usage per seat.
  • You want exact, per-token cost or already bill via the API? Use a Console account with ANTHROPIC_API_KEY. There's no monthly floor — you pay for what you use.

Subscription plans give you bundled, rate-limited usage at a flat price; the API gives you metered, uncapped spend. Neither is "better" — it's flat-rate predictability versus pay-per-use precision.

Note

Coming June 15, 2026: a separate credit pool for headless use

Starting June 15, 2026, Agent SDK and claude -p (headless/print mode) usage on subscription plans draws from a new monthly Agent SDK credit, kept separate from your interactive usage limits. Translation: scripted and automated runs get their own budget rather than eating into your interactive sessions. (Doesn't affect API/Console billing.)

Handling credentials securely

Two rules and a storage map will keep you out of trouble.

Rule 1 — Never write ANTHROPIC_API_KEY to your shell profile. Putting export ANTHROPIC_API_KEY=sk-... in ~/.zshrc or ~/.bashrc leaks the key into the environment of every child process you ever launch — a broad, persistent exposure. Set it only in the specific shell or CI job that needs it, or better, use a credential helper (below).

Rule 2 — Remember the precedence trap. Because the Console API key (step 3) outranks your subscription (step 6), an ANTHROPIC_API_KEY left lying around will silently hijack your auth. If that key belongs to a disabled or expired org, you get authentication failures even though your subscription is perfectly fine. The fix:

bash
unset ANTHROPIC_API_KEY   # fall back to subscription OAuth

Then run /status to confirm the subscription is now active.

Where credentials actually live:

OSStorageProtection
macOSEncrypted KeychainOS-managed encryption
Linux~/.claude/.credentials.jsonfile mode 0600 (owner-only)
Windows%USERPROFILE%\.claude\.credentials.jsoninherits your user-profile ACLs

Claude Code manages this file for you through /login and /logout — you should never hand-edit it. For dynamic or short-lived credentials (e.g. tokens pulled from a vault), use the apiKeyHelper setting: a shell script in settings.json that returns a key on demand. It's called every 5 minutes or on an HTTP 401, with a custom TTL via CLAUDE_CODE_API_KEY_HELPER_TTL_MS; if it takes over 10 seconds, Claude Code warns you.

Watch out

The classic gotcha, in one line

"Claude Code worked yesterday and now errors on login" → check for a stray ANTHROPIC_API_KEY. It silently outranks your subscription; unset ANTHROPIC_API_KEY usually fixes it.

Tokens for CI and automation

CI runners have no browser, so OAuth login won't work there. The answer is a long-lived token you generate once and inject as an environment variable.

bash
claude setup-token

This walks you through OAuth authorization and prints a one-year OAuth token to the terminal. It is not saved anywhere — copy it immediately and store it in your CI provider's secret manager (GitHub Actions secrets, etc.). Then expose it to the job:

bash
export CLAUDE_CODE_OAUTH_TOKEN=your-token

That's precedence step 5 — it authenticates against your subscription, so setup-token requires a Pro, Max, Team, or Enterprise plan. The token is scoped to inference only and cannot start Remote Control sessions.

yaml
# GitHub Actions — minimal sketch
jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: curl -fsSL https://claude.ai/install.sh | bash
      - run: claude -p "review the diff" --permission-mode dontAsk
        env:
          CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}

One sharp edge: CLAUDE_CODE_OAUTH_TOKEN does not work in --bare mode. Bare mode strips the machinery that reads it, so a script using --bare must authenticate with ANTHROPIC_API_KEY or an apiKeyHelper instead.

Tip

Treat the CI token like any secret

It's a one-year credential to your account. Store it in a secrets manager, never in the repo or a committed YAML file, and rotate it by re-running claude setup-token if it's ever exposed. Inject it via env: from ${{ secrets.* }}, as above.

Try it: Audit your auth and mint a CI token

Get hands-on with the precedence chain and a real token. 1) Inspect what's active: start a session and run /status (or claude auth status in a script) and note which authentication method Claude Code reports. 2) Trigger the precedence trap on purpose: in a throwaway shell, run export ANTHROPIC_API_KEY=sk-fake-not-a-real-key, start Claude Code, and observe how the stray key now takes precedence (you'll see an auth path change or failure). Then run unset ANTHROPIC_API_KEY, restart, and confirm /status shows your subscription again. 3) Check your storage: on macOS confirm credentials live in the Keychain; on Linux run ls -l ~/.claude/.credentials.json and verify the mode is 0600 (do NOT print its contents). 4) Mint a CI token: run claude setup-token, copy the printed one-year token into a password manager or a CI secret (never a file in the repo), and note that it would be injected as CLAUDE_CODE_OAUTH_TOKEN. 5) Write three sentences: which auth method you started on, what the stray API key did to precedence, and one reason you would not put ANTHROPIC_API_KEY in your ~/.zshrc. This cements the waterfall model and safe credential handling.

Key takeaways

  1. 1Claude Code is never free — you need a paid plan: Pro, Max, Team (Standard or Premium), Enterprise, or an API/Console account. See claude.com/pricing for current tiers and prices.
  2. 2Log in three ways: run `claude` for browser OAuth, `/login` inside a session, or set `ANTHROPIC_API_KEY`. Verify with `/status` or `claude auth status`.
  3. 3Precedence is a strict waterfall — cloud creds → `ANTHROPIC_AUTH_TOKEN` → `ANTHROPIC_API_KEY` → `apiKeyHelper` → `CLAUDE_CODE_OAUTH_TOKEN` → subscription OAuth — and the first populated source wins.
  4. 4A Console `ANTHROPIC_API_KEY` outranks your subscription; if it's stale it breaks auth. `unset ANTHROPIC_API_KEY` to fall back, and never put the key in `~/.zshrc`/`~/.bashrc`.
  5. 5Credentials live in the macOS Keychain or `~/.claude/.credentials.json` (mode `0600` on Linux); let `/login` and `/logout` manage that file.
  6. 6For CI, `claude setup-token` mints a one-year OAuth token set as `CLAUDE_CODE_OAUTH_TOKEN` (requires a subscription; doesn't work with `--bare`).

Quiz

Lock in what you learned

Check your understanding

0 / 4 answered

1.You have an active Claude Pro subscription, and you've also exported `ANTHROPIC_API_KEY` (a Console key) in your shell. Which credential will Claude Code use, and why?

2.A teammate on a free Claude.ai account can't get Claude Code to run, and asks whether joining your Team plan would fix it. What's the accurate answer?

3.Why is putting `export ANTHROPIC_API_KEY=sk-...` in your `~/.zshrc` considered a security and reliability problem?

4.You're wiring Claude Code into a GitHub Actions pipeline that runs `claude -p`. What's the correct way to authenticate?

Go deeper

Hand-picked sources to keep learning