Claude Code Authentication: Login Methods and Which One Wins

David IyaDavid Iya November 8, 2026 9 min read
A brass ring of different keys on a dark walnut desk beside a closed laptop and a small steel lockbox, with one key set apart under a warm lamp
Original image, Claude Code Club

How Claude Code authentication works

Claude Code authentication decides which account pays for and governs each request. In the desktop app you sign in with your account and that is the whole job. In the terminal, the first run of claude opens a browser window, you log in, and you see Login successful. It skips that prompt if you have already approved an API key or signed in earlier with claude auth login. If the browser does not open, press c to copy the login URL.

The trouble starts when a machine has more than one credential on it, which is common for anyone who has ever exported an API key for a side project. Claude Code does not ask which one you meant. It follows a fixed order. Knowing that order fixes most surprise login and billing questions before they become a ticket.

Every Claude Code login method

There are five kinds of account you can authenticate with. Pick by who pays and who needs control.

Claude Code login methods

MethodHow you sign inBest for
Pro, Max or Ultra subscriptionBrowser login with your claude.ai accountIndividuals
Claude for Teams or EnterpriseBrowser login with the claude.ai account your admin invitedMost teams. Teams includes SSO, admin tools and server-managed settings. Enterprise adds domain capture, role-based permissions and the compliance API
Claude ConsoleBrowser login with Console credentials after an admin inviteOrganizations that want API-based billing
Amazon Bedrock, Google Cloud's Agent Platform or Microsoft FoundryEnvironment variables set before launch, or the setup wizard behind 3rd-party platform at the login prompt (Bedrock and Google Cloud). No browser loginCompanies that already buy through a cloud provider
Claude apps gatewayCorporate SSO through /loginCompanies that self-host a gateway tied to their identity provider

My recommendation for a team without a cloud commitment is Claude for Teams or Enterprise. People get Claude Code and Claude on the web on one bill, and you skip handing out and rotating API keys. If procurement already runs through a cloud provider, see the guides for Bedrock, Vertex AI and Microsoft Foundry.

The Console has two roles worth knowing. The Claude Code role can only create Claude Code API keys, while the Developer role can create any kind of API key. Give people the narrower one unless they build on the API. Console users can also sign in without creating a key at all (v2.1.242 or later). Claude Code then keeps a refreshing OAuth login as a profile instead of a static key, which is the better default because there is no long-lived secret sitting on the machine.

Which credential Claude Code uses first

When several credentials are present, Claude Code uses the first one it finds in this order:

  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 a bearer token. This is for gateways and proxies.
  3. ANTHROPIC_API_KEY, sent as the X-Api-Key header. In an interactive session you approve it once and the choice is remembered. In non-interactive mode (-p) it is always used when present.
  4. The output of your apiKeyHelper script, for rotating credentials such as short-lived tokens from a vault.
  5. CLAUDE_CODE_OAUTH_TOKEN, the long-lived token from claude setup-token.
  6. Anthropic profile and federation credentials, the ones used by the ant CLI and Workload Identity Federation. A profile written by ant auth login only ranks here when you name it in ANTHROPIC_PROFILE. Otherwise it ranks below /login.
  7. Your subscription login from /login. This is the default for Pro, Max, Ultra, Team and Enterprise users.

A signed-in Claude apps gateway session sits outside this list and outranks all of it. When one exists, the CLI uses the gateway token even if a cloud provider variable is set.

Two limits on this order are worth remembering. Claude Desktop and cloud sessions do not read these environment variables or call apiKeyHelper. They use OAuth, unless a desktop session runs a third-party inference configuration, which uses that configuration's credential. And cloud sessions always use your subscription, even if you put an API key in the cloud environment. So a setup that works in the terminal can behave differently in the desktop app, and that is expected.

How to lock Claude Code login to your organization

