feat: complete reports tokens spent + saved (0.24.0)#42
Merged
Conversation
Each finalize now prints what it cost and what it compresses: complete tj-x: … | spent 1.5k tok ($0.0012) · saved ~88k→1.5k tok (59×) and a batch ends with a Totals line. Spent is exact, from the backend's own usage report (claude -p envelope usage/total_cost_usd, Anthropic/ OpenAI usage), summed across judge + any --enrich calls. Saved estimates memory compression: raw session transcript size vs compact pack (chars/4). Backends expose usage via a new LlmBackend::complete_usage method with a default that reports none, so mocks and custom backends are unchanged. claude-memory-642 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
completenow shows people what it costs and what it compresses, so the price/value is visible:claude -pJSON envelope'susage+total_cost_usd, Anthropic/OpenAIusage. Summed across the judge call and any--enrichcalls. Cost shown only when the backend reports a non-zero price (it's $0 under a subscription).~raw→pack tok (N×).Totals across N task(s):line.How
LlmUsage { input_tokens, output_tokens, cost_usd }and a newLlmBackend::complete_usagemethod with a default that reports no usage — so the three real backends opt in by parsing their usage, while mocks and any custom backend keep working unchanged (no signature break).finalize::judgereturns usage;LlmDreamBackendaccumulates usage across enrich chunks; the CLI sums judge + enrich intoFinalizeOutcomeand renders per-task + batch totals.Tests
fmt_tokensunit;stats_suffixspent/saved formatting + empty cases.claudeenvelope now carriesusage/total_cost_usd, and the test assertsspent 1.5k tok ($0.0012)appears.fmt --check,clippy --workspace --all-targets -D warnings,test --workspace, lean--no-default-featuresbuild.🤖 Generated with Claude Code