Skip to content

fix(usage): Claude monthly spend shows pace and a reset countdown - #34162

Open
jtatum wants to merge 1 commit into
pingdotgg:mainfrom
jtatum:fix/claude-monthly-spend-pace
Open

jtatum wants to merge 1 commit into
pingdotgg:mainfrom
jtatum:fix/claude-monthly-spend-pace

Conversation

@jtatum

@jtatum jtatum commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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_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
Before: Monthly spend shows only 85% left After: Monthly spend shows the pace icon, the even-spend marker and the reset countdown

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).

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T18:32:10.894005Z 912c6ce New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 11, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at f34d322

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.

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested labels: bugfix

Suggested reviewers: juliusmarminge, maria-rcks

Merge Risk: Minimal · previous review 54ea7

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed 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
Recent review info

Run configuration

Commits

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.

@binjamshid binjamshid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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:

  1. (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.
  2. (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.

@jtatum

jtatum commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

(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.

Also rebased onto current main.

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>
@jtatum
jtatum force-pushed the fix/claude-monthly-spend-pace branch from 54ea73f to 912c6ce Compare November 19, 2026 18:29

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants