Skip to content

feat(chat): tokens per turn and per bot, never in money - #73

Merged
httpsphl merged 2 commits into
mainfrom
feat/token-usage
Sep 30, 2026
Merged

httpsphl merged 2 commits into
mainfrom
feat/token-usage

Conversation

@httpsphl

Copy link
Copy Markdown
Owner

What

  • Each turn item keeps tokens (input, cacheWrite, cacheRead, output) from the usage of Claude Code's result, which is the sum of that turn's requests. costUsd is gone.
  • The chat's turn line shows the tokens ("Done in 4.2 s · 2.5k tokens"); its title gives new read, written and reread.
  • New usage.tokens {since} sums turns per bot (archived bots included). The usage dialog gets a "Tokens by bot" part: today, 7 days, 30 days, all time, with the total.
  • The headline count is new input + cache written + output; the conversation reread from the cache is shown apart, as it weighs much less.
  • Migration 0011 adds a partial index for turn items by time.
  • Spec: new 8.7; 8.1, 8.2, 11.2, 12 and 19 updated.

Why no money

total_cost_usd is API list price and adds up the whole process, not the turn, so the old tooltip was wrong after the first turn; plan users do not pay it either.

Checked against real Claude Code (2.1.284)

A claude -p stream-json process with two turns, one using Read: result.usage is the sum of the turn's requests (input_tokens 18 = 10 + 8, cache_read_input_tokens 46703 = 21692 + 25011) and starts over each turn; modelUsage and total_cost_usd accumulate. Not verified: whether subagent tokens are in that usage (listed in spec 19).

Manual test

  1. Send a bot two messages, one after the other finishes.
  2. Each turn line shows its own token count; hover shows new, written and reread.
  3. Account menu > Usage > Tokens by bot: the bot shows both turns added up; switch periods.

Each turn item keeps the tokens of Claude Code's result usage (new input,
cache written, cache read, output), which is the sum of the turn's
requests. The chat shows them on the turn's line and usage.tokens sums
them per bot for a new part of the usage dialog, over today, 7 days,
30 days or all time.

The dollar cost is gone from the app: total_cost_usd is API pricing and
adds up the whole process, not the turn, so the tooltip was wrong after
the first turn. Spec 8.7 is new; 19 records the real test.
@httpsphl
httpsphl enabled auto-merge September 30, 2026 21:56
@httpsphl
httpsphl merged commit 9d5d4d6 into main Sep 30, 2026
3 checks passed
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