fix(claude): map monthly account spending limits#19433
Claude Enterprise accounts with monthly spending budgets can return no rolling quotas, leaving the usage panel empty. This maps an enabled account budget into the existing monthly percentage window, preferring compatible spend amounts and falling back to enabled extra_usage amounts or utilization. The captured 4631/50000 budget becomes 9.262%, rather than the rounded provider value of 9%. Existing rolling and model windows remain additive; disabled and invalid budgets are omitted. Pro/Max accounts with enabled extra usage also receive this monthly window alongside their rolling quotas.
Scope and approval: the percentage-only mapping was accepted in #10155. Monetary UI and contract fields are outside this change. Thanks to @Exotic209093 for the original implementation in #19433; their commits are preserved, with main merged and the mapper/tests rebuilt on top.
Verification on Linux / Node 24:
- Focused suite: 16 → 10 tests, preserving all seven main tests and replacing nine PR cases with three behavior tests. Two positive regressions fail on main (8 pass / 2 fail); all 10 pass on this head.
- Scoped server typecheck and targeted lint/format pass.
- Actual main/head mapper replay of the sanitized Claude CLI 2.1.261 Enterprise capture:
windows: []→ onemonthly_spendwindow at 9.262%. Derived fallback, disabled-budget, and additive rolling-quota inputs also pass the existing wire schema after JSON serialization. Before/after replay output. - Independent whole-PR reviews: one fresh round with Claude Opus 5.5 and GPT-6-Sol; neither found a code blocker. Both reran the focused suite (10/10).
This changes mapping, with no visual component or contract changes, so proof is the before/after payload output. No fresh Enterprise account was available: the source capture is real, but replay does not establish current live-provider behavior. Browser rendering, macOS, Windows, iOS, Android, and Electron desktop were not verified in this takeover.
Tests: GPT-6-Astra; implementation: GPT-6.1-Sol; independent reviews: Claude Opus 5.5 and GPT-6-Sol, through T3 Code with the Codex and Claude Code harnesses.
Checks
Added 1 commit
- fix(claude): map monthly account spending limits9775623
Approvability
Verdict: Approved at 9775623
Macroscope's review found this PR approvable — This is a focused Claude usage-mapping fix that adds a validated monthly spend bar using the existing usage-window contract while preserving current session and weekly behavior. The production impact is localized to the existing usage probe and is covered by targeted tests.
You can add or adjust custom eligibility rules. Learn more.
Warning
Review limit reached
Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.
Next included review available in 11 minutes.
View limit details
Limit details: You’ve used all 10 included reviews currently available.
Review configuration:
⚙️ Run configuration
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
ccc3efd7-0ff7-411b-8216-2ea84b90f216
📥 Commits
Reviewing files that changed from the base of the PR and between 9775623a679130d12b1f9d2a7bfd412244e15918 and 139cfa4e847bf6c2e6a5932c66a26126efadd9ef.
📒 Files selected for processing: 2
apps/server/src/provider/claudeUsageLimits.test.tsapps/server/src/provider/claudeUsageLimits.ts
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
0c8dd139-5ab6-4407-9e41-f7d2eca5eac2
📥 Commits
Reviewing files that changed from the base of the PR and between 8414d168191599dec08588080d0b77506c849424 and 9775623a679130d12b1f9d2a7bfd412244e15918.
📒 Files selected for processing: 2
apps/server/src/provider/claudeUsageLimits.test.tsapps/server/src/provider/claudeUsageLimits.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
📝 Walkthrough
The Claude usage mapper now adds a monthly spend window when valid spend or extra-usage data provides a percentage. Tests cover data selection, percentage calculation, clamping, and invalid input.
Changes: Claude monthly spend window
Layer / File(s) Summary Decode and map monthly spend
apps/server/src/provider/claudeUsageLimits.ts,apps/server/src/provider/claudeUsageLimits.test.tsThe mapper validates spend and extra-usage data, prefers eligible spend data, and falls back to extra usage. It adds a monthly spend window when a valid percentage is available. Tests cover precedence, fallback, clamping, and invalid values. Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~15 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to 97756
No actionable merge-blocking risk is established for the monthly spend mapping. Merge after normal checks.
Security architecture risk: ⚪ Minimal · up to 97756
The change adds validated monthly usage reporting without changing account permissions, spending authority, or privileged operations. No material security risk introduced or worsened by this change was identified.
Retained concerns No architecture-level concerns identified.
Security review details
Security Blast Radius
- inferred — The newly interpreted data affects usage reporting for the account already queried by the configured Claude provider. The inspected path adds no account selector, credential access, cross-account operation, or broader execution authority.
Security Findings and Attack Paths
- inferred — Provider-controlled percentages can influence reported remaining usage and pacing, but the inspected consumers do not turn them into authorization or spending authority. The strongest privileged counterexample, reset-credit redemption, uses resetCredits.nextCreditId and remains independent of monthly-window percentages.
Trust Boundaries and Controls
- observed — Untyped spend fields are schema-decoded before use. Spend ratios require an enabled budget, nonnegative integer amounts, matching trimmed currencies and exponents, a positive limit, and finite arithmetic. Enabled extra usage is the fallback. Accepted percentages are clamped to the existing zero-to-100 range.
Pre-merge checks: Passed 4
Check name Status Explanation 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. Title check Passed The title clearly and concisely describes the main change: mapping monthly Claude account spending limits. Description check Passed The description provides the problem, implementation details, scope approval, verification results, limitations, and test attribution. It does not use the template's Problem, Change, or Verification h… Full details: Description check
Explanation
The description provides the problem, implementation details, scope approval, verification results, limitations, and test attribution. It does not use the template's Problem, Change, or Verification headings, but the required information is present and sufficiently detailed.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create a new PR
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
Taking over this one as maintainer for batch claude-07. I will preserve the original branch and author commits, rebuild the mapper and focused tests, and run independent reviews. The scope is the existing monthly percentage window; undocumented payload handling and the lack of a real Enterprise account will be stated explicitly. This will remain unmerged.
Added 2 commits
Takeover validation is complete on 15e58df548, preserving the original author history. Current-head lint, build/typecheck, all eight server shards, aggregate tests and Check passed; scope-filtered jobs skipped normally. A duplicate native fingerprint run was cancelled, and the same workflow succeeded on this exact head after that cancellation.
The focused suite is now 10 tests (previously 16), with all seven main tests preserved. Fresh independent whole-PR reviews by Claude Opus 5.5 and GPT-6-Sol found no code blockers. Existing bot code reviews cover the old contributor head; no current-head bot approval is claimed. All review-thread pages are empty, and there is no active change request.
The body includes captured-payload main/head replay and the existing JSON wire-contract proof. A fresh Enterprise account and native/client rendering remain unverified. This remains unmerged.
I have a Claude Enterprise account with monthly limits and can confirm this change works for me. On the stable release I get the error Claude: No limits reported.. I built this pr locally and saw the bar
I also double checked this is consistent with my actual current usage for the month which is reported as 15% used on my Claude Usage page.
Added 1 commit
- Merge remote-tracking branch 'origin/main' into fix/claude-monthly-spend-window139cfa4