Claude Code authentication: subscriptions, API keys, and cloud providers
PLClaude Code authenticates with a Claude subscription login (Pro, Max, Team, or Enterprise), a Claude Console account billed at API rates, or cloud-provider credentials for Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, or Claude Platform on AWS. When several credentials are present, a fixed precedence order decides which one is used, and /status shows the active method.
This page is for developers who are logging in for the first time, on a laptop, over SSH, or in CI. Tech leads who standardize the login for a team will find the organization controls near the end. A typical failure looks like this: you pay for Max, but your shell profile still exports ANTHROPIC_API_KEY from a side project, so every session bills that key instead. Or your pipeline has no browser, and the first job that runs claude hangs at a login prompt.
What you’ll walk away with from Claude Code authentication
Section titled “What you’ll walk away with from Claude Code authentication”- A working login for the billing model you actually want, verified by a command rather than by a hopeful prompt.
- The precedence order that decides which credential wins, and a prompt that audits your machine for conflicts.
- A browser-free token for CI and a rotating-key helper for vault-backed setups.
- Managed settings that keep a team’s logins inside one organization, with the gaps those settings leave.
All commands on this page were checked against the installed CLI, Claude Code 2.1.283 (claude --help, claude auth --help), and the official authentication documentation on 2026-09-26.
Which Claude Code login method should you choose?
Section titled “Which Claude Code login method should you choose?”Choose by who pays and who administers access. The login flow is the easy part.
| Method | Choose it when | Billing | How you sign in |
|---|---|---|---|
| Claude Pro or Max | You are an individual developer | Flat monthly plan with rolling 5-hour and weekly usage windows | claude, then Claude account with subscription |
| Claude for Teams or Enterprise | Your company wants one bill, seats, and SSO | Per seat; Enterprise adds usage at API rates | claude with the claude.ai account your admin invited |
| Claude Console | You want pay-per-token billing and per-workspace cost tracking | Tokens at API rates | claude auth login --console, or ANTHROPIC_API_KEY |
| Amazon Bedrock | AI traffic must stay on your AWS account | AWS bill | Setup wizard or CLAUDE_CODE_USE_BEDROCK=1 |
| Google Cloud’s Agent Platform (formerly Vertex AI) | AI traffic must stay on your Google Cloud project | Google Cloud bill | Setup wizard or CLAUDE_CODE_USE_VERTEX=1 |
| Microsoft Foundry | AI traffic must stay on Azure | Azure bill | CLAUDE_CODE_USE_FOUNDRY=1 (no wizard) |
| Claude Platform on AWS | You buy Anthropic’s platform through AWS | AWS bill | CLAUDE_CODE_USE_ANTHROPIC_AWS=1 |
The free Claude plan does not include Claude Code. As of 2026-09-26 the published plan prices are Pro $20 per month, Max 5x $100, and Max 20x $200; Team and Enterprise are priced per seat (claude.com/pricing). For what each option costs under agent workloads, see Claude Code cost control. If your company routes all model traffic through its own proxy, read LLM gateway configuration instead of this page.
Log in with a Claude subscription
Section titled “Log in with a Claude subscription”This is the default path for Pro, Max, Team, and Enterprise users.
-
In your terminal, start Claude Code:
Terminal window claudeTo sign in without opening a session, run
claude auth logininstead. It uses the Claude subscription by default; add--ssoto force your company’s SSO flow or--email you@example.comto pre-fill the login page. -
Choose Claude account with subscription at the login prompt. A browser window opens. If it does not, press
cto copy the login URL and paste it into any browser. -
Sign in. If the browser shows a code instead of returning to the terminal, paste the code at the
Paste code here if promptedprompt. This happens over SSH, in WSL2, and in containers, where the browser cannot reach Claude Code’s local callback server. -
Wait for
Login successful, then pressEnter. -
Confirm what you are logged in as from the terminal:
Terminal window claude auth status --textInside a session,
/statusshows the same information, including the login method, organization, and email.
Team and Enterprise members use the same flow with the claude.ai account their admin invited. Enterprise adds domain capture, role-based permissions, and the compliance API on top of Teams.
Use a Claude Console account for API billing
Section titled “Use a Claude Console account for API billing”Console billing charges per token, which suits bursty usage and teams that already track spend in the Console. An admin must invite you to the Console organization first, with either the Claude Code role (can create only Claude Code keys) or the Developer role.
claude auth login --consoleFrom v2.1.242, the Console login (Anthropic Console account at the login prompt, or claude auth login --console) asks how to sign in:
- Sign in with your Console account (labeled recommended) stores a refreshable OAuth login and creates no API key. Prefer it: there is no static secret on disk to leak.
- Create an API key (labeled legacy) creates a key and stores it with your other credentials.
The keyless sign-in also signs you out of any claude.ai login stored on the machine, so do not use it on a laptop where you want to keep your subscription login; /logout removes and revokes the credential it wrote.
Claude Code skips that choice and always creates a key when you run against a cloud provider or when a settings file sets forceLoginOrgUUID or forceLoginMethod to "claudeai" or "console", or when a managed settings source on the machine exists but can’t be read. Unset ANTHROPIC_API_KEY before you sign in without a key.
You can also supply a key directly through ANTHROPIC_API_KEY. In an interactive session, Claude Code asks you once to approve the key and remembers the answer; the “Use custom API key” toggle in /config changes it later. With claude -p, the key is always used when present. Load the key from your secret manager rather than writing it into ~/.zshrc, or use apiKeyHelper.
Configure a cloud provider
Section titled “Configure a cloud provider”With a cloud provider, no browser login is needed. Your provider’s own credentials authenticate, and requests are billed to your cloud account. For Bedrock and Google Cloud’s Agent Platform, the easiest path is the wizard: run claude, choose 3rd-party platform at the login prompt, and pick your provider. The wizard detects your credentials, asks for a region, checks which Claude models you can invoke, and saves the result to the env block of ~/.claude/settings.json.
First enable an Anthropic model in the Bedrock console’s model catalog and submit the use-case form. Then either run the wizard (reopen it later with /setup-bedrock; until CLAUDE_CODE_USE_BEDROCK=1 is set the command is hidden from the menu, so type it in full) or set the variables yourself:
# Terminal: sign in with an IAM Identity Center profile, then point Claude Code at Bedrockaws sso login --profile YOUR_PROFILEexport CLAUDE_CODE_USE_BEDROCK=1export AWS_PROFILE=YOUR_PROFILEexport AWS_REGION=us-east-1 # optional when the profile already sets a regionclaudeYOUR_PROFILE is the profile name in ~/.aws/config. Prefer a profile over static AWS_ACCESS_KEY_ID exports. To renew an expired SSO session automatically, add "awsAuthRefresh": "aws sso login --profile YOUR_PROFILE" to your settings; Claude Code runs it only when your credentials look expired and an STS GetCallerIdentity check confirms it.
Enable the API for your project and request access to the Claude models in Model Garden. Then run the wizard (reopen it with /setup-vertex) or set the variables. The environment variables still use the old “Vertex” name:
# Terminal: Application Default Credentials, then point Claude Code at your projectgcloud auth application-default loginexport CLAUDE_CODE_USE_VERTEX=1export CLOUD_ML_REGION=globalexport ANTHROPIC_VERTEX_PROJECT_ID=YOUR_PROJECT_IDclaudeglobal gives the widest model availability. For a model that is not served on the global endpoint, keep global and override that one model’s region, for example export VERTEX_REGION_CLAUDE_HAIKU_4_5=us-east5.
Foundry has no setup wizard (checked against Claude Code 2.1.283 on 2026-09-26), so the environment variables are the only configuration path:
# Terminal: Entra ID through the Azure default credential chainaz loginexport CLAUDE_CODE_USE_FOUNDRY=1export ANTHROPIC_FOUNDRY_RESOURCE=YOUR_RESOURCE_NAMEclaudeYOUR_RESOURCE_NAME is your Azure resource name; Claude Code builds the endpoint URL from it. If you cannot use Entra ID, set ANTHROPIC_FOUNDRY_API_KEY from your secret store instead of running az login.
Foundry has no startup model check, so pin ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, and ANTHROPIC_DEFAULT_HAIKU_MODEL to the deployment names you created; otherwise requests fail when a built-in default is not deployed in your resource.
# Terminal: SigV4 through your AWS profileexport CLAUDE_CODE_USE_ANTHROPIC_AWS=1export ANTHROPIC_AWS_WORKSPACE_ID=YOUR_WORKSPACE_IDexport AWS_REGION=us-east-1export AWS_PROFILE=YOUR_PROFILEclaudeANTHROPIC_AWS_WORKSPACE_ID is required and starts with wrkspc_. This provider is opt-in even when AWS credentials are present, and Bedrock and Foundry take precedence, so unset CLAUDE_CODE_USE_BEDROCK and CLAUDE_CODE_USE_FOUNDRY first. Without federated AWS credentials, set ANTHROPIC_AWS_API_KEY to a workspace key from the AWS Console (Claude Platform on AWS → API keys); it overrides SigV4.
Run /status after the first prompt: it shows the provider and, for Bedrock, the resolved region, and its source when it came from your AWS config files or the default fallback.
Authenticate Claude Code in CI and on headless machines
Section titled “Authenticate Claude Code in CI and on headless machines”A pipeline cannot click through a browser. You have two options:
- A subscription token. Run
claude setup-tokenon your own machine. It opens the same browser flow as/loginand prints a one-year OAuth token without saving it. Store the token in your CI secret store asCLAUDE_CODE_OAUTH_TOKEN. It requires a Pro, Max, Team, or Enterprise plan and can only make model requests: it cannot start Remote Control sessions or fetch claude.ai connectors. Keep it out of your laptop’s shell profile: running/loginwhile it is set switches only the current session, and every new session reads the variable again. - A Console API key. Store it as
ANTHROPIC_API_KEY. Use this, or anapiKeyHelperpassed with--settings, for any job that runsclaude --bare, because bare mode never readsCLAUDE_CODE_OAUTH_TOKEN, the Keychain, or a/loginsession. A key in a dedicated Console workspace also keeps pipeline spend separate from people’s spend.
Inject the secret only into the step that runs Claude Code. Never let a job that checks out an untrusted pull request run with it in the environment. The CI/CD page has the workflow, and agent identity and secrets covers scoping and rotation.
Which credential does Claude Code use when several are set?
Section titled “Which credential does Claude Code use when several are set?”Claude Code picks exactly one credential, in this order:
- Cloud provider credentials, when
CLAUDE_CODE_USE_BEDROCK,CLAUDE_CODE_USE_VERTEX, orCLAUDE_CODE_USE_FOUNDRYis set. ANTHROPIC_AUTH_TOKEN, sent as a bearer token (for LLM gateways and proxies).ANTHROPIC_API_KEY, once you approve it in an interactive session.- The output of an
apiKeyHelperscript. CLAUDE_CODE_OAUTH_TOKENfromclaude setup-token.- Anthropic profile and federation credentials (the
antCLI and Workload Identity Federation). A profile fromant auth loginor the keyless Console sign-in ranks here only whenANTHROPIC_PROFILEnames it; otherwise it ranks below/login./statusshows aProfilerow when one is in use. - The subscription login from
/login.
A signed-in Claude apps gateway session sits above this list. The practical consequence: anything exported in your shell outranks your subscription. An approved ANTHROPIC_API_KEY bills the Console even though you pay for Max, and a key from a disabled organization makes every request fail. When a login and a key are both configured, /status marks the one that is not in use.
Rotate keys from a vault with apiKeyHelper
Section titled “Rotate keys from a vault with apiKeyHelper”When keys come from a vault or expire on a schedule, point apiKeyHelper at a script that prints the credential to stdout. Claude Code runs it through /bin/sh (or cmd on Windows) and sends the output as the API key.
{ "apiKeyHelper": "~/.claude/bin/anthropic-key.sh"}Claude Code caches the output and re-runs the script after five minutes (change it with CLAUDE_CODE_API_KEY_HELPER_TTL_MS), after a 401 or 403, and before a request when the cached value is an expired JWT. A helper defined in project settings runs only after you accept the workspace trust prompt. If the script exits non-zero, times out, or prints nothing, requests fail with Your apiKeyHelper script is failing within three attempts.
Where does Claude Code store credentials, and how do you switch accounts?
Section titled “Where does Claude Code store credentials, and how do you switch accounts?”| System | Where the login lives |
|---|---|
| macOS | The encrypted Keychain. If the Keychain is locked (common over SSH), Claude Code falls back to ~/.claude/.credentials.json with mode 0600. |
| Linux | ~/.claude/.credentials.json, mode 0600 |
| Windows | %USERPROFILE%\.claude\.credentials.json, restricted to your user by the profile directory’s permissions |
Setting CLAUDE_CONFIG_DIR moves .credentials.json and the settings files under that directory, and on macOS it keys a separate Keychain entry. That makes it the clean way to keep a personal and a work account side by side:
# ~/.zshrc: a second command that uses its own login and settingsalias claude-work='CLAUDE_CONFIG_DIR="$HOME/.claude-work" claude'Run claude-work once and log in with the work account. To switch the account for a single configuration instead, type /login in a session; /logout signs out and also resets the first-launch setup.
Restrict logins to your organization
Section titled “Restrict logins to your organization”Tech leads who roll Claude Code out to a team should stop developers from logging in with personal accounts. Set both keys in the machine’s managed settings file (managed-settings.json, deployed through MDM):
{ "forceLoginMethod": "claudeai", "forceLoginOrgUUID": "YOUR_ORG_UUID"}YOUR_ORG_UUID is shown in the claude.ai admin settings for your Teams or Enterprise organization. Know the gaps before you rely on it:
- Server-managed settings cannot redirect a first login, because they reach only accounts that already belong to your organization. Deploy these keys through device management, and if you also use server-managed settings, set them in both places.
- The interactive login screen pre-selects the method without enforcing it, and
claude setup-tokenand/install-github-appenforce onlyforceLoginMethod, so they can still mint a token in another organization. - Environment credentials are blocked at startup once
forceLoginOrgUUIDis set:ANTHROPIC_API_KEY,ANTHROPIC_AUTH_TOKEN, andapiKeyHelpercannot prove organization membership. Cloud-provider sessions and Anthropic profile credentials are not blocked, so restrict cloud access with IAM and check profiles with/status. - Console logins are not checked for organization: for a Console login,
forceLoginOrgUUIDonly pre-selects the organization on the sign-in page, and a developer who logged in to the Console before you deployed the keys stays logged in. Because the login screen does not enforceforceLoginMethodeither, control who can bill through the Console by managing membership of your Console organization.
The full rollout, including permissions and telemetry, is on managed policy for coding agents and enterprise integration.
How do you prove the login is correct?
Section titled “How do you prove the login is correct?”Do not ask the model which account it is using: the model sees the conversation, not your credential store. Check the harness instead, and make each check a gate someone owns.
- Developer, once per machine:
claude auth status --textprints aLogin methodline plus the base URL and any proxy;/statusin a session shows the login method, organization, and email, and marks any credential that is configured but unused. - CI, every run: the smoke step above fails the job before real work starts if the secret is missing, expired, or revoked.
- Tech lead, once per rollout: on one managed laptop, log in with a personal account and confirm Claude Code refuses it; then export a test
ANTHROPIC_API_KEYand confirm startup is blocked. - Whoever owns the budget, weekly: compare
/usage(subscriptions) or the Console usage page (API billing) with what you expected; a surprise Console bill from a subscription user is the precedence trap above.
When Claude Code authentication fails
Section titled “When Claude Code authentication fails”The browser does not open, or never returns to the terminal. Press c to copy the URL, sign in anywhere, and paste the code at Paste code here if prompted. This is normal over SSH, in WSL2, and in containers.
Login expired · Please run /login. Run /login. From v2.1.217, Claude Code warns three days before expiry with Your login expires in 3 days · run /login to renew (v2.1.203–v2.1.216 warned five days out). The warning appears only when a claude.ai or Console login is the active credential. Renew before you start background sessions or Remote Control: an unattended session stops making progress once its login expires.
You pay for a subscription but see API charges, or requests fail after a key was revoked. An environment key is outranking your login. Run unset ANTHROPIC_API_KEY, remove it from your shell profile, and confirm with /status.
Your apiKeyHelper script is failing. Run the script by hand with stdout piped to wc -c. It must print only the key, exit 0, and finish in well under 10 seconds; Claude Code shows a slow-helper notice after 10.
Startup exits with an organization policy error. Your admin set forceLoginOrgUUID, which blocks environment keys. Unset them and use /login with your company account.
Cloud credentials expired mid-day. Re-run aws sso login or gcloud auth application-default login. To make it automatic, set awsAuthRefresh for Bedrock or gcpAuthRefresh for Google Cloud’s Agent Platform in your settings.
The model is not available on your provider. Enable it in the Bedrock model catalog or Model Garden, or pin a model your account can invoke; the models hub lists the IDs. For Foundry, first check that ANTHROPIC_FOUNDRY_RESOURCE is your real resource name, not the placeholder.
A macOS Console login fails over SSH. A Console login that creates an API key needs a writable Keychain. Unlock the Keychain, or choose the keyless Console sign-in.
You hit a usage limit on Pro or Max. Run /usage to see which window was reached and when it resets, then reduce parallel sessions or move to a larger plan. Claude Code cost control covers the trade-offs.
Where to go next after logging in to Claude Code
Section titled “Where to go next after logging in to Claude Code”Authentication follows installing Claude Code. Next, set the permission mode, model, and settings hierarchy for your projects. Running Codex too? See Codex authentication.
Did this guide help you?
One tap, no sign-in.
What will you do with it?
How did it read?
What got in the way? Pick any that apply
Your role?
Thanks. I read every answer. Michał Jaskólski
Did this guide help?
One tap each. Close whenever you like.
no sign-in