ccstatusline
ccstatusline copied to clipboard
feat: total session tokens including sub-agents
Summary
Adds subagent-inclusive session token accounting. The existing token widgets count only the main agent — tokens spent by Task-tool sub-agents are invisible. This wires sub-agent usage into token counting, reusing the same sub-agent transcript discovery that already backs the speed-metrics widgets.
Two surfaces (opt-in, zero change for existing setups):
(s)ubagentstoggle on the existing Tokens Input / Output / Cached / Total widgets. When on, that widget's number includes sub-agents, shows aΣmarker, and a[+sub]modifier in the editor.- New
Session Total Tokenswidget (tokens-session-total) — session grand total including sub-agents, with an optional(b)reakdownof input/output/cache:Σ Total: 152k (in 90k/out 40k/cache 22k).
How it works
getTokenMetrics(path, { includeSubagents })sums referencedsubagents/agent-*.jsonlfiles via the existinggetReferencedSubagentIds→getSubagentTranscriptPathsdiscovery.- Default behavior is byte-identical — the option defaults off; existing
widgets and the stdin
context_windowpath are unchanged. - Double-count guard: when separate sub-agent files exist, inline
isSidechainrows are dropped from the main pass (they're represented by the files); when no files exist (older transcript format), inline sidechain rows are still counted.contextLengthremains a main-chain-only concept. - The subagent-inclusive figure is computed once per render, on demand — only
when a session-total widget or a subagents-enabled token widget is configured
(
RenderContext.sessionTokenMetrics). No extra file I/O otherwise.
Testing
- New unit tests: data layer (incl. double-count guard, multi/unreferenced
sub-agents, back-compat lock), the metadata helper, the four widget toggles, and
the new widget. 49 tests pass including the pre-existing
TokensWidgetssuite (no regression). tsc --noEmitandeslintclean across the project;bun run buildsucceeds; example-payload smoke render verified.
🤖 Generated with Claude Code