Skip to content

feat(tui): show per-message input/output token counts#24434

Open
kunalkohli wants to merge 1 commit intoanomalyco:devfrom
kunalkohli:feat/per-message-token-display
Open

feat(tui): show per-message input/output token counts#24434
kunalkohli wants to merge 1 commit intoanomalyco:devfrom
kunalkohli:feat/per-message-token-display

Conversation

@kunalkohli
Copy link
Copy Markdown

Issue for this PR

Closes #24433
Relates to #13003, #17449, #17056

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds per-message input/output token counts to two places in the TUI:

1. The metadata footer under each assistant response

Before:

▣ Code · claude-opus-4 · 12.3s

After:

▣ Code · claude-opus-4 · 12.3s · 12.3K↓ 1.2K↑

Where ↓ = input tokens (including cache reads), ↑ = output tokens (including reasoning).

2. The sidebar context panel

Adds a new line showing last message's input/output breakdown:

Context
12,345 tokens
45% used
8,234↓ in · 4,111↑ out    ← NEW
$0.12 spent

Design decisions:

  • Input includes tokens.input + tokens.cache.read (total tokens sent to the model)
  • Output includes tokens.output + tokens.reasoning (total tokens generated by the model)
  • Only shown when the message has non-zero token data
  • Uses the existing Locale.number() formatter for compact K/M suffixes
  • Follows the existing theme.textMuted style for consistency

Files changed:

  • routes/session/index.tsx — add token display to the metadata footer
  • feature-plugins/sidebar/context.tsx — add input/output line to sidebar

How did you verify your code works?

  • bun run --filter opencode typecheck exits 0 (no type errors)
  • Reviewed the AssistantMessage type to confirm tokens.input, tokens.output, tokens.reasoning, tokens.cache.read are all number fields always present on the message
  • The Show guard ensures nothing renders for messages with no token data

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Add input/output token counts to two locations:

1. The per-message metadata footer (▣ line) after each assistant response,
   displayed as '12.3K↓ 1.2K↑' alongside mode, model, and duration.
2. The sidebar context panel, showing last message's input/output breakdown.

Input tokens include cache reads (input + cache.read).
Output tokens include reasoning (output + reasoning).
Only shown when the message has non-zero token data.

Closes anomalyco#24433
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.

[FEATURE]: Show per-message input/output token counts in TUI

1 participant