Summary
Track per-agent token usage and cost by switching the Claude Code runner from --output-format text to --output-format json.
Available data
claude -p --output-format json returns:
total_cost_usd — total cost for the agent run
usage.input_tokens, usage.output_tokens, usage.cache_read_input_tokens
modelUsage — per-model breakdown
Implementation
- In
src/runners/claude-code.ts, change --output-format text to --output-format json
- Parse the JSON response to extract
result (the agent's text output) and cost/usage fields
- Add
costUsd, inputTokens, outputTokens to the AgentResult type in src/types.ts
- Store in run JSON so
thinktank stats can report aggregate cost data
- Display per-agent cost in the results table
Why
Users need to understand the cost of ensemble runs. Currently we estimate "$1-5 per run" in docs but have no actual tracking. This would let thinktank stats show real cost data.
Summary
Track per-agent token usage and cost by switching the Claude Code runner from
--output-format textto--output-format json.Available data
claude -p --output-format jsonreturns:total_cost_usd— total cost for the agent runusage.input_tokens,usage.output_tokens,usage.cache_read_input_tokensmodelUsage— per-model breakdownImplementation
src/runners/claude-code.ts, change--output-format textto--output-format jsonresult(the agent's text output) and cost/usage fieldscostUsd,inputTokens,outputTokensto theAgentResulttype insrc/types.tsthinktank statscan report aggregate cost dataWhy
Users need to understand the cost of ensemble runs. Currently we estimate "$1-5 per run" in docs but have no actual tracking. This would let
thinktank statsshow real cost data.