@devries-cameron20 / t3code-1 / commits / 9f52b7d419
Fork 0

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

fix(usage): use the freshest reported pooled plan (#25214)

Co-authored-by: Vitaly Iegorov <586558+vitalyiegorov@users.noreply.github.com>

maria committed Oct 31, 2026 at 08:39 UTC 9f52b7d419fe5e69f35eb5045a74cd70def31e1e
2 files changed +50 -1
packages/shared/src/usageLimits.test.ts
+40
@@ -236,6 +236,46 @@ describe("pools", () => {
236 expect(accounts[0]?.limits.windows[0]?.usedPercent).toBe(55);
237 });
238
239 + it("uses the freshest reported plan even when the newest quota has no plan", () => {
240 + const snapshot = (label: string | undefined, checkedAt: string, usedPercent: number) =>
241 + provider({
242 + driver: claude,
243 + auth: { status: "authenticated", email: "same@example.com", label },
244 + usageLimits: { checkedAt, windows: [{ ...window, usedPercent }] },
245 + });
246 + const stale = snapshot("Claude Team Subscription", checkedAt, 40);
247 + const fresh = snapshot("Claude Max Subscription", "2026-09-03T11:30:00.000Z", 7);
248 + const newest = snapshot(undefined, "2026-09-03T12:00:00.000Z", 5);
249 + for (const [reports, plan, usedPercent] of [
250 + [[stale, fresh], "Claude Max Subscription", 7],
251 + [[stale, newest], "Claude Team Subscription", 5],
252 + [[stale, fresh, newest], "Claude Max Subscription", 5],
253 + ] as const) {
254 + for (const order of reports.length === 2
255 + ? [reports, reports.toReversed()]
256 + : [
257 + [stale, fresh, newest],
258 + [stale, newest, fresh],
259 + [fresh, stale, newest],
260 + [fresh, newest, stale],
261 + [newest, stale, fresh],
262 + [newest, fresh, stale],
263 + ]) {
264 + const accounts = collectLimitAccounts(
265 + new Map(
266 + order.map((entry, index) => [
267 + EnvironmentId.make(`env-${index}`),
268 + { ...laptop, serverConfig: { providers: [entry] } },
269 + ]),
270 + ),
271 + );
272 + expect(accounts).toHaveLength(1);
273 + expect(accounts[0]?.plan).toBe(plan);
274 + expect(accounts[0]?.limits.windows[0]?.usedPercent).toBe(usedPercent);
275 + }
276 + }
277 + });
278 +
279 it("merges OpenCode Go limits from machines with the same API key", () => {
280 const go = provider({
281 driver: ProviderDriverKind.make("opencode"),
packages/shared/src/usageLimits.ts
+10 -1
@@ -255,6 +255,7 @@ export function collectLimitAccounts(presentations: LimitPresentations): readonl
255 const accounts = new Map<string, LimitAccount>();
256 const creditSources = new Map<string, LimitAccount>();
257 const hubRedeems = new Map<string, LimitAccount>();
258 + const planSources = new Map<string, LimitAccount>();
259 const merge = (key: string, next: LimitAccount) => {
260 // Prefer hub redemption to clear its routing cooldown too; displayed balance still follows the freshest read.
261 const previousHub = hubRedeems.get(key);
@@ -273,6 +274,14 @@ export function collectLimitAccounts(presentations: LimitPresentations): readonl
274 ) {
275 creditSources.set(key, next);
276 }
277 + const previousPlan = planSources.get(key);
278 + if (
279 + next.plan &&
280 + (!previousPlan ||
281 + Date.parse(next.limits.checkedAt) > Date.parse(previousPlan.limits.checkedAt))
282 + ) {
283 + planSources.set(key, next);
284 + }
285 const previous = accounts.get(key);
286 if (!previous) {
287 accounts.set(key, next);
@@ -291,7 +300,7 @@ export function collectLimitAccounts(presentations: LimitPresentations): readonl
300 accounts.set(key, {
301 ...previous,
302 displayName: previous.displayName ?? next.displayName,
294 - plan: previous.plan ?? next.plan,
303 + plan: planSources.get(key)?.plan ?? previous.plan ?? next.plan,
304 accentColor: previous.accentColor ?? next.accentColor,
305 environments,
306 sourceLabel: environments.length > 0 ? null : (previous.sourceLabel ?? next.sourceLabel),