ThinkFacility

Error messages

Not logged in · Please run /login

The message

Not logged in · Please run /login
Claude Code 2.1.280 read September 23, 2026Claude Codeauthentication/loginANTHROPIC_API_KEY

What it means

Claude Code tried to send a request and found no credential the API would take. If your key came from an environment variable, you get the Invalid API key line instead.

What to do

Run /login. If it keeps coming back, run /status to see which credential is in use, and on a Mac run claude doctor to check the Keychain.

Claude Code shows this when it's about to talk to the API and has nothing to prove who you are, or what it has was refused:

Not logged in · Please run /login

Running /login is the right first move, and often it's the end of it. This page is for when it isn't. We read the auth code in Claude Code 2.1.280, Anthropic's error reference and troubleshooting pages, and the recent GitHub reports, where 104 issues quote the line as of September 23, 2026.

It used to say Invalid API key

If you searched for Invalid API key · Please run /login, that's the older wording of the same thing, often with API Error: 401 in front. It's in 65 GitHub issues, some from as recently as June. The current binary still carries that line, though only as an example inside one of its prompts. It no longer prints it.

What it prints now depends on where your credential came from. Claude Code checks which source is active, and if that's the ANTHROPIC_API_KEY variable or an apiKeyHelper script you get a different line:

Invalid API key · Fix external API key

A saved /login that's gone bad gets "Not logged in" instead. So the line itself tells you which half of the problem to look at.

If it says Fix external API key

The key is coming from your environment, and /login won't override it while it's there. Anthropic's error reference says to run env | grep ANTHROPIC in the same shell (in PowerShell, Get-ChildItem Env:ANTHROPIC*). Their docs point out that direnv, dotenv shell plugins and IDE terminals can load an old key from a project's .env file without you ever setting it. Either replace the key with a live one from the Console or unset it and log in with your subscription.

The order matters here. When several credentials exist, Claude Code takes cloud provider settings first, then ANTHROPIC_AUTH_TOKEN, then ANTHROPIC_API_KEY, then apiKeyHelper, and only after all of those your subscription login. A forgotten variable wins over a fresh login, unless you declined it when Claude Code asked whether to use it.

When /login says it worked and nothing changes

This is the frustrating version, and the causes we found are about where the login gets saved.

On a Mac, Claude Code keeps your login in the Keychain. If the Keychain refuses the write (it's locked in an SSH session, say, or its password has drifted from your account password), Claude Code falls back to ~/.claude/.credentials.json. Anthropic's fix is to run claude doctor, look for a warning starting macOS Keychain is not writable, unlock it with security unlock-keychain ~/Library/Keychains/login.keychain-db, then /logout and /login. Logging out clears saved MCP logins too, so expect to re-authorize those.

One September 18 report on 2.1.277 had a stranger cause. The user's errors cycled through API Error: 401 OAuth access token has been revoked and Anthropic profile login expired before landing on "Not logged in", and /login kept printing Login successful while saving nothing. Their debug log showed why: ~/.claude/.storage-write.lock existed as a plain file where Claude Code expected a directory. Deleting the stale file fixed it on the next login.

Two more things from Anthropic's troubleshooting page. Token checks depend on timestamps, so if you're asked to log in again and again, make sure your system clock is right. And if you're on something older than 2.1.211, waking a laptop from sleep with several sessions open could make two of them renew the same token at once, which revoked the saved login and logged every session out together.

In scripts and CI

Nobody can click through a browser login in a pipeline. The error reference suggests an apiKeyHelper script that fetches a key at startup, and the authentication page describes a long-lived token from claude setup-token, passed as CLAUDE_CODE_OAUTH_TOKEN. With claude -p, an ANTHROPIC_API_KEY in the environment is always used when it's present, with no prompt to approve it.

If the refusal is about money rather than identity, see “Credit balance is too low”, where a stray API key is one of the two causes Anthropic lists.

Other lines the same feature prints

Match yours against these if the one at the top of the page is not quite it. They come from the same code and mean related things.

  • Invalid API key · Please run /login
  • API Error: 401 Invalid API key · Please run /login
  • Invalid API key · Fix external API key
  • Invalid auth token · Fix external auth token
  • Your organization has disabled API key authentication · Unset ANTHROPIC_API_KEY to use your claude.ai account instead