Repository navigation
Show provider credit balances alongside usage limits - #25408
Conversation
Adapt the original provider-balance contribution to current main, preserve unknown values, and expose OpenCode balance refresh failures. Co-authored-by: mmarabel <[email protected]>
|
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 configuration
📒 Files selected for processing (10)
🚧 Files skipped from review as they are similar to previous changes (6)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review. 📝 WalkthroughWalkthroughThe change adds a shared extra-usage balance type to provider rate limits and maps balance data from Claude OAuth, Codex RPC, and OpenCode Go billing responses. OpenCode Go fetching now supports organization workspace IDs and can return balance-only results for explicit no-access usage responses. The status bar and tooltip display currency balances, credit counts, availability states, and capped-usage details. Locale strings and tests cover mapping, fetching, formatting, and display behavior. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The change shows provider balances in the status bar and tooltip. Compact balance labels are now localized as a single message, so word order is correct in each language. No merge-blocking risk remains from the reviewed evidence. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The additional billing read preserves existing credential isolation and separates balance failures from valid usage results. No introduced exploitable path was established in the examined changes. Provider-side organization authorization and portions of the affected scope remain unverified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 3 | ❌ 1 | ❓ 1❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
Full details: Out of Scope Changes checkExplanation The PR description also claims to fix Full details: Docstring CoverageExplanation Docstring coverage is 15.91% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 44 functions across 26 files. (6 skipped: 6 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2d9105d7-8470-4c8b-adf1-25c1ce303cda
📒 Files selected for processing (31)
src/main/rate-limits/claude-fetcher-extra-usage.test.tssrc/main/rate-limits/claude-oauth-usage-request.tssrc/main/rate-limits/claude-usage-credits.tssrc/main/rate-limits/claude-usage-result.tssrc/main/rate-limits/codex-credit-balance.tssrc/main/rate-limits/codex-fetcher-credit-balance.test.tssrc/main/rate-limits/codex-rate-limit-window-classification.tssrc/main/rate-limits/codex-rpc-rate-limit-probe.tssrc/main/rate-limits/opencode-go-status-parsing.test.tssrc/main/rate-limits/opencode-go-status-parsing.tssrc/main/rate-limits/opencode-go-usage-fetcher.test.tssrc/main/rate-limits/opencode-go-usage-fetcher.tssrc/main/rate-limits/opencode-go-usage-source-selection.test.tssrc/main/rate-limits/opencode-go-usage-source-selection.tssrc/renderer/src/components/status-bar/StatusBarProviderSegment.tsxsrc/renderer/src/components/status-bar/provider-extra-usage-section.tsxsrc/renderer/src/components/status-bar/provider-segment-balance.test.tsxsrc/renderer/src/components/status-bar/tooltip.test.tssrc/renderer/src/components/status-bar/tooltip.tsxsrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/fr.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/renderer/src/i18n/provider-credit-balance-locales.test.tssrc/shared/credit-count-format.test.tssrc/shared/credit-count-format.tssrc/shared/currency-format.test.tssrc/shared/currency-format.tssrc/shared/rate-limit-types.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — read the complete diff end-to-end (31 files), traced each provider path into its consumers, and verified the changed suite, typechecks, and repo gates locally.
- Shared credit model: optional
extraUsageonProviderRateLimits, modeled as a discriminated union so currency balances (unit: 'currency', nullable balance) and unitless credit counts (unit: 'credits',unlimited) can't be confused. - Claude: OAuth
spendobject → cap/balance/spent-percent mapping with a legacyextra_usagefallback; a missing balance stays unknown rather than becoming zero, andmergeClaudeUsageWindowspreserves the field when the CLI supplements windows. - Codex:
rateLimits.creditsmapped to a credit count on the RPC probe path, hidden unless the account actually has credits. - OpenCode Go:
org_workspace IDs accepted, an optional console billingGETrun concurrently with each candidate's status fetch (5s cap, always aborted and awaited before advancing), a strictprepaid/pay-as-you-goparser, honest unavailable/refresh-failed states, and unchanged API-key precedence. - Renderer: popover extras section plus a compact token gated on both a capped window and a spendable balance.
- i18n / formatters: new
currency-formatandcredit-count-formathelpers with malformed-input fallbacks; sparse locale catalogs intentionally omit copied English balance strings and resolve them from the call-site defaults.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
Keep the proxy audit current for the isolated billing request.
…/provider-credit-balances-current
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — re-reviewed the delta since the prior pullfrog review at e55b91d: the translation-ordering commit and the merge of main.
- Localized compact balance: Replaced label/amount string concatenation in
formatCompactExtraUsagewith placeholder messages ('{{value0}} credits','{{value0}} bal') so translated catalogs can order the label before or after the amount. - Catalog alignment: Updated
en.jsonand thees/fr/ja/ko/zhcatalogs to carry the{{value0}}placeholder, and covered runtime fallback/interpolation inprovider-credit-balance-locales.test.ts. - Ordering regression test: Added a
provider-segment-balance.test.tsxcase that drives Spanish/French reordered copy through the mockedtranslate, verifying the component forwardsvalue0; it fails against the prior concatenation. - Proxy audit: Bumped the audited non-
net.fetch(count foropencode-go-usage-fetcher.tsfrom 2 to 3 to cover the optional billing request.
I checked the one risk this change opens — a catalog that carries a translated 4fba7dc1e7 without the {{value0}} placeholder would silently drop the amount. Only the five updated catalogs contain that key, and each now includes the placeholder, so the English fallback is never shadowed by stale copy. Focused tests and the localization extraction/coverage/runtime-catalog gates pass locally at this head.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
Scan the merged PRs since the 2026-10-05 scan (d3943c6): 331 new en keys, 33 removed, 15 changed values. All five target locales were missing the same 187 keys; 11 are provider credit-balance keys intentionally left to the English sparse fallback (#25408), so this adds the remaining 176 keys to each locale (es 177: it alone was missing TerminalErrorToast.heldByPreviousRelay). Also fix two stale changed-English values ("Git AI Author changes" -> "AI settings") that still read "AI changes"/"移動" in es/fr/ja. Additive only: +881 target values, 0 removed. The repair pipeline normalized ja 新しい->新規, エージェント->Agent, and retry/待っている. Three review rounds (5 reviewers each): R1 fixed 14, R2 fixed 13, R3 clean. Gates: catalog verify, coverage --check, extraction, runtime-catalog, and the locale vitest suites (43 files, 386 tests) all pass.

ELI5
Show available provider credits alongside usage limits. A missing balance stays unknown; a failed refresh is shown clearly.
What Changed
This takes over @mmarabel’s provider-balance contribution in #9363 and adapts it to current main. The existing usage collector and status-bar menu now show Claude usage credits, OpenCode Zen balance, and Codex credit counts when the response supplies them. The compact segment reveals a spendable balance when a plan window caps.
OpenCode cookie discovery accepts organization workspace IDs. Its optional billing request uses the existing isolated session and workspace, while API-key usage keeps its existing priority. A missing key-response balance shows “Unavailable”; a failed cookie billing request shows “Refresh failed” without hiding valid Go quotas. Missing or invalid Claude and Codex values stay unknown, while known zero and unlimited credits remain valid.
Why
Whether a balance is known depends on the provider response and credential source. Keeping that distinction in the existing collector and menu gives users the credit information beside their limits without a separate login or a fabricated zero balance.
Linked Issue
Fixes #8145 and #9362. Supersedes the original contribution #9363, with credit to @mmarabel.
Visual Proof
The same controlled organization-cookie response reproduces the missing-workspace state before the fix and shows the balance after it. The additional captures show billing failure and installed-CLI API-key precedence. These are actual hidden-renderer captures from Orca on macOS; the HTTP responses are controlled test fixtures.
Before: organization cookie was not discovered
After: known Zen balance alongside Go quotas
After: billing failure remains explicit
After: API-key usage does not invent a balance
Testing
The two remaining UI cases completed with app exit and close code 0, CLI waits, and checked private endpoint closure. The earlier before and known-balance runs stopped during cleanup; their collector and menu observations are retained as partial evidence. This validates controlled responses, not a live wallet, paid provider turn, or every platform.
Review
Credit to @mmarabel for the original implementation. Unknown values are never converted to zero. Claude’s richer spend fields are retained for response compatibility; they are not asserted as a verified current live account contract.
Agent skill upstream boundary
Notes
Balance fields are optional in the existing payload. Credential-source precedence, remote execution ownership, and wire operations are preserved. Currency uses the existing locale-aware formatter. Complete translated balance messages control label and amount order; untranslated copy uses the existing English fallback. No new platform-dependent process or path handling is introduced.
Checklist