Commit bc1571f
fix: use first entry per message ID for correct output_tokens
Claude Code JSONL writes multiple entries per message (streaming chunks).
The FIRST entry contains the correct final usage from the API response.
Later entries are intermediate states with inflated cumulative output_tokens.
Previously we kept the entry with the highest output_tokens, causing output
to be ~9x higher than actual. Now we keep the first entry, matching ccusage
CLI's behavior (which also deduplicates by messageId:requestId, keeping first).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 1a3a119 commit bc1571f
2 files changed
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
332 | | - | |
333 | | - | |
334 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
264 | | - | |
265 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
266 | 267 | | |
267 | 268 | | |
268 | 269 | | |
| |||
0 commit comments