Repository navigation
feat(tui): compact turn token usage with expandable steps - #41922
Merged
Merged
Conversation
kitlangton
marked this pull request as ready for review
August 12, 2026 02:22
kitlangton
enabled auto-merge (squash)
August 12, 2026 02:22
This was referenced Sep 1, 2026
jinhuang712
pushed a commit
to jinhuang712/opencode
that referenced
this pull request
Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
debug.turn_tokensdiagnostic renders a per-turn "Tokens" table in the session transcript. With tool-heavy turns it prints one row per step and easily exceeds 30 rows per turn, even in non-verbose mode. This PR collapses that table into a single compact summary line by default and makes it click-to-expand.Before / After
Before: enabling
debug.turn_tokensrendered the full table for every completed turn — a header row plus one row per LLM step (Step / New / Cached / Total), unconditionally. A 30-step agentic turn produced 30+ transcript rows of diagnostics. The "Turn token usage (verbose)" checkbox in the DevTools Tools panel was always visible, even when the parent "Turn token usage" toggle was off, where toggling it had no visible effect.After: each turn renders one line:
+becomes-); clicking again collapses it· ! 2 likely cache busts), so the signal that matters is never hidden behind the foldNothing renders when the setting is off, exactly as before.
How
packages/tui/src/routes/session/index.tsx—TurnTokenUsagegainsexpanded/hoversignals. The header row follows the existing transcript idioms:+/-toggle prefix (as in the collapsed reasoning header), hover highlight, and arenderer.getSelection()guard so text selection doesn't toggle (as inInlineTool). The per-step table and cache-bust detail rows are unchanged, just wrapped in<Show when={expanded()}>. Asummarymemo derives the compact figures from the existingstepsmemo.packages/tui/src/component/devtools-bar.tsx— the "Turn token usage (verbose)"Actionis wrapped in<Show when={Boolean(turnTokens())}>, making it a visible refinement of the parent toggle rather than a peer.Scope
turn-usagerow reduction inrows.ts.Testing
bun typecheckinpackages/tui— clean.--devworktree): scripted a 4-step turn (3 tool calls + final text) with simulated OpenAI usage chunks, enabled the setting from the DevTools Tools panel, and verified compact line → click to expand (full Step/New/Cached/Total table) → click to collapse, plus the verbose checkbox appearing only after enabling the parent toggle.Demo
Recorded from the end-to-end run above (simulated model; real TUI):
turn-tokens-demo-v2.mp4