feat(sessions): surface per-task cost estimate#3545
Merged
Conversation
The Claude Agent SDK already reports a per-turn `total_cost_usd`, which flowed into `ContextUsage.cost` but was never rendered. Sum it across turns (each result reports only its own spend, matching how per-turn token usage is already accumulated) and show the running total in the context usage indicator chip and breakdown popover. Codex sessions emit tokens without a cost, so `cost` stays null and the UI hides it. Generated-By: PostHog Code Task-Id: f6d673c3-965e-4598-a4bd-663f2651a5a5
|
😎 Merged successfully - details. |
Contributor
There was a problem hiding this comment.
This review was skipped because it would exceed your organization's monthly flex usage limit. Raise the limit in billing settings or wait until the next billing period resets limits.
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
Wrap the cost readout (indicator chip suffix and breakdown popover row) in a feature flag so it can roll out gradually. On in local dev via the import.meta.env.DEV fallback, matching the other UI flags. Generated-By: PostHog Code Task-Id: f6d673c3-965e-4598-a4bd-663f2651a5a5
tatoalo
approved these changes
Jul 17, 2026
Gating the cost readout behind useFeatureFlag made the component call useService(FEATURE_FLAGS), which throws in the test's provider-less render. Mock the hook (matching the pattern used across the UI test suite) and add a case covering the cost suffix when the flag is on. Generated-By: PostHog Code Task-Id: f6d673c3-965e-4598-a4bd-663f2651a5a5
Generated-By: PostHog Code Task-Id: f6d673c3-965e-4598-a4bd-663f2651a5a5
Member
Author
|
/trunk merge |
1 similar comment
Member
Author
|
/trunk merge |
Member
Author
|
/trunk merge |
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
Surfaces a per-task cost estimate in the session UI, gated behind a feature flag. The Claude Agent SDK already reports a per-turn
total_cost_usd, which flowed intoContextUsage.costbut was never rendered anywhere. This wires it through to the UI.resultmessage reports only that turn's spend, so the running session total is the sum — mirroring how the codebase already resets and re-accumulates per-turn token usage. Split cost out of the point-in-time context aggregate (used/sizestay a snapshot of the newest turn;costaccrues), in both the batch extractor and the streaming append-only tracker (kept equivalent).ContextUsageIndicatorchip shows· $X.XX, andContextBreakdownPopovergets an "Estimated cost" row.posthog-code-task-cost(TASK_COST_FLAG). On in local dev via theimport.meta.env.DEVfallback, matching the other UI flags. Until the flag is created/enabled in PostHog,isFeatureEnabledreturnsfalse, so the cost stays hidden in production.coststaysnulland the UI hides it regardless of the flag.Labeled "Estimated cost" since it's the SDK's own estimate. Background task-notification turns are excluded (they don't feed the ACP
usage_updatethat carries cost).Rollout
Create the
posthog-code-task-costflag in the PostHog project the desktop app reads flags from, then enable for the target cohort.Test plan
contextUsage.test.ts: added cases for single-turn cost, cross-turn summation, null-when-absent, append-only accumulation, and batch/tracker equivalence — 15 tests pass.@posthog/core+@posthog/uitypecheck clean; Biome lint clean on all changed files (zeronoRestrictedImports).Follow-up (not in this PR)
Phase 2 — a local per-model pricing table for a per-model cost breakdown and Codex coverage.
Created with PostHog Code