An admin controls sign-in with three managed settings: forceLoginMethod chooses the kind of login, forceLoginOrgUUID requires claude.ai logins to belong to your organization, and allowedProviders (v2.1.285 or later) lists which services a managed machine may reach Claude through. A typical policy sets forceLoginMethod to "claudeai", forceLoginOrgUUID to a list holding your organization ID, and allowedProviders to "anthropic" and "bedrock".

  1. Find your organization ID in claude.ai admin settings.
  2. Deploy the keys through your device management tooling. A developer only receives server-managed settings after authenticating into your organization, so those cannot redirect a first login. See Claude Code managed settings for delivery on each operating system.
  3. If you also distribute server-managed settings from claude.ai, set both login keys there too until every client runs v2.1.299 or later.
  4. To allow an LLM gateway, add "customEndpoint" to allowedProviders and set the gateway URL in the managed env block of the same source.
  5. Test on one managed machine with a personal account and with an API key in the shell. Both should be refused at startup.

These settings block ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN and apiKeyHelper at startup, because organization membership cannot be verified for those credentials. That part works the way you would hope. The gaps below are the part most rollouts miss.

Where the login controls stop

GapWhat actually happensWhat I would do
The terminal login screenIt pre-selects the method in forceLoginMethod without enforcing it, so a developer can still complete a Console login thereDo not hand out Console invites to people who do not need them, and review the Members page
Console loginsforceLoginOrgUUID only pre-selects the organization on the Console sign-in page. It does not check which organization the credential belongs toTreat this as a convenience, not a control, and audit Console membership
claude setup-token and /install-github-appThey enforce only forceLoginMethod, so they can mint a token in a different organizationDecide who may run them and write that into your policy
Anthropic profiles and federation credentialsThey are not blocked unless an API key style credential is also on the machine, and the keys do not check which organization the profile belongs toCheck /status on a sample of machines. A Profile row names the source
allowedProviders set only in server-managed settingsIt reaches only sessions that fetch your organization's settingsDeliver it with device management. Keep the server-managed copy for machines you cannot reach
Gateway sign-inforceLoginOrgUUID does not apply because the gateway does not authenticate against an Anthropic organizationRestrict access in your gateway's identity provider, and keep the login keys out of the settings the gateway serves

Authentication for CI, scripts and unattended runs

For CI and scripts where nobody can click a browser, run claude setup-token. It uses the same browser approval as /login and prints a one-year OAuth token. It does not save the token anywhere, so copy it and set it as CLAUDE_CODE_OAUTH_TOKEN wherever the job runs, using your CI's secret store. It needs a Pro, Max, Ultra, Team or Enterprise plan.

  • The token only makes model requests. It cannot start Remote Control sessions or fetch claude.ai connectors. MCP servers you configure locally still work.
  • Bare mode does not read CLAUDE_CODE_OAUTH_TOKEN. If your script passes --bare, use ANTHROPIC_API_KEY or apiKeyHelper instead.
  • If you use apiKeyHelper, keep the script fast. Past 10 seconds, Claude Code shows a warning in the prompt bar. If the script errors, times out or prints nothing, requests fail within three attempts.
  • A /login credential warns you at startup when it is within three days of expiring. Renew early for unattended sessions, because a background or Remote Control session that outlives its login stops making progress until you sign in again.

My take: use one token per job and record who generated it, because it lasts a year and is tied to that person's plan. For wiring it into a pipeline, see Claude Code GitHub Actions and headless mode.

Where credentials are stored and using two accounts

Where Claude Code stores credentials

SystemLocation
macOSThe encrypted macOS Keychain. If the Keychain rejects the write, such as when it is locked in an SSH session, the login goes in ~/.claude/.credentials.json with file mode 0600
Linux~/.claude/.credentials.json with file mode 0600
Windows%USERPROFILE%\.claude\.credentials.json, restricted to your user account by default through your profile directory's access controls

To stay signed in to a work and a personal account at once, give each its own configuration directory with CLAUDE_CONFIG_DIR. An alias such as claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude' in your shell profile does it, and each directory keeps its own settings, session history and login. The exception is a Console sign-in without an API key, which is stored outside that directory, so two of those do not stay separate.

