Replace hardcoded 7-day inactive token refresh window with dynamic half-lifetime#1
Draft
Replace hardcoded 7-day inactive token refresh window with dynamic half-lifetime#1
Conversation
- Add tokenNeedsRefreshInactive (7-day window) for accounts not currently active in Claude Code; inactive accounts have no racing concern with Claude Code's background token rotation - Update refreshClaudeCredentials to take activeEmail and apply the narrow 1-hour window only to the active account (or all accounts when active account is unknown), and the wider 7-day window to inactive accounts - Pass Scopes to WriteCredentials in switchAndLaunch to preserve scope info - Warn clearly with actionable guidance when switching to an expired account - Update callers in claude.go and list.go to pass claude.ActiveEmail() Co-authored-by: zhangweiii <31117497+zhangweiii@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Explain account switching mechanism for Claude Code
Fix credential expiration for inactive Claude Code accounts
Mar 11, 2026
…etime Record IssuedAt when a Claude credential is first saved, auto-synced, or refreshed. Compute the inactive-account refresh threshold as half the token's total lifetime (expiresAt - issuedAt) / 2, so the window self-calibrates to Claude's actual OAuth token duration. Tokens without a recorded IssuedAt fall back to a 24-hour look-ahead. - internal/store/store.go: add IssuedAt int64 field to Credentials - internal/store/sync.go: set IssuedAt when auto-syncing active token - cmd/login.go: set IssuedAt when saving credentials via auto-switch login - cmd/common.go: dynamic tokenNeedsRefreshInactive(expiresAt, issuedAt), set IssuedAt after successful refresh, fix stale 7-day doc comment Co-authored-by: zhangweiii <31117497+zhangweiii@users.noreply.github.com>
Copilot
AI
changed the title
Fix credential expiration for inactive Claude Code accounts
Replace hardcoded 7-day inactive token refresh window with dynamic half-lifetime
Mar 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The inactive-account proactive refresh window was a hardcoded 7 days, ignoring Claude's actual OAuth token lifetime. For a 30-day token this triggers unnecessarily early; for a shorter-lived token it may not trigger at all.
Changes
store.Credentials— addedIssuedAt int64(unix ms,omitempty) to record when a token was issued or last refreshedtokenNeedsRefreshInactive— replaced the 7-day constant with a dynamic half-lifetime threshold:Falls back to 24 h for tokens missing
IssuedAt(accounts saved before this change) or with invalid timestamps (issuedAt ≥ expiresAt)IssuedAtpopulation — set totime.Now()at every credential write point:cmd/login.go— onauto-switch loginstore.SyncActiveToken— when Claude Code's background rotation is detectedrefreshClaudeCredentials— after a successful OAuth refresh💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.