@devries-cameron20 / t3code Mirror · read-only / commits / be53bbd850
Fork 0

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 24, 09:00 UTC

feat(usage): show remaining quota instead of used (#9889)

Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com>

Chris Deeming committed Sep 6, 2026 at 00:22 UTC be53bbd85044e937c359a89b6004c3d3c38ffcf1
5 files changed +51 -29
apps/mobile/src/features/usage/UsageLimitsSection.tsx
+17 -12
@@ -18,6 +18,7 @@ import {
18 limitsNotice,
19 paceOf,
20 providerLimitsLabel,
21 + remainingPercent,
22 } from "@t3tools/shared/usageLimits";
23 import { type ReactNode, useState } from "react";
24 import { Alert, Pressable, View } from "react-native";
@@ -44,9 +45,10 @@ function useBarColor(driver: Driver): string | null {
45 }
46
47 /**
47 - * One window as a bar spanning its whole duration: the fill is quota spent,
48 - * the hairline is how far into the window the clock is. Pace sits under the
49 - * left edge, the countdown under the right, so a row reads in one glance.
48 + * One window as a bar spanning its whole duration: the fill is quota left,
49 + * the hairline is how much of the window is left, so even spending keeps the
50 + * fill on the line. Pace sits under the left edge, the countdown under the
51 + * right, so a row reads in one glance.
52 */
53 function WindowRow(props: {
54 readonly window: ServerProviderUsageWindow;
@@ -54,37 +56,40 @@ function WindowRow(props: {
56 readonly now: number;
57 }) {
58 const { window, now } = props;
57 - const used = Math.round(Math.max(0, Math.min(100, window.usedPercent)));
59 + const remaining = remainingPercent(window);
60 const elapsed = elapsedShare(window, now);
61 + const timeLeft = elapsed === null ? null : Math.round((1 - elapsed) * 100);
62 const pace = paceOf(window, now);
63 const resetsIn = formatResetsIn(window, now);
64 return (
65 <View className="gap-1">
66 <View className="flex-row items-baseline justify-between gap-3">
67 <Text className="text-sm text-foreground">{window.label}</Text>
65 - <Text className="text-sm font-t3-medium tabular-nums text-foreground">{used}%</Text>
68 + <Text className="text-sm font-t3-medium tabular-nums text-foreground">
69 + {remaining}% left
70 + </Text>
71 </View>
72 <View className="h-3 justify-center">
73 <View className="h-1.5 flex-row overflow-hidden rounded-full bg-subtle">
74 <View
75 className={
71 - used >= 90
76 + remaining <= 10
77 ? "h-full rounded-full bg-red-500"
73 - : used >= 70
78 + : remaining <= 30
79 ? "h-full rounded-full bg-amber-500"
80 : "h-full rounded-full bg-foreground"
81 }
82 style={[
78 - { flex: used },
79 - used < 70 && props.color ? { backgroundColor: props.color } : null,
83 + { flex: remaining },
84 + remaining > 30 && props.color ? { backgroundColor: props.color } : null,
85 ]}
86 />
82 - <View style={{ flex: 100 - used }} />
87 + <View style={{ flex: 100 - remaining }} />
88 </View>
84 - {elapsed !== null ? (
89 + {timeLeft !== null ? (
90 <View
91 className="absolute top-0 bottom-0 w-px bg-foreground"
87 - style={{ left: `${elapsed * 100}%`, opacity: 0.6 }}
92 + style={{ left: `${timeLeft}%`, opacity: 0.6 }}
93 />
94 ) : null}
95 </View>
apps/web/src/components/usage/UsageLimits.tsx
+13 -11
@@ -20,6 +20,7 @@ import {
20 type LimitPace,
21 paceOf,
22 providerLimitsLabel,
23 + remainingPercent,
24 } from "@t3tools/shared/usageLimits";
25 import { GaugeIcon, TrendingDownIcon, TrendingUpIcon } from "lucide-react";
26 import { Fragment, useState } from "react";
@@ -95,14 +96,16 @@ function WindowBar({
96 readonly now: number;
97 }) {
98 const timestampFormat = usePrimarySettings((settings) => settings.timestampFormat);
98 - const used = Math.max(0, Math.min(100, window.usedPercent));
99 + const remaining = remainingPercent(window);
100 const elapsed = elapsedShare(window, now);
101 + // The fill is quota left, so the even-spending mark is the time left.
102 + const timeLeft = elapsed === null ? null : Math.round((1 - elapsed) * 100);
103 const resetsIn = formatResetsIn(window, now);
104 const resetsAt = window.resetsAt
105 ? formatUpcomingTimestamp(window.resetsAt, timestampFormat, now)
106 : null;
104 - const summary = `${window.label}: ${Math.round(used)}% used${
105 - elapsed === null ? "" : `, ${Math.round(elapsed * 100)}% of the window elapsed`
107 + const summary = `${window.label}: ${remaining}% left${
108 + timeLeft === null ? "" : `, ${timeLeft}% of the window left`
109 }${resetsIn ? `, ${resetsIn}` : ""}`;
110
111 return (
@@ -118,27 +121,26 @@ function WindowBar({
121 }
122 >
123 <div className="absolute inset-x-0 inset-y-1.5 rounded-full bg-muted" />
121 - {used > 0 ? (
124 + {remaining > 0 ? (
125 <div
126 className="absolute inset-y-1.5 left-0 rounded-full"
124 - style={{ width: `${used}%`, backgroundColor: color }}
127 + style={{ width: `${remaining}%`, backgroundColor: color }}
128 />
129 ) : null}
127 - {elapsed !== null ? (
130 + {timeLeft !== null ? (
131 <span
132 aria-hidden
133 className="absolute inset-y-0.5 w-px -translate-x-1/2 bg-foreground/60"
131 - style={{ left: `${elapsed * 100}%` }}
134 + style={{ left: `${timeLeft}%` }}
135 />
136 ) : null}
137 </TooltipTrigger>
138 <TooltipPopup side="top" className="max-w-72 text-xs">
139 <div className="flex flex-col gap-0.5">
140 <span className="text-foreground">
138 - {Math.round(used)}% used
139 - {elapsed !== null ? ` · ${Math.round(elapsed * 100)}% of the window elapsed` : ""}
141 + {remaining}% left{timeLeft !== null ? ` · ${timeLeft}% of the window left` : ""}
142 </span>
141 - {elapsed !== null ? (
143 + {timeLeft !== null ? (
144 <span className="text-muted-foreground">The line is where even spending would be.</span>
145 ) : null}
146 {resetsAt ? (
@@ -185,7 +187,7 @@ export function LimitWindows({
187 <span className="flex min-w-0 items-center gap-2 text-xs">
188 <span className="truncate text-muted-foreground">{window.label}</span>
189 <span className="ms-auto shrink-0 font-medium text-foreground tabular-nums">
188 - {Math.round(window.usedPercent)}%
190 + {remainingPercent(window)}% left
191 </span>
192 </span>
193 <WindowBar color={color} window={window} now={now} />
docs/user/usage.md
+3 -3
@@ -39,9 +39,9 @@ the dialog.
39
40 ## Track subscription limits
41
42 -**Usage → Limits** shows quota use and reset times for Codex and Claude subscriptions. It also
43 -compares quota consumed with time elapsed in each window, so you can judge your pace before the
44 -next reset.
42 +**Usage → Limits** shows how much quota is left in each window and when it resets, for Codex and
43 +Claude subscriptions. For windows with timing data, each bar also marks how much of the window is
44 +left, so you can judge your pace before the next reset.
45
46 If a window looks stale, refresh Limits to re-check every provider and hub.
47
packages/shared/src/usageLimits.test.ts
+10
@@ -20,6 +20,7 @@ import {
20 limitsNotice,
21 paceOf,
22 providersWithLimits,
23 + remainingPercent,
24 } from "./usageLimits.ts";
25
26 const now = Date.parse("2026-09-03T12:00:00.000Z");
@@ -493,6 +494,15 @@ describe("sameUsageLimitCommandCoverage", () => {
494 });
495 });
496
497 +describe("remainingPercent", () => {
498 + it("inverts and clamps the reported usage", () => {
499 + expect(remainingPercent(window)).toBe(60);
500 + expect(remainingPercent({ ...window, usedPercent: 0 })).toBe(100);
501 + expect(remainingPercent({ ...window, usedPercent: 100 })).toBe(0);
502 + expect(remainingPercent({ ...window, usedPercent: 33.4 })).toBe(67);
503 + });
504 +});
505 +
506 describe("isUsageLimitsCommand", () => {
507 it("recognizes only the standalone local action", () => {
508 expect(isUsageLimitsCommand(" /USAGE-LIMITS\n")).toBe(true);
packages/shared/src/usageLimits.ts
+8 -3
@@ -166,6 +166,11 @@ export function limitsNotice(limits: ServerProviderUsageLimits): string | null {
166 return limits.windows.length === 0 ? "No limits reported." : null;
167 }
168
169 +/** Quota left in the window, 0..100. Bars and labels show what remains, as Codex does. */
170 +export function remainingPercent(window: ServerProviderUsageWindow): number {
171 + return Math.round(100 - Math.max(0, Math.min(100, window.usedPercent)));
172 +}
173 +
174 function resetMillis(window: ServerProviderUsageWindow): number | null {
175 if (window.resetsAt === undefined) return null;
176 const at = Date.parse(window.resetsAt);
@@ -184,9 +189,9 @@ export function elapsedShare(window: ServerProviderUsageWindow, now: number): nu
189 export type LimitPace = "ahead" | "on" | "under";
190
191 /**
187 - * Usage against the clock. The bar is the whole window, so the elapsed share
188 - * is also where even spending would have put the fill; within five points of
189 - * it counts as on pace.
192 + * Usage against the clock. Spending evenly leaves the same share of quota as
193 + * there is time left in the window; within five points of that counts as on
194 + * pace, further ahead means the window may run dry first.
195 */
196 export function paceOf(window: ServerProviderUsageWindow, now: number): LimitPace | null {
197 const elapsed = elapsedShare(window, now);