You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Exit-time refresh tokens not persisted, causing invalid grant errors on restart #16957
Bug Description
Claude Code fails to persist refresh tokens received during exit, causing authentication failures on restart
Description
Claude Code v2.1.1 exhibits inconsistent OAuth refresh token handling with several issues:
Issue 1: Exit-time refresh tokens not persisted
When Claude Code exits and performs a token refresh during shutdown, it does not persist the new refresh token. On restart, it attempts to use a previously rotated token that has been revoked.
Observed pattern:
Claude Code exits, /exit or ctrl-c x 2 (sometimes triggers a final token refresh)
Server returns a new rotated refresh_token
Claude Code exits without persisting this token
On restart: Claude Code uses a previous refresh token instead of the latest one
Result: "Invalid grant: refresh token is invalid" because the old token was revoked
Issue 2: Inconsistent error reporting
When token refresh fails, Claude Code behavior is inconsistent:
Sometimes it correctly reports an authentication error (1 MCP server failed)
Sometimes it fails silently and shows the MCP as connected and authenticated, even though the server returned an error
In the silent failure case, users only discover the problem when attempting to use MCP tools: "Error: Unauthorized - Session not found"
Reproduction
Testing with accelerated token expiry consistently shows Claude Code reverting to earlier refresh tokens on restart instead of using the latest token it received.
Impact
Users experience authentication failures on restart requiring re-authentication, even though valid refresh tokens were provided by the OAuth server.
This issue is specifically about oauth refresh token rotation during exit not being persisted. On restart, Claude Code uses an old rotated token that was revoked, causing "Invalid grant" errors.
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.
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.
Activity
github-actions commentedon Jan 8, 2026
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
runeb commentedon Jan 9, 2026
Not duplicates.
This issue is specifically about oauth refresh token rotation during exit not being persisted. On restart, Claude Code uses an old rotated token that was revoked, causing "Invalid grant" errors.
Different bugs with different reproduction patterns.
github-actions commentedon Feb 9, 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 23, 2026
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
github-actions commentedon Mar 3, 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.