Skip to content

feat: add cc.output_tokens trace-level aggregate for Sankey visualization#19

Merged
jverre merged 1 commit into
mainfrom
jacques/output-tokens-trace-level
Jun 9, 2026
Merged

feat: add cc.output_tokens trace-level aggregate for Sankey visualization#19
jverre merged 1 commit into
mainfrom
jacques/output-tokens-trace-level

Conversation

@jverre

@jverre jverre commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Details

Adds cc.output_tokens to the trace-level metadata, enabling the spend Sankey diagram to use sum(metadata.cc.output_tokens.by_category.*) directly without span-level aggregation.

Previously the output breakdown (thinking / assistant_text / builtin_tool_use / mcp_tool_use / skill_invocations) only existed on individual spans via cc.llm_call.attributed_output_tokens + cc.llm_call.block_kind. This is fine for span queries but blocks trace-level aggregations.

New field shape:
```json
"cc": {
"output_tokens": {
"summary": { "total_tokens": 1312 },
"by_category": {
"thinking": 364,
"assistant_text": 671,
"builtin_tool_use": 240,
"mcp_tool_use": 25,
"skill_invocations": 12
}
}
}
```

Classification rules:

  • thinkingContentType == "thinking"
  • assistant_textContentType == "text"
  • mcp_tool_useContentType == "tool_use" + name starts with mcp__
  • skill_invocationsContentType == "tool_use" + name == "Skill"
  • builtin_tool_use — all other tool_use blocks

total_tokens equals sum(by_category.*) and matches the LLM call's actual output_tokens via the existing attribution logic (DeduplicateUsage).

Change checklist

  • extractOutputTokensSnapshot added to extractors.go
  • Wired into domainSnapshotsFromEntries in main.go (reuses the already-computed parsedTurn slice, no double-parse)
  • TestDryRunOnTestThread domain list updated
  • Unit tests added: happy path + nil-on-empty guard

Issues

N/A

AI-WATERMARK

AI assisted

Testing

go test ./... passes.

Documentation

N/A — internal metadata field; consumers are the Sankey FE component.

…tion

Adds extractOutputTokensSnapshot which aggregates attributed output
tokens by category at the trace level, enabling the spend Sankey to use
sum(metadata.cc.output_tokens.by_category.*) directly without requiring
span-level aggregation.

Categories: thinking, assistant_text, builtin_tool_use, mcp_tool_use,
skill_invocations — classified by content type and tool name prefix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jverre jverre merged commit 01232ca into main Jun 9, 2026
1 check passed
@jverre jverre deleted the jacques/output-tokens-trace-level branch June 12, 2026 21:15
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