The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 00:30 UTC
fix(server): preserve Codex hub plan metadata (#21413)
Co-authored-by: Kalven Schraut <kalvens@rtvision.com>
Julius Marminge committed
Oct 19, 2026 at 16:22 UTC
253f139b1529025fd11a3e75170ef1bd1cf8152e
2 files changed
+51
-3
apps/server/src/usage/cliproxyApi.test.ts
+46
-1
@@ -49,7 +49,12 @@ const encodeJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
49
50
function fixture(
51
options: {
52
- accounts?: Array<(typeof accounts)[number] & { disabled?: boolean }>;
52
+ accounts?: Array<
53
+ (typeof accounts)[number] & {
54
+ disabled?: boolean;
55
+ id_token: { chatgpt_account_id: string; plan_type?: string; chatgpt_plan_type?: string };
56
+ }
57
+ >;
58
upstream?: (request: RequestBody) => { status: number; body: unknown };
59
cooldownStatus?: number;
60
} = {},
@@ -254,6 +259,46 @@ describe("CLIProxyAPI built-in management API", () => {
259
}),
260
);
261
262
+ it.effect("resolves a missing usage plan from current, then legacy, token plans", () =>
263
+ Effect.gen(function* () {
264
+ const test = fixture({
265
+ accounts: [
266
+ { ...accounts[0]!, id_token: { chatgpt_account_id: "account-a", plan_type: "free" } },
267
+ {
268
+ ...accounts[1]!,
269
+ id_token: {
270
+ chatgpt_account_id: "account-b",
271
+ plan_type: "go",
272
+ chatgpt_plan_type: "plus",
273
+ },
274
+ },
275
+ {
276
+ ...accounts[1]!,
277
+ id: "third.json",
278
+ auth_index: "c",
279
+ id_token: { chatgpt_account_id: "account-c", chatgpt_plan_type: "free" },
280
+ },
281
+ ],
282
+ upstream: (request) => ({
283
+ status: 200,
284
+ body: {
285
+ ...(request.auth_index === "a" ? { plan_type: "plus" } : {}),
286
+ rate_limit: { primary_window: { used_percent: 12 } },
287
+ },
288
+ }),
289
+ });
290
+ const api = yield* test.api;
291
+ const result = yield* api.readAccounts(config);
292
+ expect(result.map((account) => [account.plan, account.usageLimits.windows[0]?.kind])).toEqual(
293
+ [
294
+ ["ChatGPT Plus Subscription", "session"],
295
+ ["ChatGPT Go Subscription", "monthly"],
296
+ ["ChatGPT Free Subscription", "monthly"],
297
+ ],
298
+ );
299
+ }),
300
+ );
301
+
302
it.effect("keeps the path of a hub served under a prefix", () =>
303
Effect.gen(function* () {
304
const test = fixture();
apps/server/src/usage/cliproxyApi.ts
+5
-2
@@ -28,6 +28,7 @@ const AuthFile = Schema.Struct({
28
Schema.Struct({
29
chatgpt_account_id: Schema.optional(Schema.String),
30
chatgpt_plan_type: Schema.optional(Schema.String),
31
+ plan_type: Schema.optional(Schema.String),
32
}),
33
),
34
});
@@ -305,14 +306,16 @@ export const makeCliproxyApi = Effect.gen(function* () {
306
: null;
307
const available = yield* credits(config, account).pipe(Effect.orElseSucceed(() => undefined));
308
const next = available?.[0];
309
+ const planType =
310
+ usage.plan_type ?? account.id_token?.plan_type ?? account.id_token?.chatgpt_plan_type;
311
return {
312
...base,
310
- plan: codexPlanLabel(usage.plan_type ?? account.id_token?.chatgpt_plan_type),
313
+ plan: codexPlanLabel(planType),
314
usageLimits: {
315
...codexRateLimitsToLimits({
316
checkedAt,
317
snapshot: {
315
- planType: usage.plan_type ?? null,
318
+ planType: planType ?? null,
319
primary: toWindow(usage.rate_limit?.primary_window),
320
secondary: toWindow(usage.rate_limit?.secondary_window),
321
},