feat(desktop): show token usage and estimated cost per agent session in the activity panel
NI
23d ago+915+915+012345678901234567890123456789-3-3-0123456789
What & why
The activity panel now shows how much each Claude Code terminal session is using: model, context window fill, input/output/cached tokens and an estimated cost. Each running or finished subagent row shows its own tokens and cost. Today the only way to see this is /cost inside the terminal, and subagents are not broken out at all.
- Host:
terminalAgents.sessionUsageandterminalAgents.subagentUsageread the transcript the binding (or the subagent roster) already recorded, on a host worker, reusingparseClaudeLogFileand the usage-history price table. Subagent reads only touch paths the roster recorded from the child's hook events. - Desktop: a "Session usage" group in
WorkspaceActivityMenu(SessionUsageRow, same meter as the chat composer'scontextWindow) and a usage line on subagent rows (SubagentUsageLabel). Both poll every 5s only while the panel is open. - Cost is labeled as an API-list-price estimate, not money spent. Only Claude records per-request usage in its transcript; other harnesses render nothing.
Review focus: logic in packages/host-service/src/terminal-agents/harness-sessions/usage.ts (context = latest request's prompt, totals summed per request, legacy 200K windows); the renderer is wiring.
How I tested it
bun test src/terminal-agents/harness-sessionsinpackages/host-service: 55 pass, including the newusage.test.ts(dedupe of streamed lines, exact cost, missing subagent file, non-Claude harness).- Dev app: opened a Claude Code session, sent two messages, and checked the panel's $0.59 against the transcript by hand (2 requests on
claude-opus-5-5, 1h cache writes): matches.
Checklist
- PR title follows conventional commits (
type(scope): subject) -
bun run lintandbun run typecheckpass (CI fails on lint warnings too) - "Allow edits from maintainers" is checked on fork PRs
- I have signed the CLA (the bot asks on your first PR)
Summary by cubic
Shows token usage and estimated cost per agent session in the activity panel, so Claude Code consumption is visible without running /cost in the terminal.
- Adds a "Session usage" group for each Claude session with model, context window fill, input/output/cached tokens, and estimated cost.
- Each subagent row gets its own token and cost line.
- Usage is read from the harness transcript the binding already records, on a host worker; non-Claude harnesses show nothing.
- Cost is labeled as an API-list-price estimate, not money spent, and rows poll every 5 seconds only while the panel is open.
Summary by CodeRabbit
- New Features
- Workspace activity now displays Claude session usage, including model, context-window usage, input/output/cached tokens, and estimated cost when available.
- Subagent activity can show token totals and estimated cost. Usage details update while activity is open.
- Usage labels are available in supported languages.
- Improvements
- Work rows can display an additional detail line beneath the work name.