Skip to content

feat: show token counts in dashboard (ZYX-79)#3

Merged
mr-j90 merged 1 commit intomasterfrom
zyx-79
Mar 19, 2026
Merged

feat: show token counts in dashboard (ZYX-79)#3
mr-j90 merged 1 commit intomasterfrom
zyx-79

Conversation

@mr-j90
Copy link
Copy Markdown
Collaborator

@mr-j90 mr-j90 commented Mar 19, 2026

Summary

  • The Claude agent runner was creating CodexEvents without populating the Usage field, so token counts were always zero in the dashboard and API
  • Added extractClaudeUsage() to parse token data from the two shapes Claude's --output-format stream-json emits: top-level usage on result events and nested message.usage on assistant events
  • Wired extracted usage into the CodexEvent forwarded to the orchestrator, matching the existing behaviour in the Codex runner

Test plan

  • TestExtractClaudeUsage_ResultEvent — parses usage from result events
  • TestExtractClaudeUsage_AssistantEvent — parses usage from assistant events
  • TestExtractClaudeUsage_NoUsage — returns nil for events with no usage
  • TestExtractClaudeUsage_ZeroTokens — returns nil when both counts are zero
  • TestExtractClaudeUsage_InvalidJSON — returns nil for malformed input
  • TestExtractClaudeUsage_WithCacheTokens — ignores cache fields, sums input+output
  • TestDashboardShowsTokenCounts — verifies aggregate and per-session token counts appear in the dashboard HTML

Closes ZYX-79

🤖 Generated with Claude Code

The Claude agent runner was not populating the Usage field on CodexEvents,
so token counts were always zero in the dashboard and API.

Add extractClaudeUsage() to parse token data from both shapes Claude emits:
- result events: top-level "usage" field
- assistant events: nested "message.usage" field

Wire the extracted usage into the CodexEvent forwarded to the orchestrator,
matching the existing behaviour in the Codex runner.

Also add tests for extractClaudeUsage and dashboard token count rendering.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@linear
Copy link
Copy Markdown

linear Bot commented Mar 19, 2026

@mr-j90 mr-j90 merged commit 0928df5 into master Mar 19, 2026
8 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