Commit ab1ea43
fix: accurate Live session cost (rate + whole-transcript) — v2.6.16
Two compounding inaccuracies made the Live "$ spent" wrong:
1. Pricing bug: opus-4-7 / opus-4-8 matched the 4.0/4.1 legacy regex
(/opus-4(?:-[01])?\b/ — the \b also matches "opus-4-7"), so they were
charged $15/$75 instead of the current $5/$25 — a 3× overcharge across ALL
cost calcs. Broaden the reduced-rate row to /opus-4-(?:[5-9]|[1-9]\d)/ so
4.5+ (incl. two-digit minors) get current rates; legacy stays 4.0/4.1 only.
2. The Live estimate summed tokens from only the last 1MB of the JSONL and
applied a single blended 0.1× rate — undercounting large sessions and
mis-blending cache-creation vs cache-read, and the message count was
tail-only too (e.g. 188 shown vs 915 actual). Replace it with computeCost()
over the whole transcript using per-type rates, cached by file mtime+size so
unchanged sessions aren't re-read on each 3s refresh.
Verified live: a session independently calculated at ~$79.66 now reports
$80.08 (was $101.91); message counts are now full-transcript accurate.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 11dc8d8 commit ab1ea43
5 files changed
Lines changed: 70 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
151 | 195 | | |
152 | 196 | | |
153 | 197 | | |
| |||
250 | 294 | | |
251 | 295 | | |
252 | 296 | | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
260 | 301 | | |
261 | 302 | | |
262 | 303 | | |
| |||
277 | 318 | | |
278 | 319 | | |
279 | 320 | | |
280 | | - | |
| 321 | + | |
281 | 322 | | |
282 | | - | |
| 323 | + | |
283 | 324 | | |
284 | 325 | | |
285 | 326 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
19 | 31 | | |
20 | 32 | | |
21 | 33 | | |
| |||
0 commit comments