feat(dashboard): surface cumulative token totals in StatsBar#365
Open
ninadgns wants to merge 1 commit into
Open
feat(dashboard): surface cumulative token totals in StatsBar#365ninadgns wants to merge 1 commit into
ninadgns wants to merge 1 commit into
Conversation
The agent already streams the full usage breakdown to the browser — the `usage` audit event carries total_input_tokens, total_output_tokens, cache_creation_input_tokens and cache_read_input_tokens alongside context_tokens. computeLiveStats read only context_tokens and total_cost_usd and dropped the four cumulative counters on the floor, so the only token number in the UI was `Context`. `Context` is a snapshot of the last message's window and moves both up and down, which makes it easy to misread as overall usage. Add a `Tokens` stat next to it showing the sum of all four counters, with a hover breakdown naming each component. Render-only: no backend, DB, or event-shape changes. Follows the existing live-then-settled fallback and renders `—` rather than `0` when no usage was ever reported, so a broken pipeline stays visible. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The StatsBar shows
Context, which reads like overall token usage but isn't.context_tokensis a snapshot of the last message's window (input + cache_creation + cache_readof that one message,stream.py:412) — it moves up and down as the conversation compacts, so it can't be a total. Sitting next to a settledCostfigure, it invites exactly the wrong reading.Meanwhile the four cumulative counters are already streamed to the browser. The
usageaudit event carries the full breakdown:computeLiveStatsreceived that whole object and read two fields, discarding the rest. There was no way to see overall usage in the UI at all — you had to query the audit endpoint or Postgres directly.Change
Add a
Tokensstat showing the sum of all four counters, with a hover breakdown (Input 1.5k · Output 2.0M · Cache write 0 · Cache read 300) naming each component.Contextstays as-is — it's a genuinely useful and different signal.Render-only. No backend, DB, or event-shape changes; the data was already client-side.
Notes
formatContextStat.—rather than0when nothing was ever reported, per the repo's fail-fast rule that distinct failure modes must render distinctly — a pipeline that never emitted usage must not look like a free run.total_output_tokensincludes thinking tokens; the breakdown label stays generic rather than implying otherwise.Testing
pnpm exec vitest run— 95 files, 719 tests pass (6 new)pnpm exec tsc --noEmit— cleanPython checks (
pyright,ruff,pytest) were not run: this change touches no Python.🤖 Generated with Claude Code