Claude Code login: subscription, API key, and tokens

Claude Code will pick a credential for you, silently, from whatever it finds. Knowing the order it looks in is the difference between a flat monthly fee and a metered invoice you did not expect.

By the Continuum team. We build a workbench that runs Claude Code, Codex, and their peers, so the model rates quoted here are the ones our own cost analytics ship with.

The short version

Run claude in a project and it opens a browser to sign in to your Claude account, or run claude auth login directly. Claude Code also accepts ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, an apiKeyHelper script, and a long-lived CLAUDE_CODE_OAUTH_TOKEN from claude setup-token. When several are present it uses the first match in a fixed precedence order, and environment credentials outrank your subscription login. Run /status to see which one is active. Claude Code requires a Pro, Max, Team, Enterprise or Console account; the free Claude plan does not include it, as of August 2026.

What you need to know
  • Sign in with claude auth login, or just run claude and follow the browser.
  • ANTHROPIC_API_KEY in the environment outranks your subscription login.
  • /status is the only reliable answer to "how am I being billed right now".
  • claude setup-token mints a one-year token for machines with no browser.
  • That token can make model requests only: no Remote Control, no claude.ai connectors.
  • Credentials live in the macOS Keychain, or a 0600 file on Linux and Windows.

The five ways in

How each one bills and where each one belongs.

MethodBills asSet up withRight for
Browser loginYour subscriptionclaude auth login or /loginNormal interactive work
API keyPer tokenANTHROPIC_API_KEYCI, automation, spiky usage
Bearer tokenWhatever the gateway billsANTHROPIC_AUTH_TOKENAn LLM gateway or proxy in front
Credential helperDepends on what it returnsapiKeyHelper in settingsShort-lived keys from a vault
Long-lived tokenYour subscriptionclaude setup-tokenHeadless machines you own

A cloud provider is the sixth path and sits outside this list: with Amazon Bedrock, Google Cloud Agent Platform or Microsoft Foundry configured, the provider credential is used and no browser login happens at all.

The precedence order, exactly

When more than one credential is present, Claude Code picks the first match walking down this list. It does not warn you that it skipped the others.

  1. Cloud provider credentials, when CLAUDE_CODE_USE_BEDROCK, CLAUDE_CODE_USE_VERTEX or CLAUDE_CODE_USE_FOUNDRY is set.
  2. ANTHROPIC_AUTH_TOKEN, sent as an Authorization: Bearer header. For gateways that authenticate with bearer tokens.
  3. ANTHROPIC_API_KEY, sent as X-Api-Key. Interactively you are asked once to approve or decline it and the answer is remembered. Under -p it is always used when present.
  4. apiKeyHelper script output, for rotating credentials.
  5. CLAUDE_CODE_OAUTH_TOKEN, the long-lived token from claude setup-token.
  6. Subscription OAuth credentials from /login. The default for Pro, Max, Team and Enterprise.
Auditing what is actually in scope, in one pass.
env | grep -E '^(ANTHROPIC_|CLAUDE_CODE_USE_|CLAUDE_CODE_OAUTH)'
grep -rn "ANTHROPIC_API_KEY" ~/.zshrc ~/.bashrc ~/.profile 2>/dev/null

claude auth status --text
Six credential sources ranked in the order Claude Code checks them, with the ANTHROPIC_API_KEY environment variable sitting above the subscription login walked top to bottom · first match wins bills as 1 cloud provider credentials BEDROCK · VERTEX · FOUNDRY the cloud account 2 ANTHROPIC_AUTH_TOKEN sent as Authorization: Bearer your gateway 3 ANTHROPIC_API_KEY X-Api-Key · approved once, remembered per token 4 apiKeyHelper script output, re-read on 401 whatever it returns 5 CLAUDE_CODE_OAUTH_TOKEN from claude setup-token your subscription 6 subscription OAuth the /login you did months ago your subscription An API key exported months ago for another script outranks the plan you pay for.

Signing in normally

01

Start it in a project

cd ~/code/your-project
claude

# or sign in without starting a session
claude auth login

On first launch a browser window opens. If it does not, press <kbd>c</kbd> to copy the login URL to the clipboard and open it yourself. claude auth login also takes --email to prefill, --sso to force SSO, and --console to sign in with an Anthropic Console account for API billing.

02

Finish in the browser, or paste the code

Sign in to the account holding your subscription and approve. The tab hands the credential back over a local callback and the terminal prints Login successful.

If the browser shows a login code instead of returning you to the terminal, paste it at the Paste code here if prompted prompt. That happens whenever the browser cannot reach the local callback server, which is normal in WSL2, over SSH, and inside containers. It is not a failure.

03

Confirm what you got

/status

This is the habit worth forming. The Login method row names the account, and a separate API key row appears when a key is in use. Thirty seconds here is cheaper than finding out from an invoice.

