-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(claude-code): stop frequent sign-ins by hardening OAuth refresh #10410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Review complete. No remaining issues.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
src/api/providers/claude-code.ts
Outdated
| cacheWriteTokens: cacheWriteTokens > 0 ? cacheWriteTokens : undefined, | ||
| totalCost: 0, | ||
| let didRetryWithForceRefresh = false | ||
| while (true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This while true is a little scary - I don’t follow all of the logic, but I’m worried about a tight loop that keeps retrying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roomote fix it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixaroo
See task on Roo Cloud
Refactored the while (true) loop to a bounded for loop that clearly shows the retry limit (max 2 attempts). All tests passed.
Why
Users are being prompted to sign in to Claude Code (“Not authenticated with Claude Code”) roughly daily.
Root cause
Claude Code’s OAuth refresh response can legitimately omit
refresh_token(common OAuth behavior). We treated it as required, so refresh parsing could fail and we’d clear stored auth, forcing a full re-login.Fix
refresh_tokeninvalid_grant)[claude-code-oauth]logs to the Roo Code output channel for better diagnosticsTests
cd src npx vitest run api/providers/__tests__/claude-code.spec.ts integrations/claude-code/__tests__/oauth.spec.tsNote
We can’t extend the server-issued token TTL; this PR prevents unnecessary sign-outs by making refresh handling resilient.