The best way to control Claude Code, Codex and more from any computer or phone
feat(web): context meter fills up and shows tokens against the limit (#27892)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 30, 2026 at 23:08 UTC
961026c6c98118a5017888a8cb6ed7078db140eb
5 files changed
+127
-83
apps/web/src/components/chat/ThreadDetailsPanel.tsx
+9
-1
@@ -23,7 +23,11 @@ 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";
26
+import {
27
+ ThreadDetailsContext,
28
+ ThreadDetailsUsage,
29
+ type ThreadDetailsUsageInput,
30
+} from "./ThreadDetailsUsage";
31
import { ThreadDetailsItemsMenuItems } from "./ThreadDetailsItemsMenu";
32
import { resolveThreadDetailsVisibility, THREAD_DETAILS_ITEMS } from "./threadDetailsItems";
33
import { useClientSettings } from "../../hooks/useSettings";
@@ -254,6 +258,10 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
258
259
{visible.usage ? <ThreadDetailsUsage {...props.usage} /> : null}
260
261
+ {visible.context && props.usage.contextWindow ? (
262
+ <ThreadDetailsContext usage={props.usage.contextWindow} />
263
+ ) : null}
264
+
265
{/* Shown only when no section above has content, so an emptied card can be refilled. */}
266
<div className="p-2 group-has-[>section>:last-child:not(:empty)]/details-items:hidden">
267
<ThreadDetailsControl
apps/web/src/components/chat/ThreadDetailsUsage.tsx
+100
-69
@@ -20,6 +20,7 @@ import { type ContextWindowSnapshot, formatContextWindowTokens } from "../../lib
20
import { cn } from "../../lib/utils";
21
import { formatUpcomingTimestamp } from "../../timestampFormat";
22
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
23
+import { formatContextWindowCompactionMessage } from "./ContextWindowMeter.logic";
24
import { ThreadDetailsSection } from "./ThreadDetailsSection";
25
26
const PACE_LABEL: Record<LimitPace, string> = {
@@ -35,16 +36,14 @@ export interface ThreadDetailsUsageInput {
36
readonly contextWindow: ContextWindowSnapshot | null;
37
}
38
38
-/**
39
- * 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
- */
39
+type UsageTone = "error" | "warning" | null;
40
+
41
+/** The selected provider's limit windows. Each row reads as room left. */
42
export function ThreadDetailsUsage({
43
providerInstanceId,
44
providers,
45
sources,
46
- contextWindow,
47
-}: ThreadDetailsUsageInput) {
46
+}: Omit<ThreadDetailsUsageInput, "contextWindow">) {
47
const nowMinute = useNowMinute();
48
const now = Date.parse(`${nowMinute}:00Z`);
49
const report =
@@ -56,28 +55,83 @@ export function ThreadDetailsUsage({
55
const limits =
56
report?.accounts.find((entry) => entry.instanceId === providerInstanceId)?.limits ??
57
providers.find((provider) => provider.instanceId === providerInstanceId)?.usageLimits;
59
- const notice = limits ? limitsNotice(limits) : null;
60
- if (!limits && !contextWindow) return null;
58
+ if (!limits) return null;
59
+ const notice = limitsNotice(limits);
60
61
return (
62
<ThreadDetailsSection
63
headingId="thread-details-usage-heading"
65
- title="Usage"
64
+ title="Usage limits"
65
showHeading={false}
66
>
67
<div className="grid grid-cols-[auto_minmax(3rem,1fr)_auto] gap-x-3 text-xs">
68
{notice ? (
69
<UsageRow
70
label="Limits"
72
- left={null}
71
+ fill={null}
72
+ tone={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}
76
+ ) : (
77
+ limits.windows.map((window) => <LimitRow key={window.id} window={window} now={now} />)
78
+ )}
79
+ </div>
80
+ </ThreadDetailsSection>
81
+ );
82
+}
83
+
84
+/** The thread's context window. The bar fills as context is used; the tick marks auto-compaction. */
85
+export function ThreadDetailsContext({ usage }: { readonly usage: ContextWindowSnapshot }) {
86
+ const maxTokens = usage.maxTokens != null && usage.maxTokens > 0 ? usage.maxTokens : null;
87
+ const used =
88
+ maxTokens !== null && usage.usedPercentage !== null
89
+ ? Math.round(Math.max(0, Math.min(100, usage.usedPercentage)))
90
+ : null;
91
+ const threshold = usage.autoCompactThreshold ?? null;
92
+ const tick =
93
+ maxTokens !== null && threshold !== null && threshold > 0 && threshold < maxTokens
94
+ ? (threshold / maxTokens) * 100
95
+ : null;
96
+ const usedTokens = formatContextWindowTokens(usage.usedTokens);
97
+ return (
98
+ <ThreadDetailsSection
99
+ headingId="thread-details-context-heading"
100
+ title="Context window"
101
+ showHeading={false}
102
+ >
103
+ <div className="grid grid-cols-[auto_minmax(3rem,1fr)_auto] gap-x-3 text-xs">
104
+ <UsageRow
105
+ label="Context"
106
+ fill={used}
107
+ tone={used === null ? null : used >= 90 ? "error" : used >= 80 ? "warning" : null}
108
+ tick={tick}
109
+ muted
110
+ value={
111
+ maxTokens !== null
112
+ ? `${usedTokens} / ${formatContextWindowTokens(maxTokens)}`
113
+ : usedTokens
114
+ }
115
+ ariaValue={used !== null ? `${used}% used` : `${usedTokens} tokens used`}
116
+ tooltip={
117
+ <>
118
+ <span className="text-foreground">
119
+ {used !== null ? `Context: ${used}% used` : `Context: ${usedTokens} tokens used`}
120
+ </span>
121
+ {maxTokens !== null ? (
122
+ <span className="text-muted-foreground">
123
+ {usage.usedTokens.toLocaleString("en-US")} of {maxTokens.toLocaleString("en-US")}{" "}
124
+ tokens
125
+ </span>
126
+ ) : null}
127
+ {threshold !== null && threshold > 0 ? (
128
+ <span className="text-muted-foreground">
129
+ {formatContextWindowCompactionMessage(null, threshold)}
130
+ </span>
131
+ ) : null}
132
+ </>
133
+ }
134
+ />
135
</div>
136
</ThreadDetailsSection>
137
);
@@ -97,7 +151,10 @@ function LimitRow({
151
return (
152
<UsageRow
153
label={window.label}
100
- left={left}
154
+ fill={left}
155
+ tone={left <= 10 ? "error" : left <= 20 ? "warning" : null}
156
+ value={`${left}%`}
157
+ ariaValue={`${left}% left`}
158
tooltip={
159
<>
160
<span className="text-foreground">
@@ -116,76 +173,43 @@ function LimitRow({
173
);
174
}
175
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
-
176
/** One label, hairline, and value row; the whole row opens the details tooltip. */
177
function UsageRow({
178
label,
156
- left,
157
- tooltip,
179
+ fill,
180
+ tone,
181
+ tick = null,
182
value,
183
+ ariaValue = value,
184
+ tooltip,
185
muted = false,
160
- className,
186
}: {
187
readonly label: string;
163
- readonly left: number | null;
188
+ /** Bar fill from 0 to 100. Null hides the bar. */
189
+ readonly fill: number | null;
190
+ readonly tone: UsageTone;
191
+ /** A marker on the bar, from 0 to 100. */
192
+ readonly tick?: number | null;
193
+ readonly value: string;
194
+ readonly ariaValue?: string;
195
readonly tooltip: ReactNode;
165
- /** Replaces the percentage when there is none. */
166
- readonly value?: string | undefined;
196
readonly muted?: boolean;
168
- readonly className?: string | undefined;
197
}) {
170
- const tone = left === null ? null : left <= 10 ? "error" : left <= 20 ? "warning" : null;
198
return (
199
<Tooltip>
200
<TooltipTrigger
201
render={
202
<div
203
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
- )}
204
+ aria-label={`${label}: ${ariaValue}`}
205
+ className="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]"
206
/>
207
}
208
>
209
<span className="max-w-28 truncate text-muted-foreground">{label}</span>
186
- {left !== null ? (
210
+ {fill !== null ? (
211
<span className="relative h-[3px] rounded-full bg-muted-foreground/30 dark:bg-muted-foreground/20">
188
- {left > 0 ? (
212
+ {fill > 0 ? (
213
<span
214
className={cn(
215
"absolute inset-y-0 left-0 rounded-full",
@@ -197,7 +221,14 @@ function UsageRow({
221
? "bg-muted-foreground"
222
: "bg-foreground/80",
223
)}
200
- style={{ width: `max(${left}%, 6px)` }}
224
+ style={{ width: `max(${fill}%, 6px)` }}
225
+ />
226
+ ) : null}
227
+ {tick !== null ? (
228
+ <span
229
+ aria-hidden
230
+ className="absolute -top-[3px] h-[9px] w-px -translate-x-1/2 bg-foreground/60"
231
+ style={{ left: `${tick}%` }}
232
/>
233
) : null}
234
</span>
@@ -206,17 +237,17 @@ function UsageRow({
237
className={cn(
238
// Text-only rows span the bar column so they never widen the shared value column.
239
"text-end font-medium tabular-nums",
209
- left === null && "col-span-2",
240
+ fill === null && "col-span-2",
241
tone === "error"
242
? "text-error-foreground"
243
: tone === "warning"
244
? "text-warning-foreground"
214
- : left === null
245
+ : fill === null
246
? "text-muted-foreground"
247
: "text-foreground/80",
248
)}
249
>
219
- {value ?? `${left}%`}
250
+ {value}
251
</span>
252
</TooltipTrigger>
253
{/* Rows sit 8px inside the card; clear its edge instead of overlapping it. */}
apps/web/src/components/chat/threadDetailsItems.test.ts
+6
-5
@@ -11,16 +11,17 @@ const servers = THREAD_DETAILS_ITEMS.find((item) => item.id === "servers")!;
11
12
describe("thread details items", () => {
13
it.each([
14
- { legacy: false, items: {}, usage: false },
15
- { legacy: true, items: {}, usage: true },
16
- { legacy: true, items: { usage: false }, usage: false },
17
- { legacy: false, items: { usage: true, retired: false }, usage: true },
18
- ])("resolves Usage from overrides and the retired Labs flag: %o", (row) => {
14
+ { legacy: false, items: {}, usage: false, context: false },
15
+ { legacy: true, items: {}, usage: true, context: true },
16
+ { legacy: true, items: { usage: false }, usage: false, context: true },
17
+ { legacy: false, items: { usage: true, retired: false }, usage: true, context: false },
18
+ ])("resolves Usage and Context from overrides and the retired Labs flag: %o", (row) => {
19
const visibility = resolveThreadDetailsVisibility({
20
threadDetailsItems: row.items,
21
threadDetailsUsageEnabled: row.legacy,
22
});
23
expect(visibility.usage).toBe(row.usage);
24
+ expect(visibility.context).toBe(row.context);
25
expect(visibility.servers).toBe(true);
26
});
27
apps/web/src/components/chat/threadDetailsItems.ts
+7
-4
@@ -11,7 +11,8 @@ export const THREAD_DETAILS_ITEMS = [
11
{ id: "servers", label: "Servers", defaultVisible: true },
12
{ id: "automations", label: "Automations", defaultVisible: true },
13
{ id: "lineage", label: "Lineage", defaultVisible: true },
14
- { id: "usage", label: "Usage", defaultVisible: false },
14
+ { id: "usage", label: "Usage limits", defaultVisible: false },
15
+ { id: "context", label: "Context window", defaultVisible: false },
16
] as const;
17
18
export type ThreadDetailsItemId = (typeof THREAD_DETAILS_ITEMS)[number]["id"];
@@ -23,9 +24,11 @@ type ThreadDetailsItemSettings = Pick<
24
"threadDetailsItems" | "threadDetailsUsageEnabled"
25
>;
26
26
-// People who turned on the retired Labs toggle keep Usage until they change it here.
27
+// People who turned on the retired Labs toggle keep Usage and Context until they change them here.
28
function defaultVisible(item: ThreadDetailsItem, settings: ThreadDetailsItemSettings) {
28
- return item.id === "usage" ? settings.threadDetailsUsageEnabled : item.defaultVisible;
29
+ return item.id === "usage" || item.id === "context"
30
+ ? settings.threadDetailsUsageEnabled
31
+ : item.defaultVisible;
32
}
33
34
export function resolveThreadDetailsVisibility(
@@ -53,7 +56,7 @@ export function isDefaultThreadDetailsVisibility(visibility: ThreadDetailsVisibi
56
return THREAD_DETAILS_ITEMS.every((item) => visibility[item.id] === item.defaultVisible);
57
}
58
56
-/** Also clears the retired Labs flag, so Usage returns to off. */
59
+/** Also clears the retired Labs flag, so Usage and Context return to off. */
60
export const RESET_THREAD_DETAILS_ITEMS = {
61
threadDetailsItems: {},
62
threadDetailsUsageEnabled: false,
docs/user/usage.md
+5
-4
@@ -120,11 +120,12 @@ current model's limits without leaving the conversation. The result opens above
120
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
121
anything. The command is offered only for providers that appear under **Usage → Limits**.
122
123
-To keep them in view on web and desktop, turn on **Usage** in **Settings → Appearance → Thread details**, or right-click the thread details card.
123
+To keep them in view on web and desktop, turn on **Usage limits** in **Settings → Appearance → Thread details**, or right-click the thread details card.
124
The bottom of the thread details card then shows how much is left in each limit window of the
125
-current provider account and in the thread's context window. Some windows, such as a weekly Opus
126
-limit, count only one model. Hover a row to see when it resets, your pace, or
127
-the token count.
125
+current provider account. Some windows, such as a weekly Opus limit, count only one model. Hover a
126
+row to see when it resets and your pace. Turn on **Context window** to also show the thread's
127
+context use against the model's limit. A tick on the bar marks where the provider compacts
128
+automatically, when it reports that point.
129
130
OpenCode Go reports its session, weekly, and monthly allowance when OpenCode runs locally in
131
the environment. T3 cannot report limits for external OpenCode servers because their credentials