The best way to control Claude Code, Codex and more from any computer or phone
fix(server): show Codex Enterprise monthly credit limits (#14657)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
kamkm committed
Oct 19, 2026 at 23:25 UTC
4c18faf62cd1685b0243dcacc1a94e333c2b93ff
2 files changed
+83
apps/server/src/provider/codexUsageLimits.test.ts
+67
@@ -13,6 +13,34 @@ import {
13
const checkedAt = "2026-07-18T10:00:00.000Z";
14
15
describe("codexRateLimitsToLimits", () => {
16
+ it("shows an Enterprise monthly credit allowance in reads and notifications without a duration", () => {
17
+ const snapshot = {
18
+ limitId: "codex",
19
+ planType: "enterprise_cbp_usage_based",
20
+ primary: null,
21
+ secondary: null,
22
+ individualLimit: { remainingPercent: 99, resetsAt: 1_784_500_000 },
23
+ };
24
+ const windows = [
25
+ {
26
+ id: "individual",
27
+ kind: "monthly",
28
+ label: "Monthly credit limit",
29
+ usedPercent: 1,
30
+ resetsAt: "2026-07-19T22:26:40.000Z",
31
+ },
32
+ ];
33
+
34
+ expect(
35
+ codexRateLimitsToLimits({
36
+ checkedAt,
37
+ snapshot: { limitId: "spark" },
38
+ rateLimitsByLimitId: { codex: snapshot },
39
+ }),
40
+ ).toEqual({ checkedAt, windows });
41
+ expect(codexRateLimitsToUpdate(snapshot)).toEqual({ windows });
42
+ });
43
+
44
it("maps primary and secondary onto the session and weekly windows", () => {
45
expect(
46
codexRateLimitsToLimits({
@@ -66,6 +94,7 @@ describe("codexRateLimitsToLimits", () => {
94
it("selects the main Codex allowance and leaves Spark out", () => {
95
const spark = {
96
limitId: "codex_bengalfox",
97
+ individualLimit: { remainingPercent: 99, resetsAt: 1_784_500_000 },
98
primary: { usedPercent: 0, windowDurationMins: 300 },
99
secondary: { usedPercent: 90, windowDurationMins: 10080 },
100
};
@@ -105,6 +134,7 @@ describe("codexRateLimitsToLimits", () => {
134
checkedAt,
135
snapshot: {
136
limitId: "codex_bengalfox",
137
+ individualLimit: { remainingPercent: 99, resetsAt: 1_784_500_000 },
138
secondary: { usedPercent: 90 },
139
},
140
}).windows,
@@ -136,6 +166,7 @@ describe("codexRateLimitsToUpdate", () => {
166
expect(
167
codexRateLimitsToUpdate({
168
limitId: "codex_bengalfox",
169
+ individualLimit: { remainingPercent: 99, resetsAt: 1_784_500_000 },
170
primary: { usedPercent: 0, windowDurationMins: 300 },
171
secondary: { usedPercent: 90, windowDurationMins: 10080 },
172
}),
@@ -266,6 +297,41 @@ describe("codexUsageLimitMessage", () => {
297
});
298
299
describe("mergeCodexRateLimits", () => {
300
+ it("updates monthly credit usage, retains it when omitted, and clears an explicit null", () => {
301
+ const snapshot = {
302
+ limitId: "codex",
303
+ primary: { usedPercent: 12 },
304
+ individualLimit: { remainingPercent: 99, resetsAt: 1_784_500_000 },
305
+ };
306
+ const individualLimit = { remainingPercent: 75, resetsAt: 1_787_000_000 };
307
+ const changed = mergeCodexRateLimits(snapshot, { individualLimit });
308
+ expect(changed).toEqual({ ...snapshot, individualLimit });
309
+ expect(codexRateLimitsToUpdate(changed!)).toEqual({
310
+ windows: [
311
+ {
312
+ id: "primary",
313
+ kind: "session",
314
+ label: "Session",
315
+ usedPercent: 12,
316
+ windowDurationMins: 300,
317
+ },
318
+ {
319
+ id: "individual",
320
+ kind: "monthly",
321
+ label: "Monthly credit limit",
322
+ usedPercent: 25,
323
+ resetsAt: "2026-08-17T20:53:20.000Z",
324
+ },
325
+ ],
326
+ });
327
+
328
+ const retained = mergeCodexRateLimits(changed, { primary: null });
329
+ expect(retained).toEqual({ ...snapshot, primary: null, individualLimit });
330
+ const cleared = mergeCodexRateLimits(retained, { individualLimit: null });
331
+ expect(cleared).toEqual({ ...snapshot, primary: null, individualLimit: null });
332
+ expect(codexRateLimitsToLimits({ checkedAt, snapshot: cleared! }).windows).toEqual([]);
333
+ });
334
+
335
it("keeps windows an update does not carry", () => {
336
const merged = mergeCodexRateLimits(
337
{
@@ -292,6 +358,7 @@ describe("mergeCodexRateLimits", () => {
358
expect(
359
mergeCodexRateLimits(main, {
360
limitId: "spark",
361
+ individualLimit: { remainingPercent: 99, resetsAt: 1_784_500_000 },
362
primary: { usedPercent: 3, resetsAt: 1_800_000_000, windowDurationMins: 300 },
363
}),
364
).toBe(main);
apps/server/src/provider/codexUsageLimits.ts
+16
@@ -22,6 +22,10 @@ export interface CodexRateLimitSnapshot {
22
readonly rateLimitReachedType?: string | null;
23
readonly primary?: CodexRateLimitWindow | null;
24
readonly secondary?: CodexRateLimitWindow | null;
25
+ readonly individualLimit?: {
26
+ readonly remainingPercent: number;
27
+ readonly resetsAt: number;
28
+ } | null;
29
}
30
31
export interface CodexResetCreditsSummary {
@@ -84,6 +88,17 @@ function codexRateLimitsToWindows(
88
...(resetsAt ? { resetsAt } : {}),
89
});
90
}
91
+ const individualLimit = snapshot.individualLimit;
92
+ if (individualLimit && Number.isFinite(individualLimit.remainingPercent)) {
93
+ const resetsAt = isoFromEpochSeconds(individualLimit.resetsAt);
94
+ windows.push({
95
+ id: "individual",
96
+ kind: "monthly",
97
+ label: "Monthly credit limit",
98
+ usedPercent: clampPercent(100 - individualLimit.remainingPercent),
99
+ ...(resetsAt ? { resetsAt } : {}),
100
+ });
101
+ }
102
return windows;
103
}
104
@@ -166,6 +181,7 @@ export function mergeCodexRateLimits(
181
: {}),
182
...(update.primary !== undefined ? { primary: update.primary } : {}),
183
...(update.secondary !== undefined ? { secondary: update.secondary } : {}),
184
+ ...(update.individualLimit !== undefined ? { individualLimit: update.individualLimit } : {}),
185
};
186
}
187