Skip to content

Bug: /login Does Not Recover Active Session After OAuth Token Expiration #15007

Closed as not planned

Description

@brianmjohnson

Bug Report: /login Does Not Recover Active Session After OAuth Token Expiration

Summary

When an OAuth token expires during an active Claude Code session, running /login and successfully authenticating in the browser does not recover the session. The session remains stuck in a 401 error loop, forcing users to abandon the session and lose context.

Problem Description

Current Behavior

  1. User is in an active Claude Code session
  2. OAuth token expires (after ~1 hour of use or idle time)
  3. Session shows repeated errors: API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth token has expired..."}}
  4. User runs /login command
  5. Browser opens, user completes OAuth authorization successfully
  6. User returns to CLI and types continue or resume
  7. Session continues showing 401 errors - token not picked up
  8. No amount of retrying helps - session is permanently stuck

Expected Behavior

After successful /login authentication:

  1. The active session should detect the new token
  2. continue or resume should work immediately
  3. Session context should be preserved

Why This Matters

  • Lost context: Users must abandon sessions with in-progress work
  • Breaks workflows: Unattended execution is impossible
  • Poor developer experience: /login appears to succeed but doesn't actually fix the problem
  • Data loss risk: Uncommitted work or in-memory state is lost when session is abandoned

Reproduction Steps

  1. Start a Claude Code session
  2. Work for 45-60+ minutes (or wait until token expires)
  3. When 401 error appears, run /login
  4. Complete browser OAuth flow
  5. Return to CLI
  6. Type continue or resume
  7. Observe: Session still shows 401 errors

Evidence from Session Logs

Session log shows 6+ consecutive 401 errors after /login:

API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth token has expired. Please obtain a new token or refresh your existing token."},"request_id":"req_011CWLUr4VZkAL644D4Di2nC"} · Please run /login
API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth token has expired. Please obtain a new token or refresh your existing token."},"request_id":"req_011CWLUt58aFJwcWZG8NMqA4"} · Please run /login
API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth token has expired. Please obtain a new token or refresh your existing token."},"request_id":"req_011CWLUzY7DCEZ1Mr6dF6B15"} · Please run /login
...

Each request has a unique request_id, confirming these are separate retry attempts, all failing.

Technical Analysis

Root Cause Hypotheses

Hypothesis Description
In-memory token caching Active session caches token in memory, doesn't reload from disk after /login
Token file not updated /login saves token but active session reads from different location
Race condition Browser callback completes but CLI doesn't wait for token write
Session ID mismatch Token saved with session ID that doesn't match active session
Process isolation /login runs in subprocess that can't update parent process state

What We've Tried

Workaround Result
Multiple continue commands Still 401
resume command Still 401
Wait 5+ minutes after /login Still 401
/login multiple times Still 401

What Might Work (Destructive)

Option Trade-off
Kill session, start fresh Loses all context
/logout then /login Untested, likely loses context
New terminal window Loses session entirely

Impact

Severity: High

  • Frequency: Occurs on every session >1 hour
  • User impact: Complete session loss, work interruption
  • Workaround availability: None that preserve session

Affected Use Cases

Use Case Impact
Long coding sessions Must restart every hour
Autonomous builds Cannot run unattended
Complex multi-step tasks Risk of losing progress mid-task
Agent frameworks Breaks reliability guarantees

Proposed Fix

Option A: Token Hot-Reload (Preferred)

Active session should detect token file changes and reload:

1. /login saves new token to ~/.claude/auth-token (or equivalent)
2. Active session watches file or checks on next API call
3. If token changed, reload it before retrying

Option B: IPC Token Update

/login subprocess should notify parent process:

1. /login completes OAuth flow
2. Sends signal/message to active session PID
3. Active session receives new token directly

Option C: Force Token Refresh Command

Add /refresh-token command that:

1. Re-reads token from disk
2. Updates in-memory token
3. Retries last failed request

Environment

  • OS: macOS Darwin 25.1.0
  • Claude Code Version: 2.0.53
  • Session duration before issue: ~4+ hours with intermittent activity
  • Authentication method: OAuth (browser-based)

