Claude Code login not working? Here is the fix

Fix Claude Code login problems: browser auth that never completes, API key conflicts, headless and SSH logins, stale credentials, and the order to try things in.

Claude Code login failures almost always come down to one of five causes: a browser handshake that never completes, a stale credential, an environment variable hijacking auth, a headless machine with no browser, or an account/plan mismatch. Work through these in order; the first three fix the vast majority of cases.

First, see what Claude Code thinks is happening

Inside Claude Code, run:

/status

It shows which account you are logged in with and how you are authenticated (subscription or API key). If /status shows an auth method you did not expect, that is your answer: jump to the API key section below.

1. The browser flow never completes

The normal login (/login) opens your browser to authorize, then hands a code back to the terminal. Where it breaks:

  • Nothing opens. Copy the URL Claude Code prints and open it manually in any browser, on any machine. Finish the flow and paste the code back into the terminal.
  • The browser opens with the wrong account. The OAuth page uses whichever claude.ai session your browser holds. Log out of claude.ai (or use a private window), then retry /login and sign in with the right account.
  • Corporate network blocks the callback. Use the copy-the-URL-manually path, and check whether a proxy requires HTTPS_PROXY to be set for the terminal session.

2. Stale or broken credentials

Log out cleanly and back in:

/logout
/login

If that loop still fails, clear the stored credential and retry. On macOS the token lives in the Keychain (search for "Claude"); on Linux it is under your Claude config directory (~/.claude). Remove the credential entry, restart Claude Code, and log in fresh. Deleting credentials is safe; your settings and history are separate.

3. An API key is overriding your login

This is the sneakiest one. If ANTHROPIC_API_KEY is set in your shell, Claude Code can use it instead of your subscription login, which surfaces as "logged in but billed per token", quota errors despite a paid plan, or auth behaving differently between terminals.

echo $ANTHROPIC_API_KEY

If that prints anything and you want to use your subscription, unset it (and remove it from .zshrc, .bashrc, or your dotfiles), restart the terminal, and check /status again. The reverse also holds: if you WANT per-token API billing, that variable being lost is why you are suddenly asked to log in.

4. Headless machines: SSH, servers, CI

A box with no browser cannot run the interactive flow directly. Your options:

  • Copy the URL. Run /login, copy the printed URL to your laptop's browser, finish there, paste the code back over SSH.
  • Port forwarding. ssh -L forwarding of the callback port lets the browser flow complete from your local machine.
  • Use an API key. For CI and automation, set ANTHROPIC_API_KEY instead of an interactive login; that is the supported non-interactive path.
  • Long-lived token. Claude Code can mint a credential for non-interactive use (see claude setup-token); useful for servers you control.

5. Account and plan mismatches

  • Logged in with Google on claude.ai but typing an email password (or vice versa)? Use the same method in the OAuth page.
  • Multiple Claude accounts (work and personal) cause silent confusion: /status shows which one is active, /login lets you switch.
  • If your organization manages your account, login can fail because of workspace policy rather than anything local. Your admin console is the fix, not your terminal.

Still stuck

Check Anthropic's status page before debugging further; auth outages happen and look exactly like local problems. Then run claude doctor, which checks the installation health and surfaces version and connectivity issues, and update to the latest version, since auth fixes ship regularly.

If you are evaluating whether Claude Code is worth the login fight, our Claude Code vs Codex and cost breakdown pages give the bigger picture.

Based on Claude Code's documented auth flows (code.claude.com/docs), checked June 2026.

Share: