Claude Code · Sign-in
Not logged in · Please run /login
Fix “Not logged in · Please run /login” in Claude Code: sign in, check your API key is exported, and stop repeated login prompts on macOS.
Message
The exact error
Not logged in · Please run /loginAlso appears as:
- In the Claude Desktop app (Code tab or Cowork)
- Authentication required · Sign in again to continue
- When the login couldn’t be saved (macOS)
- Couldn't save your login. If your Mac's keychain is locked, unlock it and log in again.
Meaning
What does “Not logged in · Please run /login” mean?
Every request needs either your Claude login or an API key. This message means Claude Code found neither, for example on first run, after logging out, or when you expected an ANTHROPIC_API_KEY that isn’t actually exported in this shell. If you sign in with your claude.ai account in another Claude Code window that uses the same configuration directory, a session showing this message picks up that login on its own; on macOS before v2.1.286 you had to restart it.
Causes
Why does Claude Code keep asking me to log in?
- You haven’t signed in yet, or you logged out
- An
ANTHROPIC_API_KEYset in a different shell or profile than the one you launchedclaudefrom, or an editor that didn’t inherit it - Repeated prompts: a wrong system clock, or on macOS a Keychain that can’t be written
- Over SSH, in WSL or in a container, a browser login whose redirect never reached Claude Code
Fix
How do I fix “Not logged in” in Claude Code?
Sign in
Run
/loginand sign in with your Claude subscription or Console account.If you meant to use an API key, check it’s exported
These print only the first characters, so the key doesn’t end up on screen or in your history. In VS Code, the extension may not have inherited your shell’s environment: start VS Code from a terminal with
code ., or sign in with your Claude account instead. To create a key, see how to get a Claude API key.macOS / Linux echo "${ANTHROPIC_API_KEY:0:7}" # should print sk-ant-Windows PowerShell $env:ANTHROPIC_API_KEY.Substring(0, 7) # should print sk-ant-Reset your login
When the cause isn’t clear, run
/logout, close Claude Code, startclaudeagain and complete the sign-in. If the browser doesn’t open, presscto copy the login URL and paste it into a browser yourself.If it keeps asking you to log in
Make sure your system clock is set automatically, since login tokens depend on correct time. On macOS, run
claude doctor; amacOS Keychain is not writablewarning means you should unlock the login keychain (security unlock-keychain ~/Library/Keychains/login.keychain-db), then/logoutand/login.For CI and automation
Where you can’t log in interactively, use an API key, a long-lived token from
claude setup-token, or anapiKeyHelperscript.
Explained
Why does Claude Code say “Login successful” but still not logged in?
Usually the sign-in worked but Claude Code couldn’t save it to its credential store. Current versions say so with Couldn't save your login. On macOS this happens when the login keychain locks, for example on sleep or idle, during a session: unlock it and run /login again. If the Keychain keeps rejecting writes, claude doctor lists the warning and the recovery steps, and if a saved login expired and the token keeps coming back as expired or revoked, see OAuth token has expired.
Explained
How do I log in over SSH, in WSL or in a container?
The browser opens on a different machine, so its redirect can’t reach Claude Code. After you sign in, the browser shows a code instead: paste it into the terminal at the Paste code here if prompted prompt. Press c to copy the login URL if no browser opens, and in WSL you can set BROWSER to your Windows browser’s path.
If pasting does nothing, try your terminal’s other paste shortcut, often right-click or Shift+Insert in Windows Terminal, or run claude auth login, which reads the code from standard input. OAuth error: Invalid code. Please make sure the full code was copied means the code expired or was cut off: press Enter to retry and paste it straight away.
Explained
Why do I see it with Ollama, a gateway or a background session?
Claude Code only skips the login when it finds a credential in the environment it started from. For a gateway that takes a bearer token that is ANTHROPIC_AUTH_TOKEN; for one that takes an Anthropic-style key, ANTHROPIC_API_KEY, alongside ANTHROPIC_BASE_URL. If those are set in one terminal but claude starts from another, an editor or a background job, it sees nothing. Set them in your shell profile, or in the env block of ~/.claude/settings.json (the settings.json builder writes it), and check with /status.
Background and cloud sessions report the same missing credential as Could not resolve authentication method…. The fix is the same: make sure the credential is set in the environment that starts the worker, not only in your interactive shell. If a credential is found but rejected, see API Error 401 or Invalid API key.
FAQ
Questions people ask
Why does /login say successful but Claude Code still says not logged in?
Usually Claude Code couldn’t save the login to its credential store, which current versions report as “Couldn’t save your login”. On macOS that means the login Keychain locked or rejects writes: run claude doctor, unlock it with security unlock-keychain ~/Library/Keychains/login.keychain-db, then run /logout and /login. Also check that your system clock is set automatically.
How do I log in to Claude Code over SSH or in WSL?
The browser opens on a different machine, so its redirect can’t reach Claude Code. Press c to copy the login URL, open it in your local browser, sign in, then paste the code it shows back into the terminal. If pasting does nothing, try right-click or Shift+Insert in Windows Terminal, or run claude auth login, which reads the code from standard input.
Why do I get “Not logged in” when using Claude Code with Ollama or a local model?
Claude Code only skips the login when it finds a credential in its environment. If ANTHROPIC_BASE_URL and the token or key your gateway expects are set in one shell but claude starts from another, such as an editor or a new terminal, it sees no credential. Set them in your shell profile or the env block of settings.json, then check with /status.
Do I need to restart Claude Code after logging in from another window?
Not on current versions. If you sign in with your claude.ai account in another Claude Code window that uses the same configuration directory, a session showing “Not logged in” starts using that login on its own. On macOS before v2.1.286 the session could keep showing the message, so restart it on those versions.
Related
Related errors
Keep exploring