claude-code - 💡(How to fix) Fix [BUG] Login succeeds but every request immediately returns "Not logged in" (macOS, OAuth)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Error Messages/Logs

That's the only error the UI shows. If the form lets you add more detail, include these supporting observations underneath it:

  • /login itself reports: "Login successful" (no error) Then send one prompt like hi. It'll print verbose output including the auth/token step and likely the underlying API error (often a 401 with a token-expired or refresh-failure message). Copy whatever it prints around the failure and paste that into the logs field too — but remove anything that looks like a token or key (long strings, sk-ant-..., eyJ...) before pasting, since logs can contain credentials.

Code Example

Not logged in · Please run /login
That's the only error the UI shows. If the form lets you add more detail, include these supporting observations underneath it:
- /login itself reports: "Login successful" (no error)
- Welcome banner shows correct name + org, so auth partially succeeds
- cat ~/.claude/.credentials.json → no file, even immediately after successful login
- security find-generic-password -s "Claude Code-credentials" → entry IS present in login.keychain-db
- env | grep -i anthropic → empty
If you can grab a real debug log, it'll strengthen the report a lot. In a plain terminal (the prompt ending in %, not inside Claude Code), run:
claude --debug
Then send one prompt like hi. It'll print verbose output including the auth/token step and likely the underlying API error (often a 401 with a token-expired or refresh-failure message). Copy whatever it prints around the failure and paste that into the logs field too — but remove anything that looks like a token or key (long strings, sk-ant-..., eyJ...) before pasting, since logs can contain credentials.
If claude --debug doesn't produce anything useful or you'd rather not run it, just the Not logged in · Please run /login line plus the bullet observations above is enough to file. Want me to keep going if there's another field after this one?Opus 4.8 High
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

After running /login, Claude Code reports "Login successful" and the welcome banner shows my correct name and organization. But the very next request — even just typing "hi" — immediately returns "Not logged in · Please run /login". The credential does not survive past the login step.

Some sessions a fresh login works for a few hours and then drops on its own; today it fails immediately after every successful login. Re-logging in does not help.

The credentials file is never written: cat ~/.claude/.credentials.json returns no file even right after a successful login, and no refreshToken is persisted (appears related to #37402). The Keychain entry "Claude Code-credentials" IS present after login, but requests still fail.

Already ruled out: no ANTHROPIC_API_KEY / ANTHROPIC_BASE_URL in env; clean global and project settings.json; Keychain credential deleted and recreated; same failure on two separate networks (home + office WiFi); system clock synced; updated 2.1.156 → 2.1.158 with no change.

What Should Happen?

After a successful login ("Login successful" + correct name/org shown), Claude Code should stay authenticated and process the requests that follow. The OAuth token should persist and auto-refresh in the background, so I should not have to re-login repeatedly — and never see "Not logged in" immediately after a login that just succeeded.

Error Messages/Logs

Not logged in · Please run /login
That's the only error the UI shows. If the form lets you add more detail, include these supporting observations underneath it:
- /login itself reports: "Login successful" (no error)
- Welcome banner shows correct name + org, so auth partially succeeds
- cat ~/.claude/.credentials.json → no file, even immediately after successful login
- security find-generic-password -s "Claude Code-credentials" → entry IS present in login.keychain-db
- env | grep -i anthropic → empty
If you can grab a real debug log, it'll strengthen the report a lot. In a plain terminal (the prompt ending in %, not inside Claude Code), run:
claude --debug
Then send one prompt like hi. It'll print verbose output including the auth/token step and likely the underlying API error (often a 401 with a token-expired or refresh-failure message). Copy whatever it prints around the failure and paste that into the logs field too — but remove anything that looks like a token or key (long strings, sk-ant-..., eyJ...) before pasting, since logs can contain credentials.
If claude --debug doesn't produce anything useful or you'd rather not run it, just the Not logged in · Please run /login line plus the bullet observations above is enough to file. Want me to keep going if there's another field after this one?Opus 4.8 High

Steps to Reproduce

  1. Run claude login in the terminal. The browser OAuth flow completes and Claude Code shows "Login successful" with the welcome banner displaying my correct name and organization.
  2. Send any prompt — even just typing "hi".
  3. The response is immediately "Not logged in · Please run /login", despite the login having just succeeded.

Notes:

  • Reproduces every time today; some earlier days the login held for a few hours before dropping on its own.
  • Re-running /login produces the same result: success, then "Not logged in" on the next request.
  • Reproduces on Claude Code 2.1.156 and 2.1.158, on two separate networks (home + office WiFi).

Already ruled out: no ANTHROPIC_API_KEY/ANTHROPIC_BASE_URL in env; clean global and project settings.json; Keychain credential deleted and recreated; system clock synced; not network-related (fails on two networks). The credentials file ~/.claude/.credentials.json is never written and no refreshToken is persisted — appears related to #37402.

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

2.1.158

Claude Code Version

2.1.158

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] Login succeeds but every request immediately returns "Not logged in" (macOS, OAuth)