Repository navigation
fix(cli): follow the active claude-swap account in Claude usage - #4631
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: afab3b87ee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let active = ClaudeSwapAccountProjection.accountSnapshots( | ||
| from: list, | ||
| source: source, | ||
| previousAccounts: ClaudeSwapRetainedUsageStore.load()).first(where: \.isActive), |
There was a problem hiding this comment.
Persist the fresh adapter projection
When a previous cards/dashboard run cached an exhausted window and this path later receives a fresh non-exhausted snapshot for the same active slot, the new projection is returned but never saved. If a subsequent codexbar usage call receives an unavailable row without measurements, accountSnapshots reloads the older exhausted snapshot and can report that stale quota until its original reset time; save the projected accounts, as the cards and dashboard consumers do, before selecting the active snapshot.
Useful? React with 👍 / 👎.
|
Codex review: blocked before merge. What this changesThis PR makes one-shot Claude Auto usage follow the active claude-swap account and label ordinary-source fallbacks. Example: The browser uses slot 1 while claude-swap slot 3 is active.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain Keep open: the owner-approved account-selection change addresses a real report, but the new path can resurrect obsolete exhausted quota. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe CLI selects a Claude data source, projects adapter account measurements or fetches ordinary provider usage, and renders text, JSON, or TOON. flowchart TD
A[Usage command] --> B[Source and account eligibility]
B --> C[Configured account adapter]
C --> D[Shared account projection]
E[Retained quota cache] --> D
D --> F[Active slot output]
B --> G[Ordinary provider fetch]
C --> G
G --> F
Technical reviewBest possible solution: Save the complete successful adapter projection through the existing retained-usage store before selecting the active slot. Do we have a high-confidence way to reproduce the issue? The reporter's distinct browser/active-slot measurements match current-main routing, and source inspection establishes the introduced retained-cache failure sequence; no target code was executed. Is this the best way to solve the issue? Reusing the existing adapter and projection is appropriate for the approved direction, but the new consumer must also honor their successful-refresh cache contract. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7e31e74ea662. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 19, 2026, 12:26 AM ET / 04:26 UTC. |
# Conflicts: # CHANGELOG.md
Merge fork/main (265d2af) into upstream main (59a7d46). Conflict handling: - Overview/menu: the fork's Overview row model and removal of the provider switcher win (StatusItemController+Menu/MenuPresentation/OverviewSubmenus/ SwitcherViews, switcher tests). Upstream steipete#4549's plugin gauge helper moves to StatusItemController+SwitcherMetrics.swift for the icon code that still uses it. Upstream steipete#4626 "Show all accounts in Overview" keeps its setting and mergedOverviewRows, but the fork Overview does not read them yet. - Claude: upstream steipete#4517 tcr source merged alongside magpie ownership: claude-swap runs only while magpie does not own Claude (claudeSwapEffectivelyEnabled, native-route gate in the runtime), the account heading/ordinal/source label handle tcr and magpie, and widget owner keys keep claude/swap, claude/tcr and claude/magpie namespaces. - CLI: upstream steipete#4631 claude-swap follow is skipped while the magpie switch owns Claude. - Config: upstream shareUsageWithCLI and the fork's top-level magpie config are both encoded; the legacy Claude cookie migration keeps the fork's magpie gate on top of upstream's table-driven migrator. - Settings: upstream mergedOverviewAllAccounts kept next to the fork's overview window filter and collapsed groups; switcherShowsIcons and switcher shortcuts stay removed but still import from older exports. - UsageStore: postQuotaWarning/postPredictivePaceWarning move to an extension to keep the class body under the SwiftLint limit after both sides added stored properties.
Claude Auto usage previously followed the ordinary provider pipeline, so it could report the browser account while cards and dashboard showed the active claude-swap slot. Reuse the existing adapter and account projection to return that active slot for one-shot Auto usage, including single-slot lists.
Explicit non-auto sources, configured non-auto sources, and explicit account selection keep their existing behavior. If the adapter fails or has no usable active slot, the ordinary fetch path remains available and its source is marked, for example,
web (claude-swap fallback). Identity, measurement timestamps, and last-known diagnostics belong to the reported source. No credential reads or provider registration changes were added; serve retains its existing path.Removed redundant CLI payload/account-selection and cards forwarding wrappers to keep production code net smaller. Updated the CLI/Claude docs and the 0.77.1 changelog. Thanks @postoso for the reproduction.
Verification
All Swift checks ran through the shared host build lock with the scrubbed test environment.
7f7977b9881:swift test --build-system native --jobs 2 -Xswiftc -gnone --filter CLIUsageClaudeSwapTests— 1 test failed with 5 assertions: browser identity and 0/92 usage instead of the active slot and 50/41.swift test --build-system native --jobs 2 -Xswiftc -gnone --filter 'CLIUsageClaudeSwapTests|CLICardsClaudeSwapTests|CLIUsageCacheTests|CLIParallelUsageTests|CLIUsageFetchSetupTests|CLIOutputTests|CLIToonSnapshotTests|CLIWebFallbackTests|TokenAccountCLISelectionTests|ProviderArchitectureGatekeeperTests|BrowserCookiePromptContractTests|ClaudeSourcePlannerTests'— 187 tests in 16 suites passed, including all 10 new cases.make check— passed; SwiftLint found 0 violations in 3,052 files.git diff --checkand the catalog precheck — passed.Fixtures use distinct synthetic browser/swap identities and a fake read-only adapter. No live account probes or app relaunches were used.
Fixes #4599