total_cost_usd returns incorrect values (~10x too high)

Resolved 💬 3 comments Opened Apr 25, 2026 by vbourdeix Closed Apr 29, 2026

Bug Description

The total_cost_usd field returned in the result event of --output-format stream-json returns values approximately 10x higher than expected, particularly noticeable with Haiku model.

Steps to Reproduce

  1. Run a Claude Code command with Haiku model using --output-format stream-json
  2. Parse the final result event
  3. Compare total_cost_usd with expected cost based on token counts and Anthropic pricing

Expected vs Actual

For a job with:

  • Model: claude-haiku-4-5-20251001
  • Input tokens: 18
  • Output tokens: 2,435
  • Cache creation tokens: 13,560
  • Cache read tokens: 69,460

Expected cost (based on Anthropic pricing):

  • Input: 18 × $0.80/1M = $0.000014
  • Output: 2,435 × $4/1M = $0.0097
  • Cache write: 13,560 × $1/1M = $0.0136
  • Cache read: 69,460 × $0.08/1M = $0.0056
  • Total: ~$0.03

Actual total_cost_usd returned: $3.67 (approximately 100x higher)

Aggregated over a day of jobs, we see ~$27 reported vs ~$2.60 calculated (~10x).

Environment

  • Claude Code CLI version: latest (April 2026)
  • Model: claude-haiku-4-5-20251001
  • Output format: stream-json

Impact

This causes cost tracking/reporting to show wildly inflated numbers, making it difficult to monitor actual API spend.

Workaround

We're currently calculating costs manually from token counts, ignoring the total_cost_usd field.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