Skip to content

feat: show each thread's session cost in the context meter - #2

Open
n0ah37 wants to merge 5 commits into
mainfrom
feat/context-meter-session-cost
Open

n0ah37 wants to merge 5 commits into
mainfrom
feat/context-meter-session-cost

Conversation

@n0ah37

@n0ah37 n0ah37 commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

The context meter has a cost row, but no provider fills it on the live path, so users never see what a thread has cost. Requested in Ideas discussion pingdotgg#18050 (originally issue pingdotgg#17818).

Change

Each provider turn can now carry costUsd, the provider's own USD estimate for that turn. The meter's popover adds them up into Session cost.

  • Contract. OrchestrationV2ProviderTurn.costUsd, optional, finite and non-negative. The server's upsertProviderTurn and the client projection's provider-turn.updated reducer keep it when a later update omits it, as they already do for tokenUsage.
  • Claude. total_cost_usd on a result is the process's running total, not the turn's. The adapter keeps the total already attributed per CLI process and charges each turn the growth (claudeTurnCostUsd). Growth from wake turns with no T3 turn carries into the next turn; a zeroed or unchanged total (crash or replayed results) is ignored; a smaller total means /clear restarted the count.
  • OpenCode 2. Sums cost from session.step.ended / session.step.failed.
  • OpenCode 1.x. Sums cost from step-finish parts. Recorded 1.x transcripts can omit cost despite the SDK type, so one unpriced step leaves the turn unpriced rather than reporting a partial figure.
  • ACP agents that already report cumulative cost through contextUsage.cost keep showing it. The live-usage path now passes that cost through too, where it used to hard-code null.
  • Everything else (Codex, Cursor, Grok, Antigravity, Muse, Pi) reports no cost on the turn. Once a turn has finished, the row reads Unpriced instead of hiding or showing $0.
  • Mixed threads. Turns recorded before this change, or by providers that report no cost, are counted, so a partial sum reads USD 0.42 + 3 unpriced turns rather than passing for the whole session.
  • Web. withThreadCost puts the sum on the meter's snapshot. Mobile has no context meter.
  • Docs. One paragraph in docs/user/composer.md.

Not included: pricing unpriced providers from the LiteLLM rate table that the Usage page uses. That would need per-turn model and cache-write data that the live turn does not carry, so it is left for a separate change.

Verification

  • vp test run on the orchestrator and Claude replay fixtures, provider-opencode adapter tests, ClaudeTurnCost.test.ts, contextWindow.test.ts, ProviderTurnTokenUsage.test.ts and orchestrationV2Projection.test.ts: 214 passed. The multi_turn/claudeAgent replay now asserts each turn's cost from the recorded running totals (0.01171425, then 0.0154371 − 0.01171425). This includes the existing OpenCode 1.x simple replay, which caught the missing-cost case. The opencode2_simple replay now asserts the turn's cost (a free model, so 0).
  • vp test run apps/server/src/orchestration-v2/testkit/ClaudeReplayFixtures.integration.test.ts apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts: passed.
  • typecheck passes for contracts, client-runtime, provider-opencode, server and web.
  • Not yet done: before/after screenshots from a running client. The popover's only visual change is the new row.

Built with Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

@n0ah37
n0ah37 force-pushed the feat/context-meter-session-cost branch from acf2bf3 to 7af2498 Compare October 11, 2026 10:04
@n0ah37
n0ah37 force-pushed the feat/context-meter-session-cost branch from c354413 to 27a9fe0 Compare October 11, 2026 12:19
Claude carries a resumed session's earlier cost into the new process's
running total, so counting each process from zero charged that history
twice. The provider thread now keeps the last total and a resumed
process counts from it. A turn stopped before any usage report no longer
reads as unpriced, since the next turn's report includes it, and dollars
read as Claude Code's /usage prints them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XXL labels Oct 11, 2026
@github-actions

Copy link
Copy Markdown

Thread transfer impact

⚠️ The latest CI run did not produce a thread transfer result for 8f7ca4f.

This comment will update automatically after the next completed run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants