claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Desktop app: OAuth session_stale_relogin latches and force-logs-out active sessions

Open shehab-bn opened this issue 2 months ago • 17 comments

App: Claude desktop app (macOS), version 1.49585.0 OS: macOS (Darwin 25.6.0)

Summary

Claude Code sessions in the desktop app get force-logged-out because the OAuth token refresh flow fails with invalid_grant, and the subsequent fresh /authorize attempt is rejected by the server with 403 session_stale_relogin ("sessionKey is valid but too old for the requested scope expansion"). This forces a full re-login even though the user had an active, valid login session.

Observed behavior (from ~/Library/Logs/Claude/main.log)

[info] [oauth] CLI requested token refresh after 401
[info] [oauth-v2] refreshing token for orgId=<redacted>
[error] OAuth token refresh failed: status=400, response=<json error=invalid_grant len=72>
[info] [oauth-v2] refresh rejected (auth_error) for orgId=<redacted>; tombstoning and falling through
[info] [oauth-v2] performing fresh /authorize for orgId=<redacted>
[info] oauth failed: authorize returned 403 <json error=permission_error code=session_stale_relogin len=238>
[info] oauth authorize rejected with session_stale_relogin; sessionKey is valid but too old for the requested scope expansion
[warn] [CCD CycleHealth] <session> api_error (success): Failed to authenticate. API Error: 401 OAuth access token has expired. Re-authenticate to continue.

Once this fires, the failure "latches" — every session warm-up attempt short-circuits with the same session_stale_relogin error (short-circuiting fresh /authorize on latched session_stale_relogin) until it clears on its own several minutes later (clearing latched session_stale_relogin failures). In this occurrence it took about 8 minutes (06:00:04 → 06:08:40) and knocked out every active local session in the meantime.

I also found a much larger burst of the same invalid_grant/session_stale_relogin pair (~116 occurrences) in an older rotated log (main4.log, ~2026-08-22), suggesting this is a recurring issue rather than a one-off.

What appears to be happening

The failing /authorize lookup requests a wider OAuth scope set (user:inference user:file_upload user:profile user:sessions:claude_code) than the existing sessionKey was granted under. It looks like an app update started requiring an additional scope, but the client doesn't proactively prompt for a fresh interactive login when this happens — it just keeps retrying silently, fails, and logs the user out with all their active local sessions torn down.

Expected behavior

When the server determines the current sessionKey can't cover a newly-required scope, the client should prompt for a clean re-login immediately (or at least surface a clear "please sign in again" state) instead of latching into repeated silent-refresh failures that tear down active sessions for several minutes.

