Claude Code login: sign in, switch accounts, log out
How to log in to Claude Code: first-run sign-in, /login and /logout, claude auth login and status, signing in over SSH, switching accounts, and API keys.
Run claude. On first launch it opens a browser to sign in; choose your Claude subscription (Pro, Max, Ultra, Team or Enterprise), an Anthropic Console account for pay-per-token billing, or a cloud provider. From the shell, claude auth login does the same and claude auth status --text shows who you are signed in as. Inside a session, /login signs in and /logout signs out; to switch accounts, run /logout and then sign in with the other one. On a machine with no browser, press c to copy the sign-in link, open it on your laptop or phone, and paste the code it shows at Paste code here if prompted. An ANTHROPIC_API_KEY in your environment wins over a subscription login once you approve it, and /status shows which one a session is using.
Signing in the first time
claudeCopiedAnthropic’s authentication docs say Claude Code “opens a browser window for you to log in on first launch”. Sign in there, and the terminal shows Login successful and asks you to press Enter. If no browser opens, press c to copy the link and paste it into one yourself. If the browser shows a code instead of sending you back, paste the code into the terminal. Which account to pick:
- A Claude subscription. Your claude.ai account on Pro, Max or Ultra. Claude Code draws on the plan’s usage limits. Every paid plan includes it and the free plan doesn’t; which Claude plans include Claude Code has the prices and limits.
- Team or Enterprise. Sign in with the claude.ai account your admin invited, not a personal one. The organization can require that, and it can also block subscription sign-ins to Claude Code entirely.
- Anthropic Console. API billing per token instead of a plan. Since 2.1.242 the screen asks how: Sign in with your Console account (marked recommended) keeps a login that Claude Code renews and creates no key, and Create an API key (marked legacy) mints a key and stores it. Unset
ANTHROPIC_API_KEYbefore the keyless sign-in, and know that it signs you out of any claude.ai login on the machine. Claude Code on an API key covers billing and caps. - A cloud provider. Amazon Bedrock, Google Cloud’s Agent Platform or Microsoft Foundry: set the provider’s environment variables before starting
claude, or choose 3rd-party platform at the login prompt for a setup wizard (Bedrock and Agent Platform).
The browser sign-in is skipped when you have already run claude auth login, or when ANTHROPIC_API_KEY is set and you approve the key at the prompt. If you haven’t installed Claude Code yet, installing Claude Code covers that first.
The login commands
| Where | Command | What it does |
|---|---|---|
In a session | /login | Signs in, or renews a login that is about to expire |
In a session | /logout | Signs out and resets first-launch setup |
In a session | /status | Shows the account and which credential is in use |
Shell | claude auth login | Signs in without starting a session |
Shell | claude auth logout | Signs out |
Shell | claude auth status | Prints the sign-in state as JSON; exit 0 signed in, 1 not |
Shell | claude setup-token | Prints a one-year token for scripts and CI |
claude auth login takes three flags, per the CLI reference:
claude auth login --email you@example.com # pre-fill the email address
claude auth login --sso # force SSO
claude auth login --console # Console, for API billing instead of a planCopiedclaude auth status prints JSON whose authMethod is one of none, claude.ai, oauth_token, api_key, api_key_helper or third_party, plus a configDirectory field naming the folder it read. Add --text for a version meant for people. Because it exits 1 when nothing is signed in, a script can check it before calling claude -p.
Signing in over SSH, in WSL or in a container
The browser can’t reach a remote machine, so the sign-in ends with a code you carry back by hand. From Anthropic’s troubleshooting page:
- Run
claude(orclaude auth login) on the machine. At the login prompt, presscto copy the link, which also works when it wraps across lines in a narrow SSH terminal;claude auth loginprints it. - Open the link in a browser on your laptop or phone and sign in to the account the machine should use. The browser shows a code instead of returning to
localhost. - Paste the code at the prompt that starts
Paste code here.
If pasting into the full-screen prompt does nothing, try your terminal’s other paste shortcut (right-click or Shift+Insert in Windows Terminal), or use claude auth login, which reads the code from standard input. That doesn't look like the full code means part of it was lost: copy all of it, including the # in the middle. OAuth error: Invalid code means the code expired or was cut off; start again and paste it promptly. On WSL2 you can point Claude Code at your Windows browser for next time:
export BROWSER="/mnt/c/Program Files/Google/Chrome/Application/chrome.exe"
claudeCopiedThat sign-in lasts until it expires and then has to be done again in a terminal. For a job with nobody present, a CI pipeline or a cron script, claude setup-token runs the same sign-in once and prints a one-year token for CLAUDE_CODE_OAUTH_TOKEN. It needs a Pro, Max, Ultra, Team or Enterprise plan and can only make model requests.
Switching accounts, or using two
To move from one account to another, such as from a personal plan to your company’s Team account, sign out and sign in again:
/logout # inside Claude Code, or: claude auth logout
claude # start again and sign in with the other accountCopied/logout resets first-launch setup, so the next claude walks you through sign-in and setup again. It removes more than the Claude login: the troubleshooting page says logging out removes “all stored credentials, including the plaintext file’s contents, saved MCP server logins, and plugin sensitive values”, so expect to re-authorize MCP servers and re-enter plugin secrets.
To stay signed in to both, give each account its own configuration folder with CLAUDE_CONFIG_DIR. Each folder has its own settings, session history and login. The docs’ example, for ~/.bashrc or ~/.zshrc:
alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'CopiedOpen a new terminal and run claude-work; it signs in separately, and claude keeps your personal account. One exception: two Console sign-ins made without an API key aren’t kept apart this way, because Claude Code stores that kind of sign-in outside the configuration folder.
A work organization can decide which account you may use. If an admin requires logins from their organization, Claude Code keeps showing the login prompt until you sign in with an account in it, and refuses others. On Enterprise, the sign-in page can answer Authorization failed with “Claude Code access has not been granted for this account. Contact your administrator.”, which only an Owner can fix by giving you a role that includes Claude Code.
Where the login is stored
| System | Location |
|---|---|
macOS | The macOS Keychain, encrypted |
Linux | ~/.claude/.credentials.json, mode 0600 |
Windows | %USERPROFILE%\.claude\.credentials.json |
On a Mac signed in over SSH, the Keychain can be locked, and Claude Code then writes the login to ~/.claude/.credentials.json instead, as on Linux. To move it back, the troubleshooting page has you run claude doctor, unlock the Keychain if it reports macOS Keychain is not writable, then /logout and /login:
security unlock-keychain ~/Library/Keychains/login.keychain-dbCopiedWith CLAUDE_CONFIG_DIR set, the file lives in that folder instead, and on macOS the Keychain entry is tied to it too. That is why a cron job, a sudo command or a service running as another user can find no login even though you are signed in: “Not logged in” in Claude Code walks through it. The file is your live login, so keep it out of repositories and shared backups; Anthropic’s docs say Claude Code manages it through /login and /logout, so don’t edit it.
Which credential wins
A machine can hold a subscription login and an API key at once. When it does, the authentication precedence decides, in this order, as of November 25, 2026:
- Cloud provider credentials, when
CLAUDE_CODE_USE_BEDROCK,CLAUDE_CODE_USE_VERTEXorCLAUDE_CODE_USE_FOUNDRYis set ANTHROPIC_AUTH_TOKEN, for an LLM gateway or proxyANTHROPIC_API_KEY, a key from the Claude Console- An
apiKeyHelperscript’s output CLAUDE_CODE_OAUTH_TOKEN, fromclaude setup-token- Anthropic profile and federation credentials (a profile written by
ant auth loginranks here only whenANTHROPIC_PROFILEnames it, and otherwise below/login) - “Subscription OAuth credentials from
/login. This is the default for Claude Pro, Max, Ultra, Team, and Enterprise users.”
So a subscription login made with /login comes last. With ANTHROPIC_API_KEY set, an interactive session asks once whether to use it and remembers the answer (change it later with the “Use custom API key” toggle in /config); in claude -p “the key is always used when present.” A forgotten key from an old job or project, still exported in your shell profile, is the usual reason a working subscription fails with an error like:
API Error: 400 ... "This organization has been disabled"CopiedDrop the key and check:
unset ANTHROPIC_API_KEY
claude
# then, in the session:
/statusCopiedRemove the export ANTHROPIC_API_KEY= line from ~/.zshrc, ~/.bashrc or ~/.profile to make it stick (on Windows, check $PROFILE and your user environment variables). When a login and a key are both configured, /status marks the one that isn’t in use. The same order applies to a CLAUDE_CODE_OAUTH_TOKEN exported in your profile: it outranks /login in every new session until you remove it. Cloud sessions on claude.ai are the exception and always use your subscription.
When the login expires
A subscription login doesn’t last forever, and using Claude Code doesn’t extend it. On 2.1.318 or later, claude auth status --text prints a line such as:
Sign-in ends: between 2026-11-20 and 2026-11-23 (2026-11-23T17:04:11.000Z)CopiedSign in again with /login or claude auth login before the earlier date, and at once if it says any day now or may have ended. From that date Claude Code warns at startup with Your login expires in 3 days · run /login to renew, and once it has lapsed, /status shows a Login row reading Expired — log in again.
When signing in fails
Not logged in · Please run /loginwhen you are signed in: the run is looking in another user’s home or another config folder. See the not-logged-in guide, which also coversLogin expired.- “Your organization has disabled Claude subscription access for Claude Code”: the organization you signed in to doesn’t allow Claude Code on a subscription login, and only its admin can change that; the guide to that message has the details.
API Error: 403 Request not allowedright after signing in: on Pro, Max or Ultra, check the subscription is active atclaude.ai/settings; on the Console, your account needs the Claude Code or Developer role; behind a corporate proxy, the proxy may be the cause.- The prompt keeps coming back: the login expired, an admin requires a particular organization or sign-in method, or Claude Code is older than 2.1.290, which showed the prompt during setup whether or not you were signed in.
claude updaterules out the last one. Login successfulbut nothing works: a full disk or a full network home folder can stop the login being saved. Claude Code 2.1.332, the current release as of November 25, 2026, fixedclaude auth loginsayingLogin successful.when a claude.ai login couldn’t be saved, so update and check free space.
When the cause isn’t clear, Anthropic’s reset is to run /logout, close Claude Code, start claude again and sign in from scratch.