Skip to content

Show OpenCode Zen and Claude extra usage balances - #24634

Draft
nwparker wants to merge 3 commits into
mainfrom
nwparker/opencode-provider-balances
Draft

nwparker wants to merge 3 commits into
mainfrom
nwparker/opencode-provider-balances

Conversation

@nwparker

@nwparker nwparker commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​955 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​948
Prod 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​604 $\color{#cf222e}{\Huge{\mathbf{−}}}$​22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​582

ELI5

Usage popovers can show OpenCode Zen credit balances and Claude extra usage. Go quotas remain visible when billing cannot be fetched; an unknown Zen balance appears as Unavailable rather than zero.

What Changed

Parse the optional console billing response independently from Go quotas, preserving signed USD microcent amounts and limiting the extra request to five seconds. Parse Claude's supplied spend/legacy extra_usage payloads with their currency exponent, preserving missing balances. Share the popover section and currency formatting; the compact segment reveals a spendable balance only after a quota caps.

Why

Quota windows alone do not describe paid fallback spending. Keeping optional billing separate prevents a billing failure from erasing valid quotas. This ports the Claude/OpenCode portion of @mmarabel's #9363, with original author credit; its Codex probe changes are outside this focused scope.

Linked Issue

#8145 and #9362; continues the relevant parts of #9363.

Visual Proof

Real hidden Orca IPC quota snapshot, rendered with the baseline component:

Before: Go quota windows

Same source rendered with this component:

After: quotas plus unavailable Zen balance

Explicit numerical fixture, not a real account balance:

Fixture: known amount versus unavailable

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

132 focused tests in seven files pass: signed/zero microcent values, optional billing timeout/errors, balance-only console accounts, unknown balances, capped/disabled compact display, currency formatting and Claude payloads. pnpm tc, changed-code quality, formatting, diff-check and commit hooks pass. Rebuilt hidden Electron app used disposable home/profile and CDP; no user config or shared OpenCode service changed.

Installed OpenCode v2.0.16 and read-only reference source inspected. A direct private request with the isolated copied key returned403; Orca's Electron request independently returned valid Go quotas but no balance. Neither proves real console billing success. Real Go login from the account worker proves connection/persistence only. The official deployed console client now independently confirms the scoped billing endpoint and signed decimal-string microcent wire contract. This source inspection does not prove successful account authentication.

Review

Hold this draft for real authorized billing proof. The expected new-console contract is precisely tested: /console/api/billing/status, console cookie plus x-org-id, prepaid/pay-as-you-go mode, signed integer-string balanceMicroCents, divided by100,000,000 for USD. Its wire schema and console-prefixed URL are independently confirmed in the official deployed console client: signed BigInt values encode as strings, USD conversion divides by100,000,000, and workspace scope uses x-org-id. A successful authenticated matched-workspace response remains unverified. No zero balance is inferred from failure.

The successful API-key Go path has no verified Zen balance endpoint or identity match to a separate console cookie; it displays Unavailable rather than mixing two possibly different accounts. No successful billing fetch, live Claude credit response, or full issue resolution is claimed.

Agent skill upstream boundary

  • Not applicable.

Notes

Preserves @mmarabel credit. No merge or closure performed; do not close the original PR until its remaining scope has a disposition.

Checklist

  • Focused Claude/OpenCode scope
  • Before/after and fixture evidence clearly separated
  • Original author credited
  • Optional-field remote compatibility and execution-host secret ownership preserved
  • Real authorized console billing and Claude payload proof pending
  • Full suite and packaging: CI

Review correction: commit 0c87d15fa19 preserves the currency of a balance-only spend response and refuses inconsistent currencies across balance, spend and cap. Nine focused tests, full typecheck and changed-code quality pass; this is mapper fixture evidence and does not satisfy the authenticated billing merge hold.

Review correction: caf1d8bc9f8 treats non-string currency fields as unavailable optional spending data. Real fetcher response fixtures with null and numeric currencies preserve valid quotas and return unavailable extra usage; 11 focused tests across two files, typecheck and changed-code quality pass. Authenticated billing proof remains pending.

This branch has not been deployed

No deployments
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