Skip to content

Track token usage and cost per agent #166

@that-github-user

Description

@that-github-user

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

  1. In src/runners/claude-code.ts, change --output-format text to --output-format json
  2. Parse the JSON response to extract result (the agent's text output) and cost/usage fields
  3. Add costUsd, inputTokens, outputTokens to the AgentResult type in src/types.ts
  4. Store in run JSON so thinktank stats can report aggregate cost data
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions