Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Dec 30, 2025

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

  • Preserve the existing refresh token when the refresh response omits refresh_token
  • Don’t clear stored credentials for transient refresh failures (network/5xx); only clear for clearly-invalid refresh tokens (e.g. invalid_grant)
  • If a request fails due to auth, force-refresh once and retry the request
  • Route [claude-code-oauth] logs to the Roo Code output channel for better diagnostics

Tests

cd src
npx vitest run api/providers/__tests__/claude-code.spec.ts integrations/claude-code/__tests__/oauth.spec.ts

Note

We can’t extend the server-issued token TTL; this PR prevents unnecessary sign-outs by making refresh handling resilient.

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. bug Something isn't working labels Dec 30, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 30, 2025

Oroocle Clock   Follow along on Roo Cloud

Review complete. No remaining issues.

  • Test: restore global.fetch after mocking to avoid leaking state across tests
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph changed the title fix(claude-code): prevent daily re-auth by hardening oauth refresh fix(claude-code): stop frequent sign-ins by hardening OAuth refresh Dec 30, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 30, 2025
cacheWriteTokens: cacheWriteTokens > 0 ? cacheWriteTokens : undefined,
totalCost: 0,
let didRetryWithForceRefresh = false
while (true) {
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roomote fix it

Copy link
Contributor

@roomote roomote bot Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixaroo Clock   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.

View commit | Revert commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

4 participants