@devries-cameron20 / t3code-1 / commits / d52ee1b237
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(usage): preserve Claude monthly spend through CLIProxy (#23435)

Aditya Garud committed Nov 1, 2026 at 07:35 UTC d52ee1b2376e7a700b073a2c0e7d21179a56ff19
2 files changed +83 -5
apps/server/src/usage/cliproxyApi.test.ts
+64
@@ -345,6 +345,70 @@ describe("CLIProxyAPI built-in management API", () => {
345 }),
346 );
347
348 + it.effect.each([
349 + {
350 + name: "spend budget",
351 + budget: {
352 + spend: {
353 + enabled: true,
354 + used: { amount_minor: 4_631, currency: "USD", exponent: 2 },
355 + limit: { amount_minor: 50_000, currency: "USD", exponent: 2 },
356 + },
357 + },
358 + },
359 + {
360 + name: "extra usage",
361 + budget: {
362 + extra_usage: {
363 + is_enabled: true,
364 + used_credits: 4_631,
365 + monthly_limit: 50_000,
366 + utilization: 9,
367 + },
368 + },
369 + },
370 + ])("keeps Claude monthly spend from $name beside rolling windows", ({ budget }) =>
371 + Effect.gen(function* () {
372 + const test = fixture({
373 + accounts: [{ ...accounts[0]!, provider: "claude" }],
374 + upstream: () => ({
375 + status: 200,
376 + body: { five_hour: { utilization: 10, resets_at: null }, ...budget },
377 + }),
378 + });
379 + const result = yield* (yield* test.api).readAccounts(config);
380 + expect(
381 + result[0]?.usageLimits.windows.map((window) => [window.id, window.usedPercent]),
382 + ).toEqual([
383 + ["five_hour", 10],
384 + ["monthly_spend", expect.closeTo(9.262, 10)],
385 + ]);
386 + }),
387 + );
388 +
389 + it.effect("omits disabled Claude budgets without losing rolling windows", () =>
390 + Effect.gen(function* () {
391 + const test = fixture({
392 + accounts: [{ ...accounts[0]!, provider: "claude" }],
393 + upstream: () => ({
394 + status: 200,
395 + body: {
396 + five_hour: { utilization: 10, resets_at: null },
397 + spend: { enabled: false, used: null, limit: null },
398 + extra_usage: {
399 + is_enabled: false,
400 + used_credits: null,
401 + monthly_limit: null,
402 + utilization: null,
403 + },
404 + },
405 + }),
406 + });
407 + const result = yield* (yield* test.api).readAccounts(config);
408 + expect(result[0]?.usageLimits.windows.map((window) => window.id)).toEqual(["five_hour"]);
409 + }),
410 + );
411 +
412 it.effect("pins redemption to the displayed credit and clears only that account's cooldown", () =>
413 Effect.gen(function* () {
414 const test = fixture();
apps/server/src/usage/cliproxyApi.ts
+19 -5
@@ -55,6 +55,17 @@ const ClaudeWindow = Schema.Struct({
55 const ClaudeUsage = Schema.Struct({
56 five_hour: Schema.optional(Schema.NullOr(ClaudeWindow)),
57 seven_day: Schema.optional(Schema.NullOr(ClaudeWindow)),
58 + spend: Schema.optional(Schema.Unknown),
59 + extra_usage: Schema.optional(
60 + Schema.NullOr(
61 + Schema.Struct({
62 + is_enabled: Schema.Boolean,
63 + monthly_limit: Schema.NullOr(Schema.Number),
64 + used_credits: Schema.NullOr(Schema.Number),
65 + utilization: Schema.NullOr(Schema.Number),
66 + }),
67 + ),
68 + ),
69 limits: Schema.optional(
70 Schema.Array(
71 Schema.Struct({
@@ -279,6 +290,13 @@ export const makeCliproxyApi = Effect.gen(function* () {
290 ]
291 : [],
292 );
293 + const rateLimits = {
294 + five_hour: usage.five_hour ?? null,
295 + seven_day: usage.seven_day ?? null,
296 + model_scoped,
297 + spend: usage.spend,
298 + extra_usage: usage.extra_usage ?? null,
299 + };
300 return {
301 ...base,
302 plan: "Claude Subscription",
@@ -286,11 +304,7 @@ export const makeCliproxyApi = Effect.gen(function* () {
304 checkedAt,
305 response: {
306 rate_limits_available: true,
289 - rate_limits: {
290 - five_hour: usage.five_hour ?? null,
291 - seven_day: usage.seven_day ?? null,
292 - model_scoped,
293 - },
307 + rate_limits: rateLimits,
308 },
309 }).limits,
310 };