Local factors ruled out

  • System clock is in sync (~0.13s offset from Apple's time server) — not a clock-skew issue.
  • App was already on the latest available build when this occurred.

shehab-bn avatar Sep 09 '26 06:09 shehab-bn

Before settling on scope expansion alone, there is a second cause worth ruling out: refresh-token rotation replay. When several clients share the same orgId/session (desktop app, CLI, editor extension), they all observe the same token expiry and all attempt refresh around the same minute. Under strict rotation only the first refresh wins; every replay gets invalid_grant. The client then tombstones and falls through to a fresh /authorize - which is where the server's session_stale_relogin (sessionKey too old for the newly requested scope set) turns a token-level problem into a session-level logout. The ~116-occurrence burst on 2026-08-22 and the 06:00 cluster both look like many clients hitting one expiry boundary after an idle period.

Falsifiable check: grep the rotated logs for two or more refresh attempts for the same orgId within roughly 60 seconds immediately before each invalid_grant. If that pattern shows up, the fix is client-side dedupe and backoff so only one client refreshes per expiry, and the others wait for the next 401 instead of racing.

On the latch itself: the client amplifies the server's scope problem. A 403 session_stale_relogin is a distinct, actionable response - it means "this sessionKey cannot be upgraded, re-login required". Short-circuiting every session warm-up with the latched error for 8 minutes is what knocks out active sessions; mapping that code to an immediate interactive sign-in-again prompt (and pausing background refresh until the user acts) would contain the blast radius to one client instead of all local sessions.

Also worth separating the two recovery paths in code: invalid_grant (token-level: rotate and re-auth) versus session_stale_relogin (session-level: never auto-retry, always prompt). Mixing them produces the tombstone-then-latch cascade in your log excerpt.

At corpusiq.io we keep many agent OAuth sessions alive and treat invalid_grant as a rotation-replay canary first: check for concurrent refreshers before tombstoning, because the tombstone path is where otherwise-healthy sessions get destroyed.

Ben-Home avatar Sep 09 '26 12:09 Ben-Home

Same failure on Linux desktop (Arch, app 2.110.0, claude-code 2.1.271) — but the latch did not self-clear. It held for 10.5 hours and only released on a manual /login.

Trigger: system wake after ~8 h suspend, concurrent with a network change.

[LAM] Timeout detector: tick arrived 29581s late — treating as system wake
[oauth] network error on fetch, flushing connection pool and retrying: net::ERR_NETWORK_CHANGED
OAuth token refresh failed (auth_error status=400 detail=<json error=invalid_grant len=85>)
[oauth-v2] refresh rejected (auth_error) for orgId=<redacted>; tombstoning and falling through
[oauth-v2] performing fresh /authorize for orgId=<redacted>
oauth failed: authorize returned 403 <json error=permission_error code=session_stale_relogin len=238>
oauth authorize rejected with session_stale_relogin; sessionKey is valid but too old for the requested scope expansion

The scope expansion in question was user:plugins (3 plugins enabled). Note it was requested as part of a routine wake-up token refresh — a privilege expansion riding along on an ordinary refresh, which turns a recoverable operation into a hard failure.

Duration of the latch — 22 consecutive short-circuits, every 30 min, 10:15 → 20:45:

[oauth-v2] short-circuiting fresh /authorize on latched session_stale_relogin for cacheKey=<redacted>
[oauth] CLI-requested token refresh failed (session_stale_relogin detail=<text len=80>)

Additional impact not covered in the original report — Remote Control dies silently:

10:15:25 [remote-control] bridge_state: "failed" — "Claude.ai login expired — run /login to restore Remote Control"
   ... identical line repeated every 30 min for 10.5 h ...
21:15:25 [remote-control] bridge_state: "connected"

The user was away from the machine. No notification was raised at any point despite agentPushNotifEnabled: true. A remote session that had been running was killed at 10:15 and the machine reported nothing — the failure was only discovered on returning ~11 h later.

Suggested handling: the latch stores a state that only a user action can resolve, so it should surface immediately (notification / in-app banner) rather than being retried silently. Self-clearing after 8 minutes as in the macOS report masks this; on Linux it did not clear at all.

Recovery was additionally blocked by the login callback being dropped — filed separately as #95599.

Chief-Detektor avatar Sep 19 '26 21:09 Chief-Detektor

Same on macOS, and still reproducing on the latest desktop build 2.2553.1 (2026-09-18). Adding 45 days of data in case the timings and the exact scope set help.

Environment

  • Claude Desktop 2.2553.1 (arm64), installed 2026-09-18
  • macOS 26.7 (25G229), Apple M4 Pro
  • Individual account, single org
  • Heavy Code tab / Cowork user, app typically running all day
  • Timestamps below are local machine time, UTC+7

Symptom

The "For your security, sign in again to keep using Claude" banner appears every 1–3 days. Chat itself keeps working the whole time, which matches what the server says: the sessionKey is valid, only the scope expansion is refused.

Log excerpt

~/Library/Logs/Claude/main.log, ids masked:

[oauth] looking up token for orgId=<org-uuid>,
        cacheKey=acct:<acct-uuid>|<device-uuid>:<org-uuid>:https://api.anthropic.com:user:inference user:office
[oauth] using cached token for orgId=<org-uuid>
...
oauth failed: authorize returned 403 <json error=permission_error code=session_stale_relogin len=238>
oauth authorize rejected with session_stale_relogin; sessionKey is valid but too old for the requested scope expansion
[oauth-v2] fresh exchange failed for orgId=<org-uuid> (session_stale_relogin)
[sessions-bridge] Cowork OAuth stale-session (session_stale_relogin); parking bridge until re-login

The scope set being requested on this machine is user:inference user:office.

Recovery happens one of two ways — either a manual re-login, or the latch clearing by itself:

[oauth] clearing latched session_stale_relogin failures
[oauth] sessionKey re-inserted with known-stale value; skipping bridge revive on zombie re-stamp
[sessions-bridge] sessionKey rotated; restarting bridge after session_stale_relogin park

Latch duration is much longer than the ~8 minutes originally reported

Measured from the first authorize rejected to clearing latched session_stale_relogin failures:

Episode Latched for
2026-09-14 07:16:29 → 07:56:28 ~40 min
2026-09-17 16:47:17 → 20:30:12 ~3 h 43 min
2026-09-18 04:13:17 → 08:58:05 ~4 h 45 min
2026-09-18 13:43:34 → 14:58:12 ~1 h 15 min

In several of these episodes the latch cleared without an accompanying sessionKey rotated line, i.e. it self-recovered rather than being fixed by a re-login. So the failure is neither reliably self-healing nor reliably fatal, which makes the banner look arbitrary from the user's side.

Timeline — first authorize rejected of each episode

2026-08-04 13:18:28      2026-08-28 22:35:50
2026-08-06 08:46:42      2026-08-29 10:25:41
2026-08-12 05:57:25      2026-08-31 22:53:38
2026-08-13 16:37:39      2026-09-02 01:52:20
2026-08-14 08:22:35      2026-09-02 16:23:26
2026-08-18 19:20:03      2026-09-11 09:35:49
2026-08-21 16:22:30      2026-09-11 10:46:05
2026-08-24 13:11:13      2026-09-14 07:16:29
2026-08-26 21:02:17      2026-09-16 23:58:25
                         2026-09-17 14:17:55
                         2026-09-17 16:47:17
                         2026-09-18 04:13:17
                         2026-09-18 13:43:34

22 episodes in 45 days. Typical spacing is 24–72 h, consistent with the intervals reported in #81512 and #87950. (No events recorded 2026-09-03 … 2026-09-10; the machine saw little use in that window.)

Additional observations

  1. The recent auth fixes do not cover this path. 2.2553.0 (2026-09-17) fixed background renewal of an expired OAuth token, and 2.110.0 (2026-09-15) fixed re-login prompts after a single network error during renewal. This is a third path — the /authorize scope-expansion rejection — and it is still failing on 2.2553.1.
  2. sessionKey re-inserted with known-stale value; skipping bridge revive on zombie re-stamp suggests the client re-stamps a value it already knows the server rejected, instead of escalating to an interactive login.
  3. Each forced re-login creates a new account session. After months of this, the account's Active sessions list has grown into the hundreds. That list is now effectively unusable for spotting a genuinely suspicious session, which is a security-usability regression in its own right.
  4. One re-login attempt failed at the login redirect itself, on a machine behind a VPN whose route can switch mid-request:
    Failed to load URL: https://claude.ai/login?returnTo=%2F...%3Freason%3Delevated_auth
      %26auth_kind%3Dsession_stale_relogin%26org_uuid%3D<org-uuid>&reauth=1&from=logout
      { errorCode: -21, errorDescription: 'ERR_NETWORK_CHANGED' }
    
    Worth handling with a retry, since the forced logout has already torn down the session by that point.

Ask

  • Satisfy the elevated scope requirement with a scoped step-up rather than a full account re-login, or extend the session freshness window for a device that has already been trusted.
  • If a re-login genuinely is required, prompt immediately instead of latching and silently retrying for hours.
  • Don't mint a brand-new account session for what is effectively a scope refresh of an existing trusted device.

Happy to provide fuller logs or run a build with extra auth tracing.

Alex-AXO avatar Sep 20 '26 09:09 Alex-AXO

Same on macOS, still reproducing on 2.2553.1 (macOS 26.6.2, M3 Max, laptop that sleeps/wakes through the day, Google SSO login). Forced re-login on Aug 25, Sep 5, 8, 12, 16, 18, 20 — now every ~2 days. Adding this because 7 weeks of main*.log point at a specific trigger: a refresh request interrupted by a network change, followed by invalid_grant on the next attempt — i.e. it looks like a lost-response race on refresh-token rotation.

The pattern

In 8 of the 10 distinct incidents, the refresh attempt immediately before the first invalid_grant died with a network error (almost always on wake from sleep):

Refresh hit network error Next refresh → invalid_grant
Aug 07 22:56:12 ERR_NETWORK_CHANGED Aug 07 22:57:50
Aug 19 10:25:44 ERR_NETWORK_CHANGED Aug 19 13:43:45
Aug 25 19:23:02 ERR_NETWORK_CHANGED Aug 25 19:46:40
Sep 07 00:35:33 ERR_NAME_NOT_RESOLVED Sep 07 08:08:14
Sep 12 07:08:39 ERR_NETWORK_CHANGED Sep 12 07:26:30
Sep 16 04:13:33 ERR_NETWORK_CHANGED (in-request retry) Sep 16 04:13:34
Sep 18 00:32:48 ERR_NETWORK_CHANGED Sep 18 08:24:49
Sep 19 09:08:52 ERR_NETWORK_CHANGED Sep 19 09:14:18

Representative chain (ids redacted):

09-19 09:08:52 [info]  [oauth-v2] refreshing token for orgId=<redacted>
09-19 09:08:52 [warn]  [oauth] network error on fetch, flushing connection pool and retrying: net::ERR_NETWORK_CHANGED
09-19 09:08:52 [error] OAuth token refresh failed (network_error detail=net::ERR_NETWORK_CHANGED)
09-19 09:08:52 [info]  [oauth-v2] transient refresh failure (network_error) for orgId=<redacted>; entry left for retry
09-19 09:14:17 [info]  [oauth-v2] refreshing token for orgId=<redacted>
09-19 09:14:18 [error] OAuth token refresh failed (auth_error status=400 detail=<json error=invalid_grant len=85>)
09-19 09:14:18 [info]  [oauth-v2] refresh rejected (auth_error); tombstoning and falling through
09-19 09:14:18 [info]  [oauth-v2] performing fresh /authorize for orgId=<redacted>
09-19 09:14:18 [info]  oauth failed: authorize returned 403 <json error=permission_error code=session_stale_relogin len=238>
09-19 09:14:18 [info]  oauth authorize rejected with session_stale_relogin; sessionKey is valid but too old for the requested scope expansion

Older builds logged the body unredacted: {"error": "invalid_grant", "error_description": "Refresh token not found or invalid"}.

Hypothesis

The "transient" refresh request actually reaches the server, which rotates the refresh token and invalidates the old one; the response is lost to the network change. The client correctly treats it as transient and keeps the old token ("preserving chain" / "entry left for retry") — but that token is now dead server-side, so the retry gets invalid_grant. The fallback /authorize with the session cookie is then refused as session_stale_relogin, so a single dropped HTTP response ends in a full browser re-login.

A sleeping laptop makes this nearly inevitable: this machine logged ~1,500 ERR_NETWORK_CHANGED in 10 days (dark-wake network re-attach), and the renewal timer tends to fire exactly at wake. (2 of the 10 incidents had no visible network error beforehand, so there may be a second trigger as well.)

Suggested fixes

  • Server: grace window / idempotent reuse for the just-rotated refresh token (accept the previous token for a short period, or return the same new pair on replay), which is standard practice for rotating refresh tokens.
  • Server or client: when the refresh chain is lost but the sessionKey is still valid, allow /authorize to re-mint the same scopes without the freshness requirement — it's not really a "scope expansion".
  • Client: defer the post-wake renewal until the network has been stable for a few seconds rather than firing on the wake tick.

Happy to provide full logs privately if useful.

sombandy avatar Sep 20 '26 14:09 sombandy

Same bug here (macOS, desktop 2.2553.13, Darwin 27.0.0). Adding a correlation that may help: in my case every invalid_grant → session_stale_relogin coincides with Remote Control (remote-tools-device / bridge) activity, and refreshes happen under two different oauth-v2 cache keys for the same account/org — which looks like two refreshers racing on a single-use refresh token.

Frequency: 1–2 forced re-logins/day since 2026-09-14.

# 1 — mobile Remote Control polling the device
[info] [remote-tools-device] served get_device_info
[info] [oauth-v2] refreshing token for orgId=<redacted>
[error] OAuth token refresh failed: status=400, response=<json error=invalid_grant len=72>

# 2 — remote-tools-device credential rotation, then a refresh under a *different* cache key 2.5 min later
[info] [remote-tools-device] rotation due — re-presenting credential in-band
[info] [remote-tools-device] credential re-verified in-band
[info] [oauth-v2] lookup orgId=<redacted> cacheKey=acct:<A>|<client-2>:...
[info] [oauth-v2] refreshing token for orgId=<redacted>
[info] handoff: publishing session_<redacted>
[error] OAuth token refresh failed (auth_error status=400 detail=<json error=invalid_grant len=72>)

# 3 — wake from sleep, bridge reconnect
[info] [sessions-bridge] System resumed; waking poll loop
[info] [remote-tools-device] connecting wss://bridge.claudeusercontent.com
[error] OAuth token refresh failed (auth_error status=400 detail=<json error=invalid_grant len=72>)

# 4 — bridge pong timeout + network change mid-refresh
[info] [remote-tools-device] pong timeout (1 consecutive) — resetting
[info] [oauth-v2] refreshing token for orgId=<redacted>
[warn] [oauth] network error on fetch, flushing connection pool and retrying: net::ERR_NETWORK_CHANGED
[error] OAuth token refresh failed (auth_error status=400 detail=<json error=invalid_grant len=85>)
[info] oauth failed: authorize returned 403 <json error=permission_error code=session_stale_relogin len=238>

Hypothesis (unconfirmed): #4 especially looks like the refresh request reached the server (token rotated), the response was lost to ERR_NETWORK_CHANGED, and the retry replayed the now-consumed refresh token → reuse detection → whole session revoked.

Impact: this makes Remote Control unusable for its main purpose. When I'm away from my home machines; once they're force-logged-out there's no way to recover remotely, and every persistent agent on them stops.

Newport1 avatar Sep 22 '26 20:09 Newport1

Same issue here on macOS 26.6.2, forced to sign in again twice in three days, each time at app launch.

  • 2026-10-04 04:15 UTC, app 2.19675.0, Claude Code 2.1.286. Same app version as the previous launch the day before, so no update was involved.
  • 2026-10-06 13:57 UTC, app 2.19675.1 (first launch after updating from 2.19675.0), Claude Code 2.1.288.

Both times main.log shows the same sequence within about 2 seconds of launch:

OAuth token refresh failed (auth_error status=400 detail=) oauth authorize rejected with session_stale_relogin; sessionKey is valid but too old for the requested scope expansion [sessions-bridge] Cowork OAuth stale-session (session_stale_relogin); parking bridge until re-login

Signing in again clears it straight away ("sessionKey rotated; restarting bridge"). My older logs back to 2026-09-08 show no failures before 2026-10-04, so this started recently for me. I also checked that nothing else on the machine touches the desktop app's credentials.

webxsite avatar Oct 06 '26 14:10 webxsite

Another Linux data point that supports the lost-response race on refresh-token rotation theory from @sombandy, plus a second variant (two concurrent refreshers) and a note on keyless Linux devices.

Environment

App Claude Desktop 2.9939.4, official .deb
OS Kubuntu, KDE Plasma, kernel 7.0
Secret store KWallet 6 (kwalletd pre-flight (kwalletd6): has-wallet), no safeStorage warnings
Clock NTP-synced, RTC in UTC
Device Laptop that suspends daily and moves between office / home / VPN
Device key keyless, although the machine has a TPM 2.0 (/dev/tpmrm0)

Frequency

Forced re-login on 2026-08-31, 09-02 (twice), 09-10, 10-02, 10-04, 10-06, and again on 10-07 (chat tab sent to /login, nothing logged in main.log, same as @ampali2011 in #89812).

Variant 1: refresh fired during the resume-time network flap (08-31, 09-10, 10-04)

Every time, it happens within seconds of OS resume, while DNS is still down:

2026-09-10 08:19:43 [info] [event-loop-stall] OS resume
2026-09-10 08:19:43 [error] [sessions-bridge] Poll error, backing off: net::ERR_NAME_NOT_RESOLVED
2026-09-10 08:19:49 [warn] [oauth] network error on fetch, flushing connection pool and retrying: net::ERR_NETWORK_CHANGED
2026-09-10 08:19:49 [error] OAuth token refresh failed: status=400, response={"error": "invalid_grant", "error_description": "Refresh token not found or invalid"}
2026-09-10 08:19:49 [info] [oauth-v2] refresh rejected (auth_error) for orgId=<org>; tombstoning and falling through
2026-09-10 08:19:50 [info] oauth authorize rejected with session_stale_relogin; sessionKey is valid but too old for the requested scope expansion

network error ... retrying and invalid_grant: Refresh token not found or invalid are in the same second. It looks like the first POST reached the server and rotated the token, the response was lost to ERR_NETWORK_CHANGED, and the automatic retry replayed the consumed refresh token. 08-31 and 10-04 show the same sequence.

Variant 2: two refreshers racing (10-06)

2026-10-06 08:16:33 [warn] [oauth] network error on fetch, flushing connection pool and retrying: net::ERR_NETWORK_CHANGED
2026-10-06 08:16:57 [warn] [oauth] CLI-requested token refresh failed oauth store read timed out
2026-10-06 08:17:03 [error] OAuth token refresh failed (network_error detail=<text len=40>)
2026-10-06 08:17:03 [info] [oauth-v2] transient refresh failure (network_error) for orgId=<org>; entry left for retry
2026-10-06 08:17:04 [error] OAuth token refresh failed (auth_error status=400 detail=<json error=invalid_grant len=85>)
2026-10-06 08:17:04 [info] [oauth-v2] refresh rejected (auth_error) for orgId=<org>; tombstoning and falling through
2026-10-06 08:17:04 [info] oauth failed: authorize returned 403 <json error=permission_error code=session_stale_relogin len=238>

One refresh fails with a network error ("entry left for retry"), and one second later another refresh uses the same refresh token and gets invalid_grant. The single-use token is not protected by a single-flight lock across the CLI-requested path and the main path.

Variant 3: Refresh token expired (09-02)

2026-09-02 10:50:31 [error] OAuth token refresh failed: status=400, response={"error": "invalid_grant", "error_description": "Refresh token expired"}

Suggested fixes

  1. Make refresh idempotent on the client. Use a single-flight lock per cache key across all callers (CLI-requested, bridge, remote-tools-device). Never replay a refresh token after a network error whose outcome is unknown. Re-read the store first, or let the server accept the previous token for a short grace window. OAuth 2.0 Security BCP §4.14 describes this kind of reuse tolerance for rotated refresh tokens.
  2. Defer token work after powerMonitor resume until net.isOnline() and a successful DNS lookup of api.anthropic.com.
  3. Treat invalid_grant that follows a network error as transient. Retry the /authorize fallback silently first instead of latching session_stale_relogin and showing the sign-in screen.
  4. Support TPM 2.0 on Linux for the device key. The machine has /dev/tpmrm0, but claude-native-binding.node has no TPM code path, so every Linux desktop is keyless and gets the shorter freshness window discussed in #89812. Allowing that would put Linux at parity with macOS (Secure Enclave) and Windows.
  5. Offer a passkey or phone-approval step-up (like GitHub Mobile or Google prompts) instead of an email magic link when re-authentication is truly needed.

Local workaround (for others)

A systemd-sleep hook that freezes the app's cgroup (app-com.anthropic.Claude-*.scope) on pre and thaws it on post only after nm-online reports the network is up and api.anthropic.com resolves. The refresh then never runs during the network flap. Happy to share it if useful.

mrm-david avatar Oct 07 '26 12:10 mrm-david

Same failure on Windows (Claude Desktop 2.31226.1, MSIX, Windows 11 Pro 10.0.26200, bundled Claude Code 2.1.295, Google sign-in). In my case the invalid_grant came right after the app was quit and restarted a few minutes after a successful token rotation, which may help narrow down the cause.

Timeline (JST, from %LOCALAPPDATA%\Claude\Logs\main.log):

2026-10-15 22:11:27 [info] [oauth] handed rotated Code-tab token to 20 running session(s)
2026-10-15 22:17:09 [info] beforeQuit: handler fired, going down
2026-10-15 22:20:45 [info] Starting app
2026-10-15 22:20:45 [info] [quit-cleanup] previous quit: { completed: true, timed_out: false, for_update: false, ... }
2026-10-15 22:20:48 [info] [oauth] loaded token cache from disk with 3 entries
2026-10-16 06:06:26 [error] OAuth token refresh failed (auth_error status=400 detail=<json error=invalid_grant len=72>)
2026-10-16 06:06:27 [info] oauth authorize rejected with session_stale_relogin; sessionKey is valid but too old for the requested scope expansion
2026-10-16 06:06:27 [warn] [oauth] Code-tab token renewal (timer) failed: session_stale_relogin
2026-10-16 06:07:43 [info] [Auth] Using system browser for: /login/app-google-auth

Restarts that happened hours after a rotation in the same week did not cause a failure:

Rotation Restart Next renewal
10/11 13:47 10/11 20:08 (+6h21m) 10/11 21:42 succeeded
10/14 06:09 10/14 09:40 (+3h31m) 10/14 14:04 succeeded
10/15 22:11 10/15 22:20 (+6 min after quit at 22:17) 10/16 06:06 invalid_grant

This is one occurrence, so it is a hypothesis: the refresh token rotated at 22:11 may not have been persisted to the token cache (%APPDATA%\Claude\config.json) before quit, so the app loaded an already-rotated refresh token on startup and the next renewal was rejected. Once that happens, the fallback /authorize hits session_stale_relogin and a full sign-in is required.

ethfumi avatar Oct 16 '26 00:10 ethfumi

Confirming the same invalid_grant → session_stale_relogin → latched failure chain on macOS during regular use, with a successful Code-tab token rotation earlier the same day.

Environment

  • Claude Desktop: 2.42304.2 (installed app version at investigation time)
  • Bundled Claude Code: 2.1.299 (observed in the running process paths)
  • macOS 27.0, arm64
  • Local Code sessions and Remote Control in use
  • All timestamps below are JST (UTC+09:00), October 20, 2026

What happened

I use Claude Code almost every day. At 11:03, Desktop successfully rotated the Code-tab token and distributed it to five running sessions. At 18:58, the next scheduled renewal failed with invalid_grant. The fallback /authorize immediately returned 403 session_stale_relogin. Remote Control then entered auth_stale, and a local Code session ended with an expired-token error at 19:03.

The Desktop process was still running when inspected, with an uptime of approximately 30 hours. This failure therefore occurred during an existing app run, rather than immediately after launching Desktop.

Redacted logs

Selected lines from main.log (omitted lines are not shown; identifiers replaced with placeholders):

2026-10-20 11:03:35 [info] [oauth-v2] renewing token ahead of expiry for orgId=<redacted>
2026-10-20 11:03:36 [info] [oauth] handed rotated Code-tab token to 5 running session(s) (fenced 0, CLI too old 0)

2026-10-20 18:58:35 [info] [oauth-v2] renewing token ahead of expiry for orgId=<redacted>
2026-10-20 18:58:36 [error] OAuth token refresh failed (auth_error status=400 detail=<json error=invalid_grant len=72>)
2026-10-20 18:58:36 [info] [oauth-v2] refresh rejected (auth_error) for orgId=<redacted>; tombstoning and falling through
2026-10-20 18:58:36 [info] [oauth-v2] performing fresh /authorize for orgId=<redacted>
2026-10-20 18:58:36 [info] oauth failed: authorize returned 403 <json error=permission_error code=session_stale_relogin len=238>
2026-10-20 18:58:36 [info] oauth authorize rejected with session_stale_relogin; sessionKey is valid but too old for the requested scope expansion
2026-10-20 18:58:36 [info] [oauth-v2] fresh exchange failed for orgId=<redacted> (session_stale_relogin)
2026-10-20 18:58:36 [warn] [oauth] Code-tab token renewal (timer) failed: session_stale_relogin

2026-10-20 19:03:51 [warn] [oauth] CLI-requested token refresh failed (session_stale_relogin detail=<text len=80>)
2026-10-20 19:03:51 [warn] [CCD CycleHealth] <session> api_error (success): Failed to authenticate. API Error: 401 OAuth access token has expired. Re-authenticate to continue.

At 19:03:51, main.log also records short-circuiting fresh /authorize on latched session_stale_relogin for the same Code scope set.

Corresponding lines from remote-control.log:

2026-10-20 18:59:17.596 [info] auth stale (epoch 1); notifying
2026-10-20 18:59:17.629 [info] watch: connected → off
2026-10-20 18:59:17.630 [info] state serving → auth_stale (no_auth) trigger=tick intent=on served=6 registering=0 failed=0 excluded=0 limited=2 missing=0 sessions=3
2026-10-20 19:03:51.631 [info] session ended (close code=1 → crash, unarchive queued) session=<remote-session> local=<local-session>

Details that may help distinguish the trigger

  • The OAuth lookup scope set was identical at the successful 11:03 renewal and the failed 18:58 renewal: user:inference user:file_upload user:profile user:sessions:claude_code. The “scope expansion” message alone does not establish that an app update introduced a new scope in this incident.
  • I found no OAuth network-error or transient-refresh-failure entries in that day's main.log. This does not rule out a network issue, but I cannot confirm the lost-response scenario reported above.
  • Remote-device activity (served get_device_info and credential re-verified in-band) occurred at 18:57. This is only temporal context, not evidence of a refresh race.
  • The recent updater entries show an update check at 18:48, but no update installation/restart around the failure.
  • The reason the initial refresh grant was rejected is still unknown. The logged response omits the detailed error description, so expiry, invalidation, and refresh-token races cannot be distinguished from this excerpt.

Could the team clarify what freshness condition /authorize is applying here, and why recovery for an already-used Code scope set requires a fresh interactive login? This interrupted ongoing Code work and disabled Remote Control despite regular use and a successful automatic renewal earlier that day.

Kirisamememe avatar Oct 20 '26 10:10 Kirisamememe

Another macOS data point, with the device-registry side effect that #81164 described before it was auto-closed.

Setup: Claude Desktop 3.1623.1 on macOS 27.2 (26B118), Apple Silicon, Google SSO, Team plan. Claude Code CLI 2.1.307 and the VS Code extension are also signed in on the same machine. Clock offset against time.apple.com is under 2 ms.

Frequency (from main.log/main1.log, 8 to 22 October):

Day session_stale_relogin rejections forced system-browser logins
8 Oct 9 0
9 Oct 10 0
10 Oct 4 0
12 Oct 10 1
13 Oct 5 1
22 Oct 0 2 (04:37 and 07:41 local)

Today's sequence. The app had signed in at 04:37. At 07:41 it was relaunched and, with no user action, navigated itself to /logout and went straight to Google sign-in:

07:41:01 [info] [updater] App is installed, enabling initial check and auto-updates
07:41:02 [info] [account] Navigated to /logout, synthesizing logged-out
07:41:02 [info] [account] Login-state transition (loggedOut: false → true, uuid: <uuid> → <none>), clearing oauth cache
07:41:02 [info] [oauth] identity changed during load; discarding
07:41:02 [error] Failed to check allowlist status: Error: Organization API returned status 403
07:41:05 [info] [Auth] Using system browser for: /login/app-google-auth
07:41:17 [info] [account] Login-state transition (loggedOut: true → false, ...), preserving oauth cache (same-user re-login)
07:41:17 [info] [oauth-v2] performing fresh /authorize for orgId=<uuid>

Earlier rejections carry the same text others have quoted:

oauth failed: authorize returned 403 <json error=permission_error code=session_stale_relogin len=238>
oauth authorize rejected with session_stale_relogin; sessionKey is valid but too old for the requested scope expansion
[oauth-v2] fresh exchange failed for orgId=<uuid> (session_stale_relogin)
[sessions-bridge] sessionKey rotated; restarting bridge after session_stale_relogin park

Device-registry side effect. ~/Library/Application Support/Claude/ant-device-registry.json was recreated at 07:41:36, 19 seconds after the re-login (file birth time, not just mtime). Each forced sign-in therefore registers the Mac as a new trusted device and a new active session; Settings > Account now lists several identical entries for this one machine. That is the symptom #81164 reported, so it looks like the same root cause rather than a separate Claude Code CLI bug.

The scope sets requested on the failed /authorize calls were user:inference user:file_upload user:profile user:sessions:claude_code and user:inference user:profile user:sessions:claude_code, which matches the "scope expansion" wording but, as others noted, the same sets succeed on other days.

Assisted-by: Claude Code:claude-fable-5-1

benrfairless avatar Oct 22 '26 00:10 benrfairless

Same issue on macOS, adding a data point that may not fit the lost-response theory.

Environment

  • Claude Desktop 3.6556.1 (arm64), bundled Claude Code 2.1.308
  • macOS 26.3, Apple Silicon, Google SSO, individual account
  • Laptop that sleeps/wakes many times a day; Code tab + Remote Control in use

Frequency: forced re-login on Oct 16, Oct 19, Oct 22, every ~3 days. The web sessionKey cookie is issued for 28 days, so the cookie isn't what's expiring.

Same chain every time (~/Library/Logs/Claude/main.log):

[oauth-v2] refreshing token for orgId=<redacted>
OAuth token refresh failed (auth_error status=400 detail=<json error=invalid_grant len=72>)
[oauth-v2] refresh rejected (auth_error) for orgId=<redacted>; tombstoning and falling through
[oauth-v2] performing fresh /authorize for orgId=<redacted>
oauth failed: authorize returned 403 <json error=permission_error code=session_stale_relogin len=238>
oauth authorize rejected with session_stale_relogin; sessionKey is valid but too old for the requested scope expansion

Triggers

  1. Oct 16 22:33. First refresh after waking from ~15 min of sleep (main process blocked for 928884ms [likely sleep: power_event]). The network was down just before (ERR_NAME_NOT_RESOLVED), and earlier that evening there were several Code-tab token renewal (timer) failed: network_error. This one matches the interrupted-refresh theory. The failure stayed latched until I signed in manually on Oct 19.
  2. Oct 22 14:56. This one doesn't seem to fit. After the Oct 19 09:57 re-login, main.log has no other [oauth-v2] refreshing token line until Oct 22 14:56:21. That attempt came 12 s after an auto-update restart (beforeQuitForUpdate handler fired) and got invalid_grant straight away. So the refresh token was rejected on what looks like its first logged use, about 3 days after it was minted. The machine went through many sleep/wake and offline cycles in between, but I found no logged refresh attempt during them.

If the second case is real, it suggests something besides a lost rotation response: a ~3-day refresh-token lifetime, the token being invalidated elsewhere, or a refresh that doesn't get logged. Happy to provide more log excerpts if useful.

lampten avatar Oct 22 '26 19:10 lampten

Still reproducing on Claude Desktop 3.6556.2 (macOS, Darwin 27.0.0, Apple Silicon), individual account, single org, Google SSO.

Same sequence as the original report, ids redacted (~/Library/Logs/Claude/main.log, 2026-10-24, local time UTC+2):

[sessions-bridge] Forcing session_ingress_token refresh for cse_<redacted> (trigger=proactive_timer)
[oauth-v2] refreshing token for orgId=<redacted>
[error] OAuth token refresh failed (auth_error status=400 detail=<json error=invalid_grant len=72>)
[oauth-v2] refresh rejected (auth_error) for orgId=<redacted>; tombstoning and falling through
[oauth-v2] performing fresh /authorize for orgId=<redacted>
oauth failed: authorize returned 403 <json error=permission_error code=session_stale_relogin len=238>
oauth authorize rejected with session_stale_relogin; sessionKey is valid but too old for the requested scope expansion

invalid_grant → session_stale_relogin episodes (first rejection of each):

Date Trigger
2026-09-20 02:24 CLI-requested token refresh
2026-09-23 10:27 Cowork sessions-bridge
2026-09-30 03:22 Code-tab token renewal (timer)
2026-10-06 06:51 at app launch
2026-10-24 21:28 sessions-bridge proactive_timer
2026-10-27 13:55 at app launch (latched since 10-24)

Things ruled out on this machine:

  • No user-initiated logout: browser history has no claude.ai logout visits, only the forced re-logins.
  • Cookie jar intact: on 2026-10-27 startup logged sign_in_cookie_present: true, signed_in_at_last_exit: true, previous_quit_clean: true, update_relaunch_marker: 'none'.
  • Fires at random times, including ~03:00 with the machine idle, so not tied to user activity.

Each episode needs a full interactive Google sign-in to recover.

natekettles avatar Oct 27 '26 12:10 natekettles

A Windows data point for the "falsifiable check" proposed earlier in this thread (two or more refreshes within ~60 s before each invalid_grant). Setup: Claude Desktop (MSIX), Windows 11 Pro 10.0.26200, Max plan, email sign-in.

Short version: in my logs, no other refresh ever came before the failing one. Each time, it was the first refresh since the previous successful refresh or sign-in.

Every [oauth-v2] refreshing token line in my main1.log + main.log (Sep 1 – Nov 2). Times are local: UTC+2 until Oct 25, UTC+1 after.

Refresh App version Result Previous refresh or sign-in
9 calls, Sep 16 – Sep 28 2.110.0 → 2.9939.2 all OK n/a
Sep 29 23:44:08 2.9939.4 invalid_grant, then session_stale_relogin refresh OK Sep 28 17:26:01 (30 h earlier)
Oct 3 11:40:18, retry 11:40:22 2.16120.0 invalid_grant, then session_stale_relogin sign-in Sep 29 23:46 (3.5 days earlier)
Oct 31 17:42:39 4.29.0 invalid_grant, then session_stale_relogin sign-in Oct 3 11:40 (28 days earlier)
Nov 2 18:11:45, retry 18:11:48 4.4212.0 invalid_grant, then session_stale_relogin sign-in + fresh /authorize Oct 31 17:46:52 (2 days earlier)

What the logs show:

  • No second refresh within 60 s before any invalid_grant. The only extra calls are the app's own retry, 3–4 s after the first failure.
  • No other renewal in between. The only refreshing token lines are the ones in the table, and there are no Code-tab token renewal lines anywhere in these logs. There was one network drop (Oct 31 17:58–18:00, ERR_INTERNET_DISCONNECTED), but no refresh was attempted during it.
  • So the refresh token was rejected on its first use, whether that came 30 hours, 2 days or 28 days after it was issued. That doesn't fit rotation replay or a lost response. It looks like the server had already invalidated the token by the time the app first used it. Caveat: this is only the desktop app's own log. I also run Claude Code in VS Code on this machine, but that uses its own login in ~/.claude/.credentials.json.
  • When it started for me: all 9 refreshes up to 2.9939.2 succeeded, and every call from 2.9939.4 on failed. So the change happened between Sep 28 17:26 and Sep 29 23:44. However, #95963 shows macOS failing on 2.2553.1, a version where my refreshes still worked. So this may be a server-side or staged change rather than a client regression.

Ignavum avatar Nov 02 '26 17:11 Ignavum

Same on macOS, adding a data point that does not look like a refresh-token race.

Environment: Claude Desktop 4.23118.1 (macOS, Apple Silicon), bundled Claude Code 2.1.321, personal Max plan, single org, Google sign-in. The machine is mostly driven remotely via Remote Control, so each forced re-login is an outage until someone is physically at the Mac.

Timeline from ~/Library/Logs/Claude/main.log (local time, UTC+9):

2026-11-06 20:16:41 [oauth-v2] performing fresh /authorize ...
2026-11-06 20:16:41 oauth: /authorize not sent: the server says this sign-in is too old (session_stale_relogin), so the person must sign in again
2026-11-10 09:45:06 [oauth] restored the stored session_stale_relogin failures: the sessionKey is unchanged, so the person must sign in again
        ... Code tab keeps working normally for ~4.6 days, no UI hint anywhere ...
2026-11-11 11:20:39 [oauth-v2] renewing token ahead of expiry ...
2026-11-11 11:20:39 [error] OAuth token refresh failed (auth_error status=400 detail=<json error=invalid_grant len=72>)
2026-11-11 11:20:39 [oauth-v2] refresh rejected (auth_error) ...; tombstoning and falling through
2026-11-11 11:20:39 oauth: /authorize not sent: ... too old (session_stale_relogin)
2026-11-11 11:20:39 [warn] [oauth] Code-tab token renewal (timer) failed: session_stale_relogin

What stands out:

  1. One renewal, rejected on the first try. Between 11-02 (oldest log I have) and 11-11 11:20 the app only ever used the cached token. 11:20:39 is the only refresh attempt in that window, and it got invalid_grant immediately. Neither main.log nor remote-control.log shows any other refresh around that second, so here it doesn't look like two clients racing on a rotated refresh token.
  2. The breakage interval is almost exactly 30 days. The previous forced re-login (401 "OAuth access token has expired" in Code tab sessions) was 2026-10-12 10:45 local; this one is 2026-11-11 11:20 local, 30 days + 35 min later. Before that there was a revoke on 10-06. It behaves like a fixed ~30-day lifetime that the background renewal can't extend, not like a rolling session that stays alive while in use.
  3. The app knew 4.6 days in advance and said nothing. The stale state was latched on 11-06 (when a fresh /authorize was attempted, apparently for another credential) and restored on every relaunch, yet the user never saw any prompt until everything broke.
  4. The #94855 fix doesn't cover this. That fix shipped in 2.7032.0, and this build is much newer.

Asks:

  • If a sign-in is going to need re-auth anyway, surface it while it still works (banner or notification on the first session_stale_relogin), so people can re-login while they're at the machine.
  • Ideally, let an actively used desktop sign-in roll forward instead of hard-expiring, or allow re-auth to be completed from the mobile app for Remote Control users.

As a stopgap, I now watch main.log for session_stale_relogin and get notified, which gave me days of warning in this case.

fujiwarakasei avatar Nov 11 '26 05:11 fujiwarakasei

Same issue here (macOS, Claude Desktop, personal account).

I get forced back to the sign-in screen roughly every 24 hours, even while the Mac is awake and the app is in use. Re-signing in works, but it keeps coming back and it interrupts my daily work (Cowork / browser and file access on this Mac).

Symptoms match the reports above:

  • Forced re-login about every 24-36 hours
  • Quitting and restarting the app does not prevent it
  • Signing out and back in only resets the clock

Please treat this as a priority. A silent session refresh from the existing OAuth tokens, a longer session for a registered device, or at least a notification when the device goes offline would remove most of the pain.

Also note: the earlier report #81512 was closed automatically as "not planned" for inactivity, but users are still hitting it (latest confirmations in November).

mamimumina3-art avatar Nov 21 '26 04:11 mamimumina3-art

Another macOS data point. Here the fallback /authorize succeeds, so there is no forced logout, but each occurrence adds a new "Claude Code" row to Settings > Account > login locations.

Environment

  • Claude Desktop 6.28899.2, macOS 27.2 (Darwin 27.2.0), Apple Silicon, personal Max plan, single org
  • Bundled Claude Code 2.1.328. The standalone CLI (2.1.330) is also signed in on the same machine.
  • Remote Control is on, serving 3 folders
  • Times below are UTC, 2026-11-21

What happened

The app was quit and relaunched 17 times between 03:34 and 04:29. Six of those launches hit the same chain within about 1 minute of startup: 03:35, 03:45, 03:50, 03:55, 04:14 and 04:30. Every one of those launches logged a clean previous quit, a present sign-in cookie, and no update relaunch:

[startup-sign-in] state: { sign_in_cookie_present: true, signed_in_at_last_exit: true, previous_quit_clean: true, update_relaunch_marker: 'none' }

The most recent occurrence (ids redacted):

04:28:43 [info] Running onQuitCleanup: code-tab-token-log-out-revoke
04:28:43 [info] Running onQuitCleanup: everyday-token-held-revoke
04:29:08 [info] Starting app {
04:29:24 [warn] [remoteManagedSettings] fetch returned 401
04:29:24 [info] [oauth-v2] a live token was expired early: cause=org_read kind=other life_left=over_7d
04:30:15 [info] [oauth-v2] refreshing token for orgId=<org>
04:30:15 [error] OAuth token refresh failed (auth_error status=400 detail=<json error=invalid_grant len=85>)
04:30:15 [info] [oauth-v2] refresh rejected (auth_error) for orgId=<org>; tombstoning and falling through
04:30:15 [info] [oauth-v2] performing fresh /authorize for orgId=<org>

In the other five occurrences, the first rejection came from cause=remote_control_api kind=sessions life_left=over_7d instead of org_read. Each time it was the first refresh after the relaunch, and no session_stale_relogin followed.

Visible effect

Each fresh /authorize creates a new "Claude Code" row in Settings > Account > login locations, and its location and sign-in time both show "Unknown". At one point the list showed three such rows for this one machine:

  • the new Code-tab credential
  • the Code-tab credential it had just replaced
  • the CLI

Superseded rows stay listed until they are removed manually from that page. To a user, these extra rows with "Unknown" location look like unrecognized sign-ins.

Question

code-tab-token-log-out-revoke and everyday-token-held-revoke run on every quit, including plain quits with no sign-out. If either one revokes the Code-tab refresh chain on a normal quit, the next launch would get invalid_grant exactly as above. That fits the timing here: the failure always came on the first refresh after a relaunch, while the access token still had more than 7 days left. Can someone confirm what these cleanups do on a quit without sign-out?

wensiyuanseven avatar Nov 21 '26 04:11 wensiyuanseven

Same on macOS, with a test that rules out a stale device identity.

Environment: Claude Desktop 6.28899.6 (arm64), MacBook Air M2 (Mac14,2), macOS 27.2.1, personal Max, email sign-in. A second Mac on the same account runs Remote Control; Code sessions opened from the Air usually run there. The standalone CLI on the Air is signed out and nothing calls it, so this is not a CLI/Desktop refresher race.

Symptom: the app forces a full sign-in about once a day: 21 episodes 2026-11-08 → 11-28. Since 11-21 every episode in main.log (ids redacted) looks the same: get_device_info → RPC [unauthenticated] → "Sign in again to use this session" → login with reason untrusted device (stepUp, reauth=1, from=logout) → device registered again 13–16 s later → next day the same.

Test: the Mac was set up with Migration Assistant, so on 11-28 19:12 (UTC+2) I quit the app and moved ant-did and ant-device-registry.json aside. The app created a fresh device id and connected keyed (keyless=false, bindingState=bound), no sign-in needed. It did not help:

  • 11-29 09:14 — session_stale_relogin → stepUp
  • 11-30 17:10 — unauthenticated → "Sign in again" → stepUp, reason untrusted device
  • plus one enclave sign failed (OSStatus -25308) on 11-29 18:32; 308 get_device_info calls in those 48 h.

So a keyed, freshly registered device loses trust within ~24 h, and the trigger is a device check, not token expiry.

Asks

  1. Why does a just-registered keyed device become untrusted device within a day, and can the server keep trust for it?
  2. If a step-up is really needed, call it "device verification" instead of "sign-in expired", warn in advance, and allow approval from another signed-in device.
  3. Don't drop a typed prompt during the step-up (I lost one on 11-28).

Related: #104419, #104150, #95963, #109640.

oleksandrilyin avatar Nov 30 '26 20:11 oleksandrilyin