Related Issues

This may be related to:

  • Token refresh/rotation handling
  • Long-running session management
  • OAuth flow completion detection

Workaround for Other Users

Until fixed, the only reliable workaround is:

  1. Commit all work frequently (git commit after each logical change)
  2. Use issue trackers (like bd beads) to persist state
  3. Accept that sessions >1 hour may need to be restarted
  4. When stuck in 401 loop, kill session and start fresh

This is not acceptable for production use of autonomous agents.

Activity

  1. added
    bug
    has repro
    platform:macos
    on Dec 21, 2025
  2. github-actions commented on Dec 21, 2025

    @github-actions

    Found 2 possible duplicate issues:

    1. [BUG] OAuth token expiration disrupts autonomous workflows – refresh token handling needed #12447
    2. OAuth expiration causes retry storm consuming 100% session usage (3.75M wasted tokens) #10784

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  3. brianmjohnson commented on Dec 21, 2025

    @brianmjohnson
    Author

    This issue is distinct from the suggested duplicates:

    This issue (#15007) is specifically about the /login command:

    1. User runs /login after 401 error
    2. Browser opens, OAuth flow completes successfully
    3. User returns to CLI
    4. Session remains stuck in 401 loop - the new token is NOT picked up

    The key difference: /login appears to succeed (browser auth works) but the active session doesn't reload the token. This is a token hot-reload / IPC problem between the login subprocess and the active session.

    The other issues don't address why /login specifically fails to recover the session.

  4. Soli-code commented on Dec 23, 2025

    @Soli-code

    Same problem here.. Claude code doesn't work in terminal

  5. mnewkirk commented on Jan 1, 2026

    @mnewkirk

    I have this same issue through the MacOS Claude client using the 'Code' tab. After returning to a session the next day, I get the authentication error, i.e.:

    API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth token has expired. Please obtain a new token or refresh your existing token."},"request_id":"req_011CWh69FsZ51TAU4m32Uysd"} · Please run /login

    /login as a command from the client does not work, but if I go into the CLI from the client and /login, that will have me re-auth. If I continue to work from the CLI within the client, that will let me continue the session but that context will not be saved back to the client which makes it undesirable. Quitting Claude (usually requiring the activity monitor, as Quit will not actually close the app, possibly a separate issue) and re-starting lets me resume the prior Code session within the mac client.

    After quitting and restarting and entering 'continue' it will understand my previous request that was failing., e.g.

    The back tongue is now taller (5mm vs 3mm) and raised higher (3mm vs 1mm) to take advantage of the greater material thickness at the back of the tray. This should provide a much better fit and stronger connection!

    Two additional corrections to make. The distance between the right-most edge of the center hole and the left-most edge of the right hole is 4.2mm. The distance between the right-most edge of the left hole and the left-most edge of the center hole is 5.2mm.

    API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth token has expired. Please obtain a new token or refresh your existing token."},"request_id":"req_011CWh5vis9y14YCCYMC3Xms"} · Please run /login

    Unknown slash command: login

    (after quitting and restarting)

    continue

    I understand. You need to adjust the spacing between the holes. Let me calculate the current spacing and then fix it.

    Using Claude 1.0.2339 (1782e2) 2025-12-16T19:35:52.000Z

  6. BlindGuyNW commented on Jan 4, 2026

    @BlindGuyNW

    Just chiming in to say this is also a serious problem on Windows. I thought my sessions were irrecoverable until i found out about killing Claude here, so thanks for that.

  7. faze79 commented on Jan 8, 2026

    @faze79

    I have the same issue

  8. github-actions commented on Feb 8, 2026

    @github-actions

    This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

  9. added
    autoclose
    on Feb 8, 2026
  10. github-actions commented on Feb 22, 2026

    @github-actions

    Closing for now — inactive for too long. Please open a new issue if this is still relevant.

  11. github-actions commented on Mar 2, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  12. locked as resolved and limited conversation to collaborators on Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:authautoclosebughas reproplatform:macos

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions