@devries-cameron20 / t3code Mirror · read-only / commits / 310c128552
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 22, 13:15 UTC

feat(web): Labs toggle keeps 5h, weekly, and context limits in view (#26859)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 29, 2026 at 01:14 UTC 310c12855238cc191021dfbaaa51aef203374769
8 files changed +282
apps/desktop/src/settings/DesktopClientSettings.test.ts
+1
@@ -64,6 +64,7 @@ const clientSettings: ClientSettings = {
64 sidebarThreadSortOrder: "created_at",
65 boringSidebarEnabled: false,
66 boringSidebarMultilineRows: false,
67 + threadDetailsUsageEnabled: false,
68 legacySidebarEnabled: false,
69 sidebarWorkingShelfEnabled: false,
70 loadBalancingEnabled: false,
apps/web/src/components/ChatView.tsx
+13
@@ -1228,6 +1228,9 @@ export default function ChatView(props: ChatViewProps) {
1228 const canChangeEnvironment =
1229 hasMultipleEnvironments && !envLocked && draftId !== null && !draftThread?.promotedTo;
1230
1231 + const threadDetailsUsageEnabled = useClientSettings(
1232 + (settings) => settings.threadDetailsUsageEnabled,
1233 + );
1234 const loadBalancingSettings = useClientSettings((settings) => ({
1235 loadBalancingEnabled: settings.loadBalancingEnabled,
1236 loadBalancingWeights: settings.loadBalancingWeights,
@@ -3770,6 +3773,16 @@ export default function ChatView(props: ChatViewProps) {
3773 onAddProjectScript={saveProjectScriptStable}
3774 onUpdateProjectScript={updateProjectScriptStable}
3775 onDeleteProjectScript={deleteProjectScriptStable}
3776 + usage={
3777 + threadDetailsUsageEnabled
3778 + ? {
3779 + providerInstanceId: activeProviderInstanceId,
3780 + providers: providerStatuses,
3781 + sources: serverConfig?.usageLimitSources ?? EMPTY_USAGE_LIMIT_SOURCES,
3782 + contextWindow: activeContextWindow,
3783 + }
3784 + : undefined
3785 + }
3786 />
3787
3788 <PullRequestThreadDialogHost
apps/web/src/components/chat/ThreadDetailsPanel.tsx
+5
@@ -23,6 +23,7 @@ import { ThreadDetailsSection } from "./ThreadDetailsSection";
23 import { ThreadAutomationsPanel } from "./ThreadAutomationsPanel";
24 import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
25 import { ThreadServersPanel } from "./ThreadServersPanel";
26 +import { ThreadDetailsUsage, type ThreadDetailsUsageInput } from "./ThreadDetailsUsage";
27
28 const GitActionsControl = memo(BaseGitActionsControl);
29
@@ -67,6 +68,8 @@ interface ThreadDetailsPanelProps extends Pick<
68 input: NewProjectScriptInput,
69 ) => Promise<ProjectScriptActionResult>;
70 onDeleteProjectScript: (scriptId: string) => Promise<ProjectScriptActionResult>;
71 + /** Set only while the Labs usage readout is on. */
72 + usage?: ThreadDetailsUsageInput | undefined;
73 }
74
75 export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
@@ -195,6 +198,8 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
198 threadId={props.threadId}
199 />
200 ) : null}
201 +
202 + {props.usage ? <ThreadDetailsUsage {...props.usage} /> : null}
203 </>
204 )}
205 </ThreadDetailsCard>
apps/web/src/components/chat/ThreadDetailsUsage.tsx new
+228
@@ -0,0 +1,228 @@
1 +import type {
2 + ProviderInstanceId,
3 + ServerProvider,
4 + ServerProviderUsageWindow,
5 + UsageLimitSourceSnapshots,
6 +} from "@t3tools/contracts";
7 +import {
8 + collectProviderUsageLimits,
9 + formatDuration,
10 + type LimitPace,
11 + limitsNotice,
12 + paceOf,
13 + remainingPercent,
14 +} from "@t3tools/shared/usageLimits";
15 +import type { ReactNode } from "react";
16 +
17 +import { usePrimarySettings } from "../../hooks/useSettings";
18 +import { useNowMinute } from "../../hooks/useNowMinute";
19 +import { type ContextWindowSnapshot, formatContextWindowTokens } from "../../lib/contextWindow";
20 +import { cn } from "../../lib/utils";
21 +import { formatUpcomingTimestamp } from "../../timestampFormat";
22 +import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
23 +import { ThreadDetailsSection } from "./ThreadDetailsSection";
24 +
25 +const PACE_LABEL: Record<LimitPace, string> = {
26 + ahead: "Ahead of pace",
27 + on: "On pace",
28 + under: "Under pace",
29 +};
30 +
31 +export interface ThreadDetailsUsageInput {
32 + readonly providerInstanceId: ProviderInstanceId | null;
33 + readonly providers: readonly ServerProvider[];
34 + readonly sources: UsageLimitSourceSnapshots;
35 + readonly contextWindow: ContextWindowSnapshot | null;
36 +}
37 +
38 +/**
39 + * Labs readout of the selected provider's limit windows and the thread's context window.
40 + * Every row reads as room left, so a longer bar always means more headroom.
41 + */
42 +export function ThreadDetailsUsage({
43 + providerInstanceId,
44 + providers,
45 + sources,
46 + contextWindow,
47 +}: ThreadDetailsUsageInput) {
48 + const nowMinute = useNowMinute();
49 + const now = Date.parse(`${nowMinute}:00Z`);
50 + const report =
51 + providerInstanceId !== null
52 + ? collectProviderUsageLimits(providerInstanceId, providers, sources, now)
53 + : null;
54 + // Only this instance's data: the report keeps one instance per login, and any other entry may be
55 + // a different login or workspace, so fall back to the instance's own snapshot.
56 + const limits =
57 + report?.accounts.find((entry) => entry.instanceId === providerInstanceId)?.limits ??
58 + providers.find((provider) => provider.instanceId === providerInstanceId)?.usageLimits;
59 + const notice = limits ? limitsNotice(limits) : null;
60 + if (!limits && !contextWindow) return null;
61 +
62 + return (
63 + <ThreadDetailsSection
64 + headingId="thread-details-usage-heading"
65 + title="Usage"
66 + showHeading={false}
67 + >
68 + <div className="grid grid-cols-[auto_minmax(3rem,1fr)_auto] gap-x-3 text-xs">
69 + {notice ? (
70 + <UsageRow
71 + label="Limits"
72 + left={null}
73 + value="Unavailable"
74 + tooltip={<span className="text-foreground">{notice}</span>}
75 + />
76 + ) : null}
77 + {limits && !notice
78 + ? limits.windows.map((window) => <LimitRow key={window.id} window={window} now={now} />)
79 + : null}
80 + {contextWindow ? <ContextRow usage={contextWindow} spaced={limits !== undefined} /> : null}
81 + </div>
82 + </ThreadDetailsSection>
83 + );
84 +}
85 +
86 +function LimitRow({
87 + window,
88 + now,
89 +}: {
90 + readonly window: ServerProviderUsageWindow;
91 + readonly now: number;
92 +}) {
93 + const timestampFormat = usePrimarySettings((settings) => settings.timestampFormat);
94 + const left = remainingPercent(window);
95 + const pace = paceOf(window, now);
96 + const resetsAt = window.resetsAt ? Date.parse(window.resetsAt) : Number.NaN;
97 + return (
98 + <UsageRow
99 + label={window.label}
100 + left={left}
101 + tooltip={
102 + <>
103 + <span className="text-foreground">
104 + {window.label}: {left}% left
105 + </span>
106 + {window.resetsAt && resetsAt > now ? (
107 + <span className="text-muted-foreground">
108 + Resets in {formatDuration(resetsAt - now)} ·{" "}
109 + {formatUpcomingTimestamp(window.resetsAt, timestampFormat, now)}
110 + </span>
111 + ) : null}
112 + {pace ? <span className="text-muted-foreground">{PACE_LABEL[pace]}</span> : null}
113 + </>
114 + }
115 + />
116 + );
117 +}
118 +
119 +function ContextRow({
120 + usage,
121 + spaced,
122 +}: {
123 + readonly usage: ContextWindowSnapshot;
124 + readonly spaced: boolean;
125 +}) {
126 + const maxTokens = usage.maxTokens ?? null;
127 + const left =
128 + maxTokens !== null && usage.usedPercentage !== null
129 + ? Math.round(100 - Math.max(0, Math.min(100, usage.usedPercentage)))
130 + : null;
131 + const used = formatContextWindowTokens(usage.usedTokens);
132 + return (
133 + <UsageRow
134 + label="Context"
135 + left={left}
136 + muted
137 + className={cn(spaced && "mt-2")}
138 + tooltip={
139 + <>
140 + {left !== null ? <span className="text-foreground">Context: {left}% left</span> : null}
141 + <span className={left !== null ? "text-muted-foreground" : "text-foreground"}>
142 + {maxTokens !== null
143 + ? `${used} of ${formatContextWindowTokens(maxTokens)} tokens used`
144 + : `${used} tokens used`}
145 + </span>
146 + </>
147 + }
148 + value={left === null ? used : undefined}
149 + />
150 + );
151 +}
152 +
153 +/** One label, hairline, and value row; the whole row opens the details tooltip. */
154 +function UsageRow({
155 + label,
156 + left,
157 + tooltip,
158 + value,
159 + muted = false,
160 + className,
161 +}: {
162 + readonly label: string;
163 + readonly left: number | null;
164 + readonly tooltip: ReactNode;
165 + /** Replaces the percentage when there is none. */
166 + readonly value?: string | undefined;
167 + readonly muted?: boolean;
168 + readonly className?: string | undefined;
169 +}) {
170 + const tone = left === null ? null : left <= 10 ? "error" : left <= 20 ? "warning" : null;
171 + return (
172 + <Tooltip>
173 + <TooltipTrigger
174 + render={
175 + <div
176 + tabIndex={0}
177 + aria-label={`${label}: ${value ?? `${left}% left`}`}
178 + className={cn(
179 + "col-span-3 grid h-6 cursor-default grid-cols-subgrid items-center rounded-lg px-2.5 outline-none hover:bg-black/[0.035] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring data-popup-open:bg-black/[0.035] dark:hover:bg-white/[0.08] dark:data-popup-open:bg-white/[0.08]",
180 + className,
181 + )}
182 + />
183 + }
184 + >
185 + <span className="max-w-28 truncate text-muted-foreground">{label}</span>
186 + {left !== null ? (
187 + <span className="relative h-[3px] rounded-full bg-muted-foreground/30 dark:bg-muted-foreground/20">
188 + {left > 0 ? (
189 + <span
190 + className={cn(
191 + "absolute inset-y-0 left-0 rounded-full",
192 + tone === "error"
193 + ? "bg-error"
194 + : tone === "warning"
195 + ? "bg-warning"
196 + : muted
197 + ? "bg-muted-foreground"
198 + : "bg-foreground/80",
199 + )}
200 + style={{ width: `max(${left}%, 6px)` }}
201 + />
202 + ) : null}
203 + </span>
204 + ) : null}
205 + <span
206 + className={cn(
207 + // Text-only rows span the bar column so they never widen the shared value column.
208 + "text-end font-medium tabular-nums",
209 + left === null && "col-span-2",
210 + tone === "error"
211 + ? "text-error-foreground"
212 + : tone === "warning"
213 + ? "text-warning-foreground"
214 + : left === null
215 + ? "text-muted-foreground"
216 + : "text-foreground/80",
217 + )}
218 + >
219 + {value ?? `${left}%`}
220 + </span>
221 + </TooltipTrigger>
222 + {/* Rows sit 8px inside the card; clear its edge instead of overlapping it. */}
223 + <TooltipPopup side="left" sideOffset={16}>
224 + <div className="flex flex-col gap-0.5">{tooltip}</div>
225 + </TooltipPopup>
226 + </Tooltip>
227 + );
228 +}
apps/web/src/components/settings/LabsSettingsPanel.tsx
+21
@@ -18,6 +18,7 @@ export function LabsSettingsPanel() {
18 <SettingsSection id="beta" title="Beta">
19 <BoringSidebarRow />
20 <BoringSidebarMultilineRow />
21 + <ThreadDetailsUsageRow />
22 {/* Clerk is only mounted when this build has T3 Connect. */}
23 {hasCloudPublicConfig() ? <GuestLinksRowWithSignIn /> : <GuestLinksRow />}
24 <LinkedEnvironmentsRow />
@@ -69,6 +70,26 @@ function BoringSidebarMultilineRow() {
70 );
71 }
72
73 +function ThreadDetailsUsageRow() {
74 + const settings = useScopedSettings();
75 + const updateSettings = useUpdateScopedSettings();
76 + return (
77 + <SettingsRow
78 + {...searchableSetting("thread-details-usage")}
79 + description="Show the current provider's usage limits and the thread's context window at the bottom of the thread details card."
80 + control={
81 + <Switch
82 + checked={settings.threadDetailsUsageEnabled}
83 + onCheckedChange={(checked) =>
84 + updateSettings({ threadDetailsUsageEnabled: Boolean(checked) })
85 + }
86 + aria-label="Usage in thread details"
87 + />
88 + }
89 + />
90 + );
91 +}
92 +
93 /** Signed out of T3 Connect, the row offers to sign in instead of its switch. */
94 function GuestLinksRowWithSignIn() {
95 const { isSignedIn } = useAuth();
apps/web/src/components/settings/settingsSearch.ts
+6
@@ -437,6 +437,12 @@ export const SETTINGS_SEARCH_ITEMS = [
437 to: "/settings/labs",
438 searchTerms: ["beta boring sidebar folder rows multiline branch pull request details"],
439 },
440 + {
441 + id: "thread-details-usage",
442 + title: "Usage in thread details",
443 + to: "/settings/labs",
444 + searchTerms: ["beta limits 5 hour weekly context window tokens quota rate limit"],
445 + },
446 {
447 id: "guest-links",
448 title: "Guest links",
docs/user/usage.md
+6
@@ -116,6 +116,12 @@ current model's limits without leaving the conversation. The result opens above
116 closes when you dismiss it or send your next message. It uses the same snapshot as **Usage → Limits**, so it does not run the agent or refresh
117 anything. The command is offered only for providers that appear under **Usage → Limits**.
118
119 +To keep them in view, turn on **Settings → Labs → Usage in thread details** on web and desktop.
120 +The bottom of the thread details card then shows how much is left in each limit window of the
121 +current provider account and in the thread's context window. Some windows, such as a weekly Opus
122 +limit, count only one model. Hover a row to see when it resets, your pace, or
123 +the token count.
124 +
125 OpenCode Go reports its session, weekly, and monthly allowance when OpenCode runs locally in
126 the environment. T3 cannot report limits for external OpenCode servers because their credentials
127 belong to the remote server. Limits need an OpenCode Go API key, or an OpenCode Console connected
packages/contracts/src/settings.ts
+2
@@ -477,6 +477,7 @@ export const ClientSettingsSchema = Schema.Struct({
477 boringSidebarMultilineRows: Schema.Boolean.pipe(
478 Schema.withDecodingDefault(Effect.succeed(false)),
479 ),
480 + threadDetailsUsageEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
481 // Opt-in for the removed legacy sidebar. Still read so those users land in
482 // the boring sidebar; the boring sidebar toggle clears it.
483 legacySidebarEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
@@ -1720,6 +1721,7 @@ export const ClientSettingsPatch = Schema.Struct({
1721 showSkillsInSlashMenu: Schema.optionalKey(Schema.Boolean),
1722 boringSidebarEnabled: Schema.optionalKey(Schema.Boolean),
1723 boringSidebarMultilineRows: Schema.optionalKey(Schema.Boolean),
1724 + threadDetailsUsageEnabled: Schema.optionalKey(Schema.Boolean),
1725 legacySidebarEnabled: Schema.optionalKey(Schema.Boolean),
1726 sidebarWorkingShelfEnabled: Schema.optionalKey(Schema.Boolean),
1727 sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),