Skip to content

fix(account): sync refreshed OAuth tokens back before keychain switch#101

Merged
himerus merged 9 commits intostagingfrom
fix/account-switch-credential-sync-back
Apr 14, 2026
Merged

fix(account): sync refreshed OAuth tokens back before keychain switch#101
himerus merged 9 commits intostagingfrom
fix/account-switch-credential-sync-back

Conversation

@himerus
Copy link
Copy Markdown
Contributor

@himerus himerus commented Apr 14, 2026

Summary

  • Root cause: account switch wrote stale credentials with already-rotated refresh tokens to Claude Code's keychain, causing 401 errors when Claude Code attempted its next token refresh
  • Adds syncBackActiveCredential() that reads Claude Code's current credential and updates reagent's stored copy before any switch operation
  • Tracks active account in ~/.reagent/active-account so sync-back targets the correct account
  • Advisory file lock prevents concurrent switches from corrupting credential entries

Test plan

  • npx tsc --noEmit passes
  • All 786 tests pass
  • npm run build succeeds
  • All pre-push quality gates pass (format, lint, types, tests, build, pack, shellcheck)
  • Manual: rswitch <account>, wait for token refresh (~1h), rswitch again — verify no 401
  • Manual: run rswitch in two terminals simultaneously — verify lock prevents corruption

himerus and others added 9 commits April 13, 2026 22:17
feat(account): add account verify, preserve credential fields, expiry warnings
fix(account): keychain slot swap for rswitch — sessions survive overnight
This reverts commit b75fb09.
account switch was writing stale credentials with already-rotated refresh
tokens, causing 401 errors when Claude Code attempted its next token refresh.

Adds sync-back mechanism with active-account tracking, advisory file locking,
and input validation.
@himerus himerus merged commit 4dad2f7 into staging Apr 14, 2026
12 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant