Conversation
Sums referenced subagent transcript files into token totals, reusing the existing subagent discovery (getReferencedSubagentIds/getSubagentTranscriptPaths) that already backs speed metrics. Default behavior is byte-identical; a double-count guard drops inline sidechain rows from the main pass only when separate subagent files are present. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
includeSubagents per-widget flag, the Σ marker constant, and a tokenMetricsForWidget selector (main-only vs session-inclusive metrics). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds RenderContext.sessionTokenMetrics and computes it once (includeSubagents) only when a session-total widget or a subagents-enabled token widget is present. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Tokens Input/Output/Cached/Total gain a (s)ubagents keybind that includes sub-agent usage, a [+sub] editor modifier, and a Σ render marker. Input/Output bypass the main-only stdin context_window payload when the toggle is on. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Dedicated tokens-session-total widget: session grand total including sub-agents, with an optional (b)reakdown of input/output/cache. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Merge ed087b6 is bad, compilation errors starting in src/utils/jsonl-metrics.ts:256 |
The `Merge branch 'main'` commit left several files in an inconsistent
state. This repairs them:
- jsonl-metrics.ts: getTokenMetrics had a corrupted body (duplicate
variable declarations plus leftover pre-refactor loop code referencing
out-of-scope symbols), causing TS1005 syntax errors. Rebuilt it to use
the sumUsage/getFinalizedUsageEntries/computeContextLength helpers and
to emit the hot/cold cacheReadTokens/cacheCreationTokens split that
main added and the cache-metrics widget depends on. sumUsage now tracks
that split too.
- jsonl-metrics.test.ts: added cacheReadTokens/cacheCreationTokens to the
three subagent-token assertions so they match the current shape.
- ccstatusline.ts: fixed import ordering (token-subagents after terminal).
- TokensInput/TokensOutput: the widgets still checked context_window
before tokenMetrics, contradicting the PR's own tests ("prefers
cumulative tokenMetrics for all token widgets"). Reordered so
tokenMetrics wins and context_window is the main-only fallback, and
dropped the now-redundant duplicate fallback branches.
tsc --noEmit and eslint are clean; the token/jsonl suites (37 tests) pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Fixed it in 0f89739. |
…oundary fix upstream/main added post-compaction-aware context length tracking (findLastCompactBoundary + the mostRecentPostCompactionEntry logic) to getTokenMetrics as an inline loop, independently of this branch's refactor of the same function into sumUsage/getFinalizedUsageEntries/ computeContextLength helpers for subagent-inclusive counting. Naively taking one side of the merge would have either dropped the compaction fix (stale context length after a compaction) or dropped subagent summing. Resolution: getFinalizedUsageEntries now returns entries paired with their original line index (IndexedTranscriptLine), threaded through sumUsage and a new computeContextLength(entries, boundary) that reimplements upstream's dual most-recent-entry tracking (overall vs. post-boundary) against the helper-based structure. Boundary detection is its own small helper, findLastCompactBoundary(lines), computed once in getTokenMetrics and passed to computeContextLength. Verified: tsc --noEmit clean, eslint clean (0 warnings), full test suite 1887/1888 pass (the one failure, usage-fetch.test.ts's proxy/cache test, is untouched by this diff, reproduces on 3/3 isolated reruns with a different expect() count each time, and matches the pre-existing sandboxed-process-spawn flakiness already documented on this repo's other open PR). bun run build succeeds. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Re-ports the subagent-inclusive token accounting onto upstream's rewritten transcript scanner. `getTokenMetrics()` and the array-based helpers this branch was built on are gone; the metrics now come from a single streaming pass over the transcript (`scanTranscript`), and the token widgets gained number formats and hideable zero states. - `jsonl-metrics.ts`: new `includeSubagentTokens` option adds `sessionTokenMetrics` to the analysis. Sub-agent transcripts are read once each and feed the token and speed collectors together, so nothing is parsed twice. Inline `isSidechain` usage is tracked in its own accumulator and subtracted from the session totals when separate sub-agent files exist - the old `skipMainSidechain` rule, in collector form. - `ccstatusline.ts`: the subagent-inclusive pass is requested only when a widget asks for it; `context.sessionTokenMetrics` is wired from it. - Token widgets: the `(s)ubagents` toggle, `Σ` marker and `[+sub]` modifier sit on top of upstream's `resolveNumberFormat` / zero-hideable rendering. The main-only `context_window` fallback is skipped when subagents are on. - `token-subagents.ts` and `SessionTotalTokens.ts` now use upstream's shared metadata helpers; `Session Total Tokens` gained number-format support and the zero-hideable state for parity with its category. Default behavior is unchanged: without the opt-in, no sub-agent file is read and every existing token number is byte-identical. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Rebuilt against current The conflicts weren't textual:
Default behavior is unchanged: without the opt-in, no sub-agent file is opened and every existing token number is identical. Verification, beyond CI:
One note for scheduling: #591 fixes a double-count in the same collector (one API response is logged once per content block, so every transcript-derived token number currently reads ~2x). The two are independent, but whichever lands second needs a trivial re-merge of 🤖 Generated with Claude Code |
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 / Totalwidgets. When on, that widget's number includes sub-agents, shows a
Σmarker,and a
[+sub]modifier in the editor.Session Total Tokenswidget (tokens-session-total) — session grandtotal 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.widgets and the stdin
context_windowpath are unchanged.isSidechainrows are dropped from the main pass (they're represented by thefiles); when no files exist (older transcript format), inline sidechain rows are
still counted.
contextLengthremains a main-chain-only concept.when a session-total widget or a subagents-enabled token widget is configured
(
RenderContext.sessionTokenMetrics). No extra file I/O otherwise.Testing
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