Repository navigation
fix(usage): read the Claude sign-in that expires later, keychain item or credentials file - #277
Conversation
… or credentials file
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 SummarySummary by CodeRabbit
WalkthroughClaude sign-in discovery checks both the macOS keychain and ChangesClaude Credential Freshness
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to The change selects fresher Claude credentials while preserving keychain preference when expiry cannot be compared. No actionable merge-blocking risk remains, subject to normal checks. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 2 systems. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
…older credentials file
# Conflicts: # CHANGELOG.md
Prepares v0.3.41. - `package.json` and `herdr-plugin.toml` go to 0.3.41. - The `[Unreleased]` notes move under `[0.3.41] - 2026-10-02`; compare links added. - 19 entries that had no PR link get one, with `by @login` for outside contributors (#262 by @diegolhambi; #255, #277, #278, #279 by @ddotz). After the merge: `gh workflow run release.yml --ref main -f version=0.3.41`.
Change
On a Mac, Claude's usage takes the
Claude Code-credentialskeychain item whenever it can read it, and uses~/.claude/.credentials.jsononly when the item is missing or locked (server/usage.ts, claude provider).Claude Code started outside the desktop session (over SSH, by a detached multiplexer or a launchd service) cannot write the login keychain, so it refreshes only the credentials file. The item keeps an access token that expired hours ago, and Claude Code keeps refreshing only the file, so the item never catches up. A server that can read the item then shows Claude as
expiredwhile Claude Code is signed in and working.Now both stores are read and the sign-in that expires later wins; on a tie the keychain item still wins, as before. Cursor's usage already uses this rule for its CLI and app sign-ins. Both stores are still only read: nothing is refreshed, written or run.
Merge order with #255: this should land before or together with #255. #255 makes the item readable from a server outside the desktop session. Without this change, a server and Claude Code that both run outside the desktop session would go from working (the file is used because the item reads as locked) to
expired(the stale item wins).Validation
main(ef90055), unchanged, on macOS with Claude Code running in herdr panes started outside the desktop session:expiresAt2026-10-01T12:27Z (in the past); credentials fileexpiresAt2026-10-01T23:25Z (valid).new UsageService(systemUsageContext(), [claude]).report(true)run in the desktop session (a one-shotlaunchctl bootstrap gui/<uid>job):problem: "expired", no windows. Run outside it,securityexits 36, the file is used and the session and week windows show.problem: null, with the session and week windows.main); a fresher item with an older file still reads the item. The existing equal-expiry "prefers the Claude keychain item" test is unchanged and passes.bun run generate:types --check,bun run typecheck,bun run build: pass.bun run test:unit: 727 pass, 1 skip, 0 fail (main: 725 pass, 1 skip, 0 fail).