Skip to content

Commit 54ea73f

Browse files
jtatumclaude
andcommitted
fix(usage): Claude monthly spend shows pace and a reset countdown
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>
1 parent 21fe33c commit 54ea73f

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎apps/server/src/provider/claudeUsageLimits.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ describe("claudeUsageResponseToLimits", () => {
133133
kind: "monthly",
134134
label: "Monthly spend",
135135
usedPercent: expect.closeTo(9.262, 10),
136+
resetsAt: "2026-08-01T00:00:00.000Z",
137+
windowDurationMins: 31 * 24 * 60,
136138
};
137139

138140
it("maps the captured Enterprise budget precisely, preferring spend beside rolling windows", () => {
@@ -142,6 +144,20 @@ describe("claudeUsageResponseToLimits", () => {
142144
windows: [monthlyWindow],
143145
},
144146
);
147+
expect(
148+
claudeUsageResponseToLimits({
149+
checkedAt: "2027-12-31T23:59:00.000Z",
150+
response: enterpriseResponse,
151+
}).limits.windows,
152+
).toEqual([{ ...monthlyWindow, resetsAt: "2028-01-01T00:00:00.000Z" }]);
153+
expect(
154+
claudeUsageResponseToLimits({
155+
checkedAt: "2028-02-10T08:00:00.000Z",
156+
response: enterpriseResponse,
157+
}).limits.windows,
158+
).toEqual([
159+
{ ...monthlyWindow, resetsAt: "2028-03-01T00:00:00.000Z", windowDurationMins: 29 * 24 * 60 },
160+
]);
145161
const response = {
146162
...enterpriseResponse,
147163
rate_limits: {

‎apps/server/src/provider/claudeUsageLimits.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ function isoFromString(value: string | null | undefined): string | undefined {
149149
return Option.isSome(dt) ? DateTime.formatIso(dt.value) : undefined;
150150
}
151151

152+
// get_usage omits the spend reset; Anthropic documents it as 00:00 UTC on the 1st of each month.
153+
function calendarMonthWindow(checkedAt: string) {
154+
const at = DateTime.make(checkedAt);
155+
if (Option.isNone(at)) return {};
156+
const start = DateTime.startOf(at.value, "month");
157+
const end = DateTime.add(start, { months: 1 });
158+
return {
159+
resetsAt: DateTime.formatIso(end),
160+
windowDurationMins: (DateTime.toEpochMillis(end) - DateTime.toEpochMillis(start)) / 60_000,
161+
};
162+
}
163+
152164
function makeWindow(
153165
id: keyof typeof WINDOWS & string,
154166
usedPercent: number,
@@ -221,6 +233,7 @@ export function claudeUsageResponseToLimits(input: {
221233
kind: "monthly",
222234
label: "Monthly spend",
223235
usedPercent: spendPercent,
236+
...calendarMonthWindow(checkedAt),
224237
});
225238
}
226239
return {

0 commit comments

Comments
 (0)