claude-usage-limits 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "usage-limits",
3
3
  "displayName": "Usage Limits",
4
- "version": "1.3.0",
4
+ "version": "1.4.0",
5
5
  "description": "Puts your remaining Claude Code usage limit into Claude's context before every prompt, so it opens with what fits in the budget instead of starting work that gets cut off. Reports headroom as turns rather than percentages, prices a job before you start it, and detects your plan tier.",
6
6
  "author": {
7
7
  "name": "Ridelink",
package/README.md CHANGED
@@ -428,6 +428,13 @@ Good enough to plan with, not a bill. The honest caveats:
428
428
  - A model released after this table was written is priced at its family's
429
429
  average rate, and the report marks those rows with an asterisk rather than
430
430
  passing the guess off as a published price.
431
+ - Time of day is not modelled. Anthropic used to shrink the five-hour limit
432
+ during peak hours, but removed that on 6 May 2026 for Pro and Max while
433
+ doubling the limits. If demand-based limits ever return, the numbers here
434
+ follow automatically, because they are calibrated from what your traffic did
435
+ to the meter rather than from an assumption about the clock.
436
+ - The turn cost behind "turns of headroom" is a median over at least five
437
+ turns, so one compaction cannot define your pace.
431
438
  - The cache only refreshes when Claude Code talks to the API, so after a gap it
432
439
  can be hours old and its 5-hour window long since rolled over. Dropping that
433
440
  window would hide the limit that actually stops short work, so it gets rebuilt
@@ -464,7 +471,7 @@ test/ node --test, no dependencies
464
471
  node --test
465
472
  ```
466
473
 
467
- 142 tests over the pricing, the window arithmetic, plan and credit detection,
474
+ 148 tests over the pricing, the window arithmetic, plan and credit detection,
468
475
  the status line, the before-prompt line, job forecasting, per-project
469
476
  attribution, the CLI, packaging, and the settings save/restore.
470
477
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-usage-limits",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Puts your remaining Claude Code usage limit into Claude's context before every prompt, so it opens with what fits in the budget instead of starting work that gets cut off. Reports headroom as turns rather than percentages, prices a job before you start it, and detects your plan tier.",
5
5
  "keywords": [
6
6
  "claude",
@@ -124,6 +124,26 @@ window that no longer exists. Those are marked stale, excluded from the
124
124
  binding choice, and never used for projections, because treating one as
125
125
  current would report an empty budget at the exact moment the budget came back.
126
126
 
127
+ **Time of day is not modelled, and does not need to be.** Anthropic used to
128
+ shrink the Claude Code five-hour limit during peak hours, so the same work cost
129
+ more of it in the afternoon. That ended on 6 May 2026, when the five-hour
130
+ limits were doubled and, in Anthropic's words, they removed "the peak hours
131
+ limit reduction on Claude Code for Pro and Max accounts". So there is no
132
+ peak-hour penalty to model today.
133
+
134
+ If one ever returns, nothing here needs changing. Every figure is calibrated
135
+ from what your own traffic actually did to the meter, so if a point of budget
136
+ starts costing more at four in the afternoon, the measured dollars-per-point
137
+ moves with it and the headroom follows. That is the advantage of measuring
138
+ rather than assuming: the tool does not need to know why a point got dearer.
139
+
140
+ **One turn is not a pace.** The turn cost behind "turns of headroom" is the
141
+ median of a sample, not the mean, and never from fewer than five turns. A
142
+ compaction or a large file read can cost ten times an ordinary turn, and one of
143
+ those landing in a thin sample once put a window that was 13 percent full at
144
+ nine turns remaining. Thin samples widen to the whole window, and then to
145
+ everything on record.
146
+
127
147
  **Pace is not a promise.** Turns left assumes the next turns look like the last
128
148
  hour's. A debugging spiral or a large file read breaks that assumption
129
149
  immediately. Re-run the report if the shape of the work changes.
@@ -355,6 +355,36 @@ function byModel(events) {
355
355
  return list;
356
356
  }
357
357
 
358
+ const MIN_PACE_SAMPLE = 5;
359
+
360
+ // The middle turn, not the mean, and never from a sample so small that one
361
+ // turn defines the pace. A compaction or a big file read can cost ten times an
362
+ // ordinary turn, and treating that as "the" turn cost sends the headroom
363
+ // estimate swinging: a single $7 turn once put a 13% full window at nine turns
364
+ // left. Too few recent turns to be sure, so widen to the whole window.
365
+ function typicalTurnCost(recentEvents, windowEvents, allEvents, minSample) {
366
+ const floor = Number.isFinite(minSample) ? minSample : MIN_PACE_SAMPLE;
367
+
368
+ // What a turn costs is a fact about how you work, not about which budget it
369
+ // is being measured against, so a thin window borrows from a wider sample
370
+ // rather than inventing a figure from two turns.
371
+ const tiers = [recentEvents, windowEvents, allEvents];
372
+ let pool = [];
373
+ for (const tier of tiers) {
374
+ if (tier && tier.length >= floor) {
375
+ pool = tier;
376
+ break;
377
+ }
378
+ if (tier && tier.length > pool.length) pool = tier;
379
+ }
380
+ const costs = pool
381
+ .map((event) => event.cost)
382
+ .filter((cost) => Number.isFinite(cost) && cost > 0)
383
+ .sort((a, b) => a - b);
384
+ if (!costs.length) return null;
385
+ return costs[Math.floor(costs.length / 2)];
386
+ }
387
+
358
388
  function dominantEffort(events) {
359
389
  const counts = new Map();
360
390
  for (const event of events) {
@@ -527,12 +557,11 @@ function buildWindow(spec, snapshot, events, now, options) {
527
557
  // The API reports whole numbers, so a low reading is a wide bracket.
528
558
  window.coarse = percent < 5;
529
559
 
530
- const perTurn = recent.turns
531
- ? recent.cost / recent.turns
532
- : spent.cost / Math.max(spent.turns, 1);
533
- window.percentPerTurn = perTurn / window.usdPerPercent;
560
+ const perTurn = typicalTurnCost(recentEvents, inWindow, events, MIN_PACE_SAMPLE);
561
+ window.percentPerTurn = perTurn === null ? null : perTurn / window.usdPerPercent;
562
+ window.typicalTurnUSD = perTurn;
534
563
  window.percentPerHour = window.recentUSDPerHour / window.usdPerPercent;
535
- if (window.percentPerTurn > 0) {
564
+ if (window.percentPerTurn !== null && window.percentPerTurn > 0) {
536
565
  window.turnsLeft = Math.floor(window.percentLeft / window.percentPerTurn);
537
566
  }
538
567
  if (window.percentPerHour > 0) {
@@ -1151,6 +1180,8 @@ module.exports = {
1151
1180
  buildWindows,
1152
1181
  bindingWindow,
1153
1182
  dominantEffort,
1183
+ typicalTurnCost,
1184
+ MIN_PACE_SAMPLE,
1154
1185
  formatDuration,
1155
1186
  formatUSD,
1156
1187
  formatCount,