Switching accounts, and undoing an override.
/logout                # inside a session, or: claude auth logout
claude auth login      # sign in as someone else

# a stale key overriding your subscription
unset ANTHROPIC_API_KEY
claude

# scriptable: exit code 0 if logged in, 1 if not
claude auth status

Machines with no browser

A build agent or a bare server has no browser to complete the flow with. Generate the credential where a browser exists and carry it over.

Subscription billing on a machine with no browser.
# on your laptop
claude setup-token

# on the server
export CLAUDE_CODE_OAUTH_TOKEN="<token>"
claude

claude setup-token opens the same browser authorization as /login, prints a one-year token, and does not save it anywhere. Copy it at that moment or mint another. It requires a Pro, Max, Team or Enterprise plan.

What the long-lived token can and cannot do, as of August 2026.

CapabilityLong-lived tokenFull browser login
Model requestsYesYes
Locally configured MCP serversYesYes
Remote Control sessionsNoYes
claude.ai connectorsNoYes
Read by --bare modeNoNot applicable

Where credentials live

PlatformLocation
macOSThe encrypted macOS Keychain
Linux~/.claude/.credentials.json, file mode 0600
Windows%USERPROFILE%\.claude\.credentials.json, restricted by the profile directory permissions
Any, with CLAUDE_CONFIG_DIR setThe same file under that directory instead (Linux and Windows)

Claude Code owns that file through /login and /logout. Hand-editing it is not a supported way to move a credential between machines, and it is not where you change the API endpoint: that is ANTHROPIC_BASE_URL.

Rotating credentials with apiKeyHelper

For short-lived keys out of a vault, point the apiKeyHelper setting at a script that prints one. Claude Code calls it after five minutes or on an HTTP 401, and CLAUDE_CODE_API_KEY_HELPER_TTL_MS overrides that interval. If the script takes longer than ten seconds it shows a warning with the elapsed time, which is a hint that the script is doing too much work per call.

When login fails

SymptomCauseFix
Metered despite a subscriptionANTHROPIC_API_KEY set and approvedunset it, then check every shell profile
Browser never returns to the terminalCallback unreachable: WSL2, SSH, containerPaste the login code at the prompt
Login loop, never completesProxy or firewall between you and the callbackCopy the URL manually; check HTTPS_PROXY
Login expired · Please run /loginThe stored login aged outRun /login; the warning starts three days ahead
Prompted to log in every launchCredential store not persistingclaude doctor; check Keychain access
Invalid API keyMalformed, revoked, or trailing whitespaceRe-copy the key, then regenerate it
Signed in, requests still failPossibly a service incidentCheck the Anthropic status page
Exits at startup complaining about the organizationforceLoginOrgUUID in managed settingsSign in to the organization your admin pinned

Two of those deserve a sentence more. The expiry warning reads Your login expires in 3 days · run /login to renew and never blocks a request, so it is easy to scroll past; a background or Remote Control session that outlives the login simply stops making progress. And organizations can pin login with forceLoginMethod and forceLoginOrgUUID in managed settings, which also blocks sessions authenticated by ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN or apiKeyHelper, because organization membership cannot be verified for an environment credential.

Questions people ask

Run claude in a project directory and follow the browser prompt, or run claude auth login directly. Inside a session, /login signs you in again and /logout signs you out.

Because ANTHROPIC_API_KEY outranks a subscription login in the credential precedence order once you have approved it. Unset the variable, check your shell profiles for an export you forgot, and confirm with /status.

Run /status inside a session and read the Login method row. An API key row appears when a key is in use. From a script, claude auth status prints JSON and exits 0 when logged in and 1 when not.

Run claude setup-token on a machine that has a browser and set CLAUDE_CODE_OAUTH_TOKEN on the server. The token lasts a year, is printed once and never saved, and requires a Pro, Max, Team or Enterprise plan.

No. Claude Code requires a Pro, Max, Team, Enterprise or Console account, or access through Amazon Bedrock, Google Cloud Agent Platform or Microsoft Foundry, as of August 2026.

Because the browser cannot reach the local callback server, which is normal in WSL2, over SSH and inside containers. Paste the code at the Paste code here if prompted line. The login completes exactly the same way.

Run /logout, then claude auth login as the other account. The credential store holds one login per operating-system user, so switching replaces the previous one rather than adding to it.

In the encrypted macOS Keychain on macOS, and in a 0600 .credentials.json file under ~/.claude on Linux or %USERPROFILE%\.claude on Windows. Setting CLAUDE_CONFIG_DIR moves that file.

Sources

Every figure above was read from these pages on August 2026. Vendors reprice without notice; if you find a stale number, tell us.

  1. Claude Code authentication
  2. Claude Code setup and install
  3. Claude Code CLI reference
Try it

Two accounts,
side by side.

Continuum runs several Claude and Codex subscriptions at once, each with isolated credentials and its own quota gauge, so a session bills the account you picked.

free app · your subscriptions · local-first