@devries-cameron20 / t3code Mirror · read-only / commits / 13c5328dd0
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 23, 16:45 UTC

feat(web): filter the Usage page to just the providers you want (#16970)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Theo Browne committed Oct 8, 2026 at 02:24 UTC 13c5328dd02ab0f5863f7d46455efc8dc243d4ce
7 files changed +204 -20
apps/web/src/components/usage/UsageLimits.tsx
+34 -4
@@ -340,17 +340,47 @@ export function ResetCredits({
340 */
341 export function UsageLimitsSection({
342 selectedEnvironmentIds,
343 + hiddenProviders,
344 now,
345 cursorPrompt,
346 }: {
347 readonly selectedEnvironmentIds: ReadonlySet<EnvironmentId> | null;
348 + readonly hiddenProviders: ReadonlySet<UsageProviderKind>;
349 readonly now: number;
350 readonly cursorPrompt?: ReactNode;
351 }) {
352 const presentations = useAtomValue(environmentPresentations.presentationsAtom);
351 - const selected =
352 - selectedEnvironmentIds === null
353 - ? presentations
354 - : new Map([...presentations].filter(([id]) => selectedEnvironmentIds.has(id)));
353 + const hiddenDrivers = new Set<ServerProvider["driver"]>(
354 + [...hiddenProviders].map((provider) => PROVIDER_PRESENTATION[provider].driverKind),
355 + );
356 + const isVisible = (driver: ServerProvider["driver"]) => !hiddenDrivers.has(driver);
357 + // Hidden drivers leave both native accounts and hub accounts, so their
358 + // bars, notices, and external links all drop out together.
359 + const selected = new Map(
360 + [...presentations].flatMap(([id, presentation]) => {
361 + if (selectedEnvironmentIds !== null && !selectedEnvironmentIds.has(id)) return [];
362 + const config = presentation.serverConfig;
363 + if (hiddenDrivers.size === 0 || config === null) return [[id, presentation] as const];
364 + return [
365 + [
366 + id,
367 + {
368 + ...presentation,
369 + serverConfig: {
370 + ...config,
371 + providers: config.providers.filter((provider) => isVisible(provider.driver)),
372 + // A hub left with no visible accounts is dropped, not reported as empty.
373 + usageLimitSources: config.usageLimitSources?.flatMap((source) => {
374 + const accounts = source.accounts.filter((account) => isVisible(account.driver));
375 + return accounts.length === 0 && source.accounts.length > 0
376 + ? []
377 + : [{ ...source, accounts }];
378 + }),
379 + },
380 + },
381 + ] as const,
382 + ];
383 + }),
384 + );
385 return <UsageLimitsPooled presentations={selected} now={now} cursorPrompt={cursorPrompt} />;
386 }
apps/web/src/components/usage/UsagePage.test.tsx
+1
@@ -39,6 +39,7 @@ vi.mock("./usageProviders", async (importOriginal) => {
39 const actual = await importOriginal<typeof import("./usageProviders")>();
40 return {
41 ...actual,
42 + PROVIDER_ORDER: ["codex", "claude"],
43 PROVIDER_PRESENTATION: {
44 codex: { color: "white", label: "Codex", mark: "span" },
45 claude: { color: "orange", label: "Claude Code", mark: "span" },
apps/web/src/components/usage/UsagePage.tsx
+87 -9
@@ -139,14 +139,21 @@ export function UsagePage() {
139 const [selectedModelKey, setSelectedModelKey] = useState<string | null>(null);
140 const [selectedEnvironmentIds, setSelectedEnvironmentIds] =
141 useState<ReadonlySet<EnvironmentId> | null>(null);
142 + const hiddenProviders = useMemo(
143 + () => new Set(preferences.hiddenProviders),
144 + [preferences.hiddenProviders],
145 + );
146 const { days: windowDays, window } = windowSelection;
147 const isPast24Hours = windowDays === 1;
148 const { merged, environments, selectedEnvironments, isPending, isPartial, refresh } = useUsage(
149 window,
150 selectedEnvironmentIds,
151 + hiddenProviders,
152 );
153 const presentations = useAtomValue(environmentPresentations.presentationsAtom);
149 - const cursorAccessEnvironments = cursorKeychainAccessEnvironments(selectedEnvironments);
154 + const cursorAccessEnvironments = hiddenProviders.has("cursor")
155 + ? []
156 + : cursorKeychainAccessEnvironments(selectedEnvironments);
157 const sourceMessages = [
158 ...new Set(
159 selectedEnvironments.flatMap(
@@ -154,6 +161,7 @@ export function UsagePage() {
161 environment.summary?.sources.flatMap((source) =>
162 source.message &&
163 !source.action &&
164 + !hiddenProviders.has(source.fingerprint.provider) &&
165 (source.status === "partial" ||
166 source.status === "failed" ||
167 source.fingerprint.provider === "cursor")
@@ -217,11 +225,14 @@ export function UsagePage() {
225 );
226 const timeValueColumnWidth = `${60 / (activeProviders.length + 2)}%`;
227
220 - const selectWindow = (days: number) => {
221 - if (!isUsageWindowDays(days)) return;
222 - const nextPreferences = { metric, windowDays: days };
228 + const updatePreferences = (patch: Partial<UsagePagePreferences>) => {
229 + const nextPreferences = { ...preferences, ...patch };
230 setPreferences(nextPreferences);
231 saveUsagePagePreferences(nextPreferences);
232 + };
233 + const selectWindow = (days: number) => {
234 + if (!isUsageWindowDays(days)) return;
235 + updatePreferences({ windowDays: days });
236 setWindowSelection({
237 days,
238 window: makeWindow(days, undefined, days === 1 ? "hour" : "day"),
@@ -229,9 +240,7 @@ export function UsagePage() {
240 };
241 const selectMetric = (nextMetric: UsageMetric) => {
242 if (nextMetric === "limits") setLimitsNow(Date.now());
232 - const nextPreferences = { metric: nextMetric, windowDays };
233 - setPreferences(nextPreferences);
234 - saveUsagePagePreferences(nextPreferences);
243 + updatePreferences({ metric: nextMetric });
244 };
245 const refreshLimits = async (automatic = false, afterPending = false) => {
246 try {
@@ -334,7 +343,7 @@ export function UsagePage() {
343 <h1>Usage</h1>
344 </WorkspaceBreadcrumbItem>
345 <WorkspaceBreadcrumbSeparator />
337 - <WorkspaceBreadcrumbItem current className="min-w-10">
346 + <WorkspaceBreadcrumbItem className="min-w-10 shrink">
347 <UsageEnvironmentFilter
348 environments={environments}
349 selectedEnvironments={selectedEnvironments}
@@ -347,6 +356,13 @@ export function UsagePage() {
356 onOpenModelPrices={() => setPriceDialog({})}
357 />
358 </WorkspaceBreadcrumbItem>
359 + <WorkspaceBreadcrumbSeparator />
360 + <WorkspaceBreadcrumbItem current className="min-w-10">
361 + <UsageProviderFilter
362 + hiddenProviders={hiddenProviders}
363 + onChange={(next) => updatePreferences({ hiddenProviders: next })}
364 + />
365 + </WorkspaceBreadcrumbItem>
366 </WorkspaceBreadcrumb>
367 {!showingLimits ? (
368 <span className="hidden min-w-0 truncate text-xs text-muted-foreground 2xl:block">
@@ -480,6 +496,7 @@ export function UsagePage() {
496 ) : showingLimits ? (
497 <UsageLimitsSection
498 selectedEnvironmentIds={selectedEnvironmentIds}
499 + hiddenProviders={hiddenProviders}
500 now={limitsNow}
501 cursorPrompt={
502 cursorAccessEnvironments.length > 0 ? (
@@ -548,7 +565,8 @@ export function UsagePage() {
565 </span>
566 </div>
567
551 - {[...presentations].some(
568 + {!hiddenProviders.has("codex") &&
569 + [...presentations].some(
570 ([id, presentation]) =>
571 (selectedEnvironmentIds === null || selectedEnvironmentIds.has(id)) &&
572 presentation.serverConfig?.providers.some(usesChatGptSharing),
@@ -1232,6 +1250,66 @@ function UsageEnvironmentFilter({
1250 );
1251 }
1252
1253 +/** Provider visibility shared by every tab. Stored as the hidden set. */
1254 +function UsageProviderFilter({
1255 + hiddenProviders,
1256 + onChange,
1257 +}: {
1258 + readonly hiddenProviders: ReadonlySet<UsageProviderKind>;
1259 + readonly onChange: (hiddenProviders: readonly UsageProviderKind[]) => void;
1260 +}) {
1261 + const visible = PROVIDER_ORDER.filter((provider) => !hiddenProviders.has(provider));
1262 + const label =
1263 + visible.length === PROVIDER_ORDER.length
1264 + ? "All providers"
1265 + : visible.length === 0
1266 + ? "No providers"
1267 + : visible.length === 1
1268 + ? PROVIDER_PRESENTATION[visible[0]!].label
1269 + : `${visible.length} providers`;
1270 +
1271 + return (
1272 + <Menu>
1273 + <MenuTrigger render={<InlineButton />} className="group/usage-provider min-w-0 max-w-full">
1274 + <span className="min-w-0 truncate">{label}</span>
1275 + <ChevronDownIcon
1276 + className="size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover/usage-provider:opacity-100 group-focus-visible/usage-provider:opacity-100 group-data-popup-open/usage-provider:opacity-100"
1277 + aria-hidden
1278 + />
1279 + </MenuTrigger>
1280 + <MenuPopup align="start">
1281 + <MenuCheckboxItem
1282 + checked={hiddenProviders.size === 0}
1283 + closeOnClick={false}
1284 + onCheckedChange={(checked) => onChange(checked ? [] : PROVIDER_ORDER)}
1285 + >
1286 + All providers
1287 + </MenuCheckboxItem>
1288 + <MenuSeparator />
1289 + {PROVIDER_ORDER.map((provider) => (
1290 + <MenuCheckboxItem
1291 + key={provider}
1292 + checked={!hiddenProviders.has(provider)}
1293 + closeOnClick={false}
1294 + onCheckedChange={(checked) =>
1295 + onChange(
1296 + PROVIDER_ORDER.filter((entry) =>
1297 + entry === provider ? !checked : hiddenProviders.has(entry),
1298 + ),
1299 + )
1300 + }
1301 + >
1302 + <span className="flex min-w-0 items-center gap-2">
1303 + <ProviderMark provider={provider} className="size-3.5" />
1304 + <span className="truncate">{PROVIDER_PRESENTATION[provider].label}</span>
1305 + </span>
1306 + </MenuCheckboxItem>
1307 + ))}
1308 + </MenuPopup>
1309 + </Menu>
1310 + );
1311 +}
1312 +
1313 /**
1314 * Stand-in with the loaded page's shape, using the shared `Skeleton` bars so it
1315 * breathes with the same `animate-skeleton` pulse as every other loading state.
apps/web/src/components/usage/usagePagePreferences.test.ts
+8
@@ -35,6 +35,14 @@ describe("Usage page preferences", () => {
35 }
36 });
37
38 + it("round-trips hidden providers and reads older saves without them", () => {
39 + saveUsagePagePreferences({ metric: "cost", windowDays: 7, hiddenProviders: ["codex"] });
40 + expect(readUsagePagePreferences().hiddenProviders).toEqual(["codex"]);
41 +
42 + values.set(key, '{"metric":"tokens","windowDays":30}');
43 + expect(readUsagePagePreferences()).toEqual({ metric: "tokens", windowDays: 30 });
44 + });
45 +
46 it.each([
47 "not-json",
48 '{"metric":"unknown","windowDays":7}',
apps/web/src/components/usage/usagePagePreferences.ts
+3
@@ -1,3 +1,4 @@
1 +import { UsageProviderKind } from "@t3tools/contracts";
2 import * as Schema from "effect/Schema";
3
4 import { getLocalStorageItem, setLocalStorageItem } from "../../hooks/useLocalStorage";
@@ -6,6 +7,8 @@ const STORAGE_KEY = "t3code:usage-page-preferences:v1";
7 const UsagePagePreferencesSchema = Schema.Struct({
8 metric: Schema.Literals(["cost", "tokens", "limits"]),
9 windowDays: Schema.Literals([1, 7, 30, 90]),
10 + /** Providers filtered out of the page. Stored as hidden so new providers show by default. */
11 + hiddenProviders: Schema.optional(Schema.Array(UsageProviderKind)),
12 });
13 export type UsagePagePreferences = typeof UsagePagePreferencesSchema.Type;
14
apps/web/src/state/usage.test.tsx
+36 -6
@@ -1,4 +1,9 @@
1 -import { EnvironmentId, UsageDay, USAGE_CONTRACT_VERSION } from "@t3tools/contracts";
1 +import {
2 + EnvironmentId,
3 + UsageDay,
4 + USAGE_CONTRACT_VERSION,
5 + type UsageProviderKind,
6 +} from "@t3tools/contracts";
7 import { act, useLayoutEffect } from "react";
8 import { create, type ReactTestRenderer } from "react-test-renderer";
9 import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
@@ -17,7 +22,12 @@ const input = {
22 timeZone: "UTC",
23 };
24
20 -function environment(id: string, cost: number | null, hostId = id): EnvironmentUsageStatus {
25 +function environment(
26 + id: string,
27 + cost: number | null,
28 + hostId = id,
29 + provider: UsageProviderKind = "codex",
30 +): EnvironmentUsageStatus {
31 return {
32 environmentId: EnvironmentId.make(id),
33 label: id,
@@ -35,7 +45,7 @@ function environment(id: string, cost: number | null, hostId = id): EnvironmentU
45 buckets: [
46 {
47 day: input.sinceDay,
38 - provider: "codex",
48 + provider,
49 model: id,
50 totals: {
51 uncachedInputTokens: 100,
@@ -56,7 +66,7 @@ function environment(id: string, cost: number | null, hostId = id): EnvironmentU
66 {
67 fingerprint: {
68 hostId,
59 - provider: "codex",
69 + provider,
70 resolvedHomePath: "/sessions",
71 volumeId: hostId,
72 },
@@ -77,8 +87,14 @@ function environment(id: string, cost: number | null, hostId = id): EnvironmentU
87 let renderer: ReactTestRenderer | undefined;
88 let latest: UsageView;
89
80 -function Probe({ selected }: { selected: ReadonlySet<EnvironmentId> | null }) {
81 - const usage = useUsage(input, selected);
90 +function Probe({
91 + selected,
92 + hidden,
93 +}: {
94 + selected: ReadonlySet<EnvironmentId> | null;
95 + hidden?: ReadonlySet<UsageProviderKind>;
96 +}) {
97 + const usage = useUsage(input, selected, hidden);
98 useLayoutEffect(() => {
99 latest = usage;
100 }, [usage]);
@@ -166,3 +182,17 @@ describe("usage environment selection", () => {
182 expect(latest.isPartial).toBe(false);
183 });
184 });
185 +
186 +describe("usage provider filter", () => {
187 + it("drops hidden providers from totals and sessions, then restores them", async () => {
188 + testState.environments = [environment("a", 10), environment("c", 5, "c", "claude")];
189 + await act(() => renderer?.update(<Probe selected={null} hidden={new Set(["codex"])} />));
190 + expect(latest.merged.costUsd).toBe(5);
191 + expect(latest.merged.sessions).toBe(1);
192 + expect(latest.merged.providers.map((entry) => entry.provider)).toEqual(["claude"]);
193 +
194 + await act(() => renderer?.update(<Probe selected={null} />));
195 + expect(latest.merged.costUsd).toBe(15);
196 + expect(latest.merged.sessions).toBe(2);
197 + });
198 +});
apps/web/src/state/usage.ts
+35 -1
@@ -13,6 +13,7 @@ import {
13 type EnvironmentId,
14 type UsageBucket,
15 type UsageSummary,
16 + type UsageProviderKind,
17 type UsageSummaryInput,
18 } from "@t3tools/contracts";
19 import { needsCursorKeychainAccess, refreshUsage } from "@t3tools/client-runtime/state/usage";
@@ -128,9 +129,39 @@ export function mergeAnsweredUsage(
129 return mergeUsage(answered, USAGE_CONTRACT_VERSION);
130 }
131
132 +const NO_HIDDEN_PROVIDERS: ReadonlySet<UsageProviderKind> = new Set();
133 +
134 +/**
135 + * Drops hidden providers' buckets and sources before merging, so totals,
136 + * shares, and session counts all describe only the visible providers.
137 + */
138 +function withoutProviders(
139 + environments: readonly EnvironmentUsageStatus[],
140 + hiddenProviders: ReadonlySet<UsageProviderKind>,
141 +): readonly EnvironmentUsageStatus[] {
142 + if (hiddenProviders.size === 0) return environments;
143 + return environments.map((environment) =>
144 + environment.summary === null
145 + ? environment
146 + : {
147 + ...environment,
148 + summary: {
149 + ...environment.summary,
150 + buckets: environment.summary.buckets.filter(
151 + (bucket) => !hiddenProviders.has(bucket.provider),
152 + ),
153 + sources: environment.summary.sources.filter(
154 + (source) => !hiddenProviders.has(source.fingerprint.provider),
155 + ),
156 + },
157 + },
158 + );
159 +}
160 +
161 export function useUsage(
162 input: UsageSummaryInput,
163 selectedEnvironmentIds: ReadonlySet<EnvironmentId> | null = null,
164 + hiddenProviders: ReadonlySet<UsageProviderKind> = NO_HIDDEN_PROVIDERS,
165 ): UsageView {
166 const windowKey = useMemo(
167 () =>
@@ -183,7 +214,10 @@ export function useUsage(
214 [selectedEnvironments, windowKey],
215 );
216
186 - const merged = useMemo(() => mergeAnsweredUsage(selectedEnvironments), [selectedEnvironments]);
217 + const merged = useMemo(
218 + () => mergeAnsweredUsage(withoutProviders(selectedEnvironments, hiddenProviders)),
219 + [selectedEnvironments, hiddenProviders],
220 + );
221
222 const answeredCount = selectedEnvironments.filter(
223 (environment) => environment.summary !== null,