Repository navigation
Report each run's API token usage and estimated cost - #168
Merged
Merged
Conversation
Planner, judge and repair calls are collected per run in memory (src/usage.ts, AsyncLocalStorage around dispatch) and written to report.json as `cost`, shown in the HTML report, the CLI's closing summary and the dispatch trace, and returned by the MCP tool with the report. Priced like scripts/cost.sh: list rates from src/models.ts, repair at the Agent SDK's own total_cost_usd. README, the report design doc, the plugin guide and the generate-app skill describe the new block; the skill quotes it in its headline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016UPsTupJqJ5X1NK2gZEN5c
Merged
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.
Closes #167.
Each run now reports what it cost, instead of leaving the user to filter
tmp/trace/by timestamp.What changed
src/usage.ts: a per-run ledger (AsyncLocalStoragearounddispatch(), so concurrent MCP calls and the smoke tests' many dispatches don't mix). The planner and each judge call record theirusage; the repair agent records the Agent SDK'stotal_cost_usd. Priced exactly likescripts/cost.sh(list rates fromOPUS_PRICE_PER_MTOK; calls served by a refusal-fallback model are counted infallbackCallsand priced at the same rates).report.jsongets acostblock (estimatedUsd,calls,byAgent.{planner,judge,repair}with tokens and USD,pricing). Absent when the run made no API call (stub mode).cost: ≈ $0.2197 (25 API calls: planner $0.0273, judge $0.1924)after theoverall:line; the same line goes totmp/trace/dispatch.log.reportinstructuredContent, no extra field.--testsadds ~2.5 min and no API cost since the suites run in parallel),docs/validation-report.md(section + data model),docs/PLUGIN-GUIDE.md, and the generate-app skill (report shape; quotes the cost in its headline).Tests (
npm test: 206 pass; build +typecheck:testsclean)cost; report/HTML/CLI line carry it.Run for real (local build,
--visual=0, barbershop spec):report.jsoncost= planner 2,722 in / 849 out = $0.0279, identical toscripts/cost.shon that run's trace; the CLI line and the HTML section show it. The judge path wasn't exercised live (no simulator booted at the time); it's the samerecordMessageUsagecall next to the existingusage:trace line.🤖 Generated with Claude Code
https://claude.ai/code/session_016UPsTupJqJ5X1NK2gZEN5c