feat(tui): show session cost in tray status line - #919
Open
Xsidz wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds persistent session cost visibility to the interactive TUI tray/status line by plumbing SessionStats.cost into the connection snapshot/state and rendering it next to the existing token/context usage readout.
Changes:
- Extended
AgentConnectionStatewith optionalsessionCost?: number. - Populated and refreshed
sessionCostfromgetSessionStats().cost(on attach via snapshot, and after each completed turn via the existing context-usage refresh). - Rendered a cost label in the tray with sub-cent precision rules and documented the change in the coding-agent changelog.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/coding-agent/src/modes/interactive/interactive-mode.ts | Persists sessionCost during usage refresh and appends a formatted cost label to the tray context string. |
| packages/coding-agent/src/modes/agent-connection/types.ts | Adds sessionCost?: number to the connection state shape. |
| packages/coding-agent/src/modes/agent-connection/snapshot.ts | Populates sessionCost from session.getSessionStats() so it’s available immediately on attach. |
| packages/coding-agent/CHANGELOG.md | Adds an Unreleased entry documenting the new tray cost display. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Xsidz
commented
Aug 8, 2026
Xsidz
left a comment
Author
There was a problem hiding this comment.
Good catch — fixed in a82fb3ca. Replaced session.getContextUsage() with sessionStats.contextUsage since getSessionStats() already calls getContextUsage() internally.
Xsidz
force-pushed
the
fix/tui-session-cost
branch
2 times, most recently
from
August 11, 2026 17:35
40af471 to
bf1066b
Compare
added 3 commits
August 11, 2026 23:32
Populates session spend from getSessionStats().cost in the connection state snapshot so the TUI can render it in the tray. Part of fixes PrimeIntellect-ai#894
Renders accumulated session spend next to token/context usage, e.g. '128.4k (61%) · $1.32'. Sub-cent costs use 4 decimal places to avoid showing $0.00 for non-zero spend. fixes PrimeIntellect-ai#894
…ntextUsage() again getSessionStats() already calls getContextUsage() internally; reusing the result avoids the duplicate scan of session state.
Xsidz
force-pushed
the
fix/tui-session-cost
branch
from
August 11, 2026 18:05
bf1066b to
23d7315
Compare
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.
Summary
Shows accumulated session spend in the TUI tray/status line next to the existing token/context readout:
sessionCost?: numbertoAgentConnectionStateintypes.tssession.getSessionStats().costincreateAgentConnectionState(snapshot.ts) so cost is available immediately on attachrefreshConnectionContextUsagealongside the existingcontextUsagepatch (no extra RPC call —getSessionStatswas already called here and the result discarded)getTrayContextLabelwith sub-cent precision: 4 decimal places for cost < $0.01 (e.g.$0.0042), 2 decimal places otherwiseAll the plumbing already existed; this is a display-only change.
Test plan
npm run checkpasses (biome, tsgo, installer render, browser smoke)$0.00shown when cost is 0 (before first assistant turn)$0.0042)$1.32)sessionCostis populated (noundefinedrendered)Fixes #894
Note
Show session cost in TUI tray/status line alongside token/context readout
sessionCostfield toAgentConnectionStatein types.ts, populated fromsession.getSessionStats()in snapshot.ts.getTrayContextLabelin interactive-mode.ts to append a formatted cost string (e.g.$1.32) next to the context usage label, updated after each completed turn.formatSessionCosthelper: shows$0.00for zero, 4 decimal places below$0.01, otherwise 2 decimal places.Macroscope summarized 23d7315.