Repository navigation
Closed as not planned
Closed as not planned
Copy link
Labels
area:authautocloseIssue will be closed automaticallybugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOS
Description
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
- User is in an active Claude Code session
- OAuth token expires (after ~1 hour of use or idle time)
- Session shows repeated errors:
API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth token has expired..."}} - User runs
/logincommand - Browser opens, user completes OAuth authorization successfully
- User returns to CLI and types
continueorresume - Session continues showing 401 errors - token not picked up
- No amount of retrying helps - session is permanently stuck
Expected Behavior
After successful /login authentication:
- The active session should detect the new token
continueorresumeshould work immediately- 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:
/loginappears 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
- Start a Claude Code session
- Work for 45-60+ minutes (or wait until token expires)
- When 401 error appears, run
/login - Complete browser OAuth flow
- Return to CLI
- Type
continueorresume - 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:
- Commit all work frequently (
git commitafter each logical change) - Use issue trackers (like
bdbeads) to persist state - Accept that sessions >1 hour may need to be restarted
- When stuck in 401 loop, kill session and start fresh
This is not acceptable for production use of autonomous agents.
Reacted by mlissen, Matt Newkirk, LawSnap, Felix and vreugdevolk
Metadata
Metadata
Assignees
Labels
area:authautocloseIssue will be closed automaticallybugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOS
Activity
github-actions commentedon Dec 21, 2025
Found 2 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
brianmjohnson commentedon Dec 21, 2025
This issue is distinct from the suggested duplicates:
This issue (#15007) is specifically about the
/logincommand:/loginafter 401 errorThe key difference:
/loginappears 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
/loginspecifically fails to recover the session.Soli-code commentedon Dec 23, 2025
Same problem here.. Claude code doesn't work in terminal
mnewkirk commentedon Jan 1, 2026
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.:
/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.
(after quitting and restarting)
Using Claude 1.0.2339 (1782e2) 2025-12-16T19:35:52.000Z
BlindGuyNW commentedon Jan 4, 2026
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.
faze79 commentedon Jan 8, 2026
I have the same issue
github-actions commentedon Feb 8, 2026
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.
github-actions commentedon Feb 22, 2026
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
github-actions commentedon Mar 2, 2026
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.