You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(usage): Claude monthly spend shows pace and a reset countdown - #34162
On Claude Enterprise, Usage > Limits shows the "Monthly spend" row as only "NN% left" and a bar. Unlike the Session and Weekly rows, it has no pace icon, no even-spend marker and no reset countdown. The Claude adapter builds the monthly_spend window without resetsAt or windowDurationMins, and the shared pace math (packages/shared/src/usageLimits.ts) needs both to work out how much of the window has passed. get_usage returns no reset date for the spend budget (also noted in #27344), so nothing ever sets them.
Change
claudeUsageResponseToLimits now sets both fields on monthly_spend, derived from the probe's checkedAt:
resetsAt: 00:00 UTC on the 1st of the next month
windowDurationMins: the length of the current UTC calendar month (handles 28–31 days, leap Februaries and year rollover via DateTime.startOf/add)
The boundary is the one Anthropic documents for spend limits: "monthly spend resets at 00:00 UTC on the first of each calendar month" (Spend Limits API). Claude Code's own /usage uses the same rule: it shows "Resets Nov 1", working out the 1st of the next month on the client because get_usage reports no reset date (noted in #27345). This matches how Session and Weekly already use fixed durations in the adapter. No contract, client or other provider changes are needed. The existing pace and countdown UI picks this up.
One side effect: a spent budget now counts as exhausted only until the 1st of the next month. Before, a stale 100% reading had no reset and blocked indefinitely.
Scope and approval
This is a very small, focused fix for an obvious bug. The monthly row is the only Claude limit window missing the two fields every other window carries, so the existing pace UI silently skips it. One function in one adapter changes, and nothing else moves.
Related, not overlapping: #30274 (same gap for OpenCode Go), #21896 / #21897 (pace for Grok and Cursor), #27344 / #27345 (dollar amounts on this same row).
Verification
Extended the existing Enterprise cases in claudeUsageLimits.test.ts. The expected monthly_spend window now includes resetsAt and windowDurationMins (July: 31 days). New assertions cover December → January rollover and a leap-year February (29 days). On main, the two monthly-spend tests fail on the missing fields; with the fix, all 8 pass.
vp run check:changed: format, lint, knip, typecheck and tests all pass.
Checked against a live Claude Enterprise account in a dev build (vp run dev, Usage > Limits), on 2026-11-11 at 04:30 UTC. Before and after are the same running data. Only claudeUsageLimits.ts was swapped between main and this branch, with a server restart in between.
Before: the row's label is "Claude: 85% left". No pace icon, marker or countdown.
After: the label is "Claude: 85% left, resets in 19d 19h, 66% of the window left". There's an under-pace icon and an even-spend marker at about the one-third mark. The countdown matches 00:00 UTC on Dec 1, and the pace is right because about 15% is spent and about 34% of November has passed. The Codex row next to it doesn't change.
Before
After
Caveat: some Anthropic help-center pages describe the org-wide cap on sales-assisted plans as resetting at the "next billing period". If an account's billing period doesn't line up with calendar months, pace would be off for that account. The API docs say monthly is the only supported period and that it resets on calendar-month boundaries. The Enterprise account used for the check above also resets on the calendar-month boundary.
Why infer it at all: on that Enterprise account, the full get_usage response has no reset or period field and no timestamps anywhere. The top-level limits array, which carries resets_at for weekly windows on subscription plans, is empty. The same row also covers Pro/Max usage credits with a monthly cap, through the spend/extra_usage fallback. Anthropic doesn't document when that cap resets, so this PR assumes the same calendar month there. That matches Claude Code: its /usage "Usage credits" section puts the reset at the 1st of next month for Pro, Max, Team and Enterprise alike (in local time, where this PR uses UTC per the API docs). A Max account with credits disabled returns spend.enabled: false and extra_usage.is_enabled: false, so no row is built and nothing changes for it.
Written by Claude Opus 5.5 in Claude Code (via T3 Code).
Macroscope's review found this PR approvable — Adds calendar-month timing to Claude monthly-spend reporting so it can show pace and a reset countdown. The change affects reporting only, not charges or spending-limit enforcement.
You can add or adjust custom eligibility rules. Learn more.
Reviewing files that changed from the base of the PR and between 54ea73f and 912c6ce.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
Claude monthly spend windows now include the next calendar-month reset timestamp and a duration based on that month’s length. Tests check reset dates and durations for December and February, including a leap year.
Changes: Claude monthly spend window
Layer / File(s)
Summary
Derive and verify monthly window apps/server/src/provider/claudeUsageLimits.ts, apps/server/src/provider/claudeUsageLimits.test.ts
A helper derives the next calendar-month boundary and duration from checkedAt. Monthly spend windows include these values when the date is valid. Tests check reset dates and durations, including February in a leap year.
The Claude monthly spend row now shows a reset countdown and pace indicator based on the UTC calendar month. The change is small and tested. The only remaining uncertainty is whether some account types reset at a different boundary, which would at worst show a slightly wrong countdown.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: Claude monthly spend now shows pace and a reset countdown. It matches the changeset, which sets resetsAt and windowDurationMins on the monthly_spend window. It follows…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description follows the repository template closely. It has a conventional-style title, a Problem section, a Change section, a Scope section that explains why no issue is linked and cites related …
Full details: Title check
Explanation
The title names the main change: Claude monthly spend now shows pace and a reset countdown. It matches the changeset, which sets resetsAt and windowDurationMins on the monthly_spend window. It follows the conventional commit form and uses plain language.
Full details: Description check
Explanation
The description follows the repository template closely. It has a conventional-style title, a Problem section, a Change section, a Scope section that explains why no issue is linked and cites related issues, and a Verification section with specific tests, a live-account check, before/after screenshots, and the model used. It is complete and specific, with only minor gaps. The Scope section does not link a tracking issue for the bug, but it explains the reasoning for skipping one, which the template allows for small obvious fixes.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Reviewing files that changed from the base of the PR and between f34d3229a4b8c29b8e9495333ecad8e592708f11 and 54ea73f.
Files selected for processing: 1
apps/server/src/provider/claudeUsageLimits.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Deriving resetsAt and windowDurationMins for monthly_spend from checkedAt addresses the missing pace marker and countdown: the shared pace code needs both fields and every other Claude window already has them. DateTime.make on the ISO checkedAt yields a UTC DateTime, so startOf("month") / add({ months: 1 }) give the documented 00:00 UTC boundary. The new assertions cover a 31-day month, the December to January rollover and a leap February.
No defects found. Notes:
(low) apps/server/src/provider/claudeUsageLimits.ts:223 — the side effect you describe is real and reaches beyond the Limits row. exhaustedUsageWindow (packages/shared/src/usageLimits.ts:34) now ends exhaustion at the inferred reset, and the new-thread model fallback in the same file carries window.resetsAt into fallback.resetsAt, so a guessed date can show up in that flow too. That seems right for calendar-month budgets. For Pro/Max usage credits, where the reset rule isn't documented, a wrong guess would show a misleading reset time instead of none. Leaving the inferred fields off the extra_usage fallback would avoid that, if the source is easy to tell apart in readSpendPercent.
(low) apps/server/src/provider/claudeUsageLimits.test.ts:147 — the rollover and leap-year checks are appended inside the existing "maps the captured Enterprise budget precisely" case. A separate it (or it.each) for the month-boundary cases would make a failure easier to read. Not required.
(1) Claude Code's own /usage makes the same inference for usage credits on every plan. Its "Usage credits" section handles Pro, Max, Team and Enterprise through one path, and it sets resets_at to the 1st of next month from extra_usage. Leaving the inferred fields off that branch would make T3 Code disagree with Claude Code for Pro/Max users. One difference: Claude Code uses local midnight, and this PR uses 00:00 UTC per the Spend Limits API docs. I added a line about this to the description.
(2) AGENTS.md asks to extend an existing case before adding a new it, so I left the boundary assertions where they are.
get_usage reports no reset date for the Enterprise spend budget, so the
monthly_spend window had no resetsAt or windowDurationMins and the Usage
page skipped pace. Anthropic documents that spend limits reset at 00:00 UTC
on the 1st of each calendar month, so derive both from the probe's
checkedAt.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size:S10-29 changed lines (additions + deletions).vouch:unvouchedAuthor is not yet trusted in the VOUCHED list.
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Claude Enterprise, Usage > Limits shows the "Monthly spend" row as only "NN% left" and a bar. Unlike the Session and Weekly rows, it has no pace icon, no even-spend marker and no reset countdown. The Claude adapter builds the
monthly_spendwindow withoutresetsAtorwindowDurationMins, and the shared pace math (packages/shared/src/usageLimits.ts) needs both to work out how much of the window has passed.get_usagereturns no reset date for the spend budget (also noted in #27344), so nothing ever sets them.Change
claudeUsageResponseToLimitsnow sets both fields onmonthly_spend, derived from the probe'scheckedAt:resetsAt: 00:00 UTC on the 1st of the next monthwindowDurationMins: the length of the current UTC calendar month (handles 28–31 days, leap Februaries and year rollover viaDateTime.startOf/add)The boundary is the one Anthropic documents for spend limits: "monthly spend resets at 00:00 UTC on the first of each calendar month" (Spend Limits API). Claude Code's own
/usageuses the same rule: it shows "Resets Nov 1", working out the 1st of the next month on the client becauseget_usagereports no reset date (noted in #27345). This matches how Session and Weekly already use fixed durations in the adapter. No contract, client or other provider changes are needed. The existing pace and countdown UI picks this up.One side effect: a spent budget now counts as exhausted only until the 1st of the next month. Before, a stale 100% reading had no reset and blocked indefinitely.
Scope and approval
This is a very small, focused fix for an obvious bug. The monthly row is the only Claude limit window missing the two fields every other window carries, so the existing pace UI silently skips it. One function in one adapter changes, and nothing else moves.
Related, not overlapping: #30274 (same gap for OpenCode Go), #21896 / #21897 (pace for Grok and Cursor), #27344 / #27345 (dollar amounts on this same row).
Verification
claudeUsageLimits.test.ts. The expectedmonthly_spendwindow now includesresetsAtandwindowDurationMins(July: 31 days). New assertions cover December → January rollover and a leap-year February (29 days). Onmain, the two monthly-spend tests fail on the missing fields; with the fix, all 8 pass.vp run check:changed: format, lint, knip, typecheck and tests all pass.vp run dev, Usage > Limits), on 2026-11-11 at 04:30 UTC. Before and after are the same running data. OnlyclaudeUsageLimits.tswas swapped betweenmainand this branch, with a server restart in between.Caveat: some Anthropic help-center pages describe the org-wide cap on sales-assisted plans as resetting at the "next billing period". If an account's billing period doesn't line up with calendar months, pace would be off for that account. The API docs say monthly is the only supported period and that it resets on calendar-month boundaries. The Enterprise account used for the check above also resets on the calendar-month boundary.
Why infer it at all: on that Enterprise account, the full
get_usageresponse has no reset or period field and no timestamps anywhere. The top-levellimitsarray, which carriesresets_atfor weekly windows on subscription plans, is empty. The same row also covers Pro/Max usage credits with a monthly cap, through thespend/extra_usagefallback. Anthropic doesn't document when that cap resets, so this PR assumes the same calendar month there. That matches Claude Code: its/usage"Usage credits" section puts the reset at the 1st of next month for Pro, Max, Team and Enterprise alike (in local time, where this PR uses UTC per the API docs). A Max account with credits disabled returnsspend.enabled: falseandextra_usage.is_enabled: false, so no row is built and nothing changes for it.Written by Claude Opus 5.5 in Claude Code (via T3 Code).
🤖 Generated with Claude Code