claude-code - 💡(How to fix) Fix total_cost_usd returns incorrect values (~10x too high) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#53371Fetched 2026-04-26 05:17:30
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1

Fix Action

Workaround

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

RAW_BUFFERClick to expand / collapse

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.

extent analysis

TL;DR

The total_cost_usd field in the result event of --output-format stream-json may be incorrectly calculated, resulting in values approximately 10x higher than expected, and a manual calculation based on token counts and Anthropic pricing should be used as a workaround.

Guidance

  • Verify the calculation of total_cost_usd by comparing it with the manual calculation based on token counts and Anthropic pricing for multiple jobs to confirm the discrepancy.
  • Check if the issue is specific to the claude-haiku-4-5-20251001 model or if it affects other models as well.
  • Consider reaching out to the Claude Code CLI support team to report the issue and request assistance in resolving the incorrect calculation.
  • Use the manual calculation as a temporary workaround to ensure accurate cost tracking and reporting.

Notes

The issue seems to be specific to the total_cost_usd field in the result event of --output-format stream-json, and the cause of the incorrect calculation is unknown.

Recommendation

Apply workaround: use the manual calculation based on token counts and Anthropic pricing to ensure accurate cost tracking and reporting, as the total_cost_usd field appears to be unreliable.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix total_cost_usd returns incorrect values (~10x too high) [1 comments, 2 participants]