Skip to content

Usage view: per-provider/model cost and token analytics over 7/30/90 days - #236

Merged
currentbits merged 5 commits into
mainfrom
coder/usage-and-cost-analytics-view-per-provid-52e120
Aug 17, 2026
Merged

currentbits merged 5 commits into
mainfrom
coder/usage-and-cost-analytics-view-per-provid-52e120

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Closes #152.

Solenta only ever showed usage two ways: a per-thread token/cost line and a single "today vs budget" meter in the sidebar. Neither answers the question people juggling five providers actually ask — where did my quota go this week, and to which model. usageByThread looks like it holds that data, but it is a cumulative per-thread snapshot with no time dimension, and spendByDay is cost-only with no provider or model dimension. So this adds the missing ledger and a view over it.

Store

New persisted map, pruned by the same 90-day retention as spendByDay:

usageByDay { "YYYY-MM-DD": { provider: { model: { costUsd, inputTokens, outputTokens, turns } } } }

store.recordUsage() is called at the five places that already record usage — the claude, codex, kimi and opencode run paths in electron/runner.js plus the workflow agent roll-up in electron/workflow.js. It records per-turn deltas keyed on tokens, not on cost: recordSpend skips when costDelta <= 0, and reusing that gate would have made every subscription provider invisible, which is exactly the case the issue is about. spendByDay, recordSpend and the budget meter are untouched.

Wire

usage:byDay handler reading the store directly (same shape as activity:list), preload channel, CoderApi.usage.byDay(), plus the wireClient / devCoder / fakeCoder mirrors so the web build and the renderer tests stay in parity.

View

A Usage nav row next to Activity, rendering UsageView:

  • 7 / 30 / 90 day range toggle and a Cost / Tokens metric toggle
  • daily bar chart built from plain divs and CSS — no chart dependency added
  • provider breakdown with share bars, and a model table (cost, input, output, turns)
  • empty state, and correct behaviour when every cost is 0 and only tokens moved

Aggregation lives in pure src/usage.ts (summarizeUsage), which takes today as a parameter so the rollup is deterministic under test. Empty days inside the range are filled so the chart has no gaps.

Not built

The rolling-24h hourly chart (needs hourly buckets and its own retention policy) and cache savings (providers do not report cache hits uniformly). Both are additive on top of this ledger if the daily view proves them wanted.

Verification

  • npm run typecheck and npm run build clean
  • renderer suite: 755 pass, 0 fail
  • electron suite: 883 pass, 1 fail — wireClient × webBridge over a real socket > reconnect asserts a 1s production backoff and gets 120000; it fails identically on main and is unrelated to this change
  • new tests: store accumulation/zero-cost/prune/malformed-input in electron/test/budget-spend.test.js, aggregation in test/usage.test.ts, component in test/usageView.test.tsx, and an appWiring test pinning the Usage nav to the usage.byDay channel

Built by two parallel workers on isolated worktrees (store + IPC, and aggregation + view), merged and wired here.

  • PR created by the Claude Code agent

Willem and others added 5 commits August 17, 2026 14:35
Record turn deltas in usageByDay and expose them read-only over usage:byDay.
Pure summarizeUsage rollup plus UsageView with 7/30/90-day and cost/token toggles. Not wired into App or the sidebar.
…into coder/usage-and-cost-analytics-view-per-provid-52e120

# Conflicts:
#	src/shared/ipc.ts
Adds the Usage nav row, the "usage" AppView route and the appWiring test
that pins the nav to the usage.byDay channel. Drops the services.js
pass-through so the handler reads the store directly, like activity:list.

Closes #152

Co-Authored-By: Claude Opus 5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit a626996 into main Aug 17, 2026
1 check failed
@currentbits
currentbits deleted the coder/usage-and-cost-analytics-view-per-provid-52e120 branch October 3, 2026 16:07
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.

Usage and cost analytics view (per provider/model, 7/30/90-day ranges)

1 participant