Fix common Claude Code login problems

Symptoms and fixes

What you seeLikely causeFix
Auth errors even though your subscription is activeANTHROPIC_API_KEY is set and belongs to a disabled or expired organizationRun unset ANTHROPIC_API_KEY, then check /status
Login prompt appears after you already signed inExpired sign-in, an organization or login method your admin requires, or a version before v2.1.290Log in again with the account your admin requires, or update Claude Code
Login expired, please run /loginThe stored login expired and could not be refreshedRun /login. /status shows the expired login's organization and email
Your apiKeyHelper script is failingThe script errored, timed out or printed nothingRun the script by hand and fix what it prints
Connectors or /schedule are missingA profile or federation source is selected, and those features need your claude.ai loginUnset ANTHROPIC_PROFILE or either federation variable. For an active profile, run /logout or ant auth logout depending on how it was created
Your login does not stick after /loginCLAUDE_CODE_OAUTH_TOKEN is still set, so the switch only lasts for that sessionRemove the variable from your shell profile and any settings file that sets it

To start over, type /logout at the prompt. It also resets your first-launch setup, so the next run walks you through login and setup again.

Free Claude Code drops, straight to your inbox

Short, practical drops on skills, MCP, agents, prompts, and more. No spam, unsubscribe anytime.

Frequently asked questions

How do I log in to Claude Code?

Sign in through the desktop app, or run claude in a terminal and complete the browser login with a Pro, Max, Ultra, Team, Enterprise or Console account. Bedrock, Google Cloud and Foundry use environment variables instead of a browser login.

Does ANTHROPIC_API_KEY override my Claude subscription?

Yes, once you approve it. The API key ranks above your /login subscription credential. In non-interactive mode it is used whenever it is present. Run unset ANTHROPIC_API_KEY to fall back to your subscription and check /status to confirm.

How do I check which credential Claude Code is using?

Run /status. It shows the active login method, and when a login and an API key are both configured it marks the one that is not in use. If a profile is the source, a Profile row names it.

Does Claude Code support SSO?

Yes. Claude for Teams and Enterprise include SSO, the Console can be set up with SSO, and a self-hosted Claude apps gateway signs developers in with corporate SSO through your identity provider.

How do I authenticate Claude Code in CI?

Generate a one-year OAuth token with claude setup-token and set it as CLAUDE_CODE_OAUTH_TOKEN from your secret store, or use ANTHROPIC_API_KEY. In bare mode the OAuth token is not read, so use an API key or apiKeyHelper.

Can I stop developers logging in with personal accounts?

Set forceLoginMethod and forceLoginOrgUUID in managed settings and deploy them through device management. Claude Code then refuses claude.ai logins from other organizations. Console logins and claude setup-token have gaps, so test them on a managed machine.

Last reviewed by David Iya on November 8, 2026

David Iya

Written by

David Iya

Forbes 30 Under 30 · Y Combinator

Keep reading

Claude CodeMemory

Why does Claude Code forget everything between sessions?

Claude Code forgets between sessions because every session starts with a fresh, empty working memory. Two things carry over: a file called CLAUDE.md that you write, and notes Claude saves for itself, called auto memory. Here is how each one works, what gets lost when a long conversation is squeezed down, and what to do so you stop repeating yourself.

Duncan Rogoff 9 min
Read article
Claude CodeSetup

How to Roll Out Claude Code to Your Team (6-Step Plan)

To roll out Claude Code to your team, make five admin decisions first (provider, how settings reach devices, what to enforce, how you will see usage, and data handling), verify the policy with /status, run a small pilot, then launch with one real first task and a channel someone owns. Champions carry it from there. Here is the plan in order, with the launch checklist and the errors you will see on day one.

David Iya 9 min
Read article

Ready to build it yourself?

Join Claude Code Club, the #1 community for learning claude code, for $9/month.

← Back to the blog