@devries-cameron20 / t3code Mirror · read-only / commits / a91d6c8821
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 21, 23:30 UTC

fix(server): Claude effort picker marks levels capped by maxEffortLevel (#23629)

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

Julius Marminge committed Nov 11, 2026 at 11:53 UTC a91d6c8821a85f51edfc04b5afe81b3e2bb7ad38
5 files changed +603 -19
apps/server/src/provider/ClaudeModelCatalog.test.ts
+240
@@ -3,6 +3,8 @@ import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
3
4 import { resolveProviderCatalog, type ModelManifestData } from "./ModelManifest.ts";
5 import {
6 + capClaudeCatalogEffort,
7 + type ClaudeModelCatalog,
8 formatClaudeVersionUpgradeMessage,
9 getClaudeCatalogModelCapabilities,
10 normalizeClaudeCatalogEffort,
@@ -230,4 +232,242 @@ describe("Claude model catalog", () => {
232 ["claude-synthetic-next", "claude-custom-tuned"],
233 );
234 });
235 +
236 + it("marks effort options that would run above the cap without changing ids or defaults", () => {
237 + const effortModel = (slug: string) => ({
238 + slug,
239 + name: slug,
240 + isCustom: false,
241 + capabilities: {
242 + optionDescriptors: [
243 + {
244 + id: "effort",
245 + label: "Reasoning",
246 + type: "select" as const,
247 + options: [
248 + { id: "medium", label: "Medium" },
249 + { id: "high", label: "High", isDefault: true },
250 + { id: "xhigh", label: "Extra High" },
251 + { id: "max", label: "Max" },
252 + { id: "ultracode", label: "Ultracode" },
253 + { id: "ultrathink", label: "Ultrathink" },
254 + ],
255 + },
256 + ],
257 + },
258 + });
259 + const models = [effortModel("claude-plain"), effortModel("claude-remapped")];
260 + const catalog: ClaudeModelCatalog = {
261 + models: [
262 + {
263 + model: models[0]!,
264 + runtime: { effortMap: { ultracode: "xhigh", ultrathink: null } },
265 + compatibility: {},
266 + },
267 + {
268 + model: models[1]!,
269 + runtime: { effortMap: { max: "high", xhigh: "max", ultrathink: null } },
270 + compatibility: {},
271 + },
272 + ],
273 + };
274 + const options = (cap: "high" | "xhigh") =>
275 + capClaudeCatalogEffort(catalog, models, [{ maxEffortLevel: cap }]).map((model) => {
276 + const effort = model.capabilities?.optionDescriptors?.[0];
277 + return effort?.type === "select" ? effort.options : undefined;
278 + });
279 +
280 + assert.deepStrictEqual(options("high"), [
281 + [
282 + { id: "medium", label: "Medium" },
283 + { id: "high", label: "High", isDefault: true },
284 + { id: "xhigh", label: "Extra High (capped to High)" },
285 + { id: "max", label: "Max (capped to High)" },
286 + { id: "ultracode", label: "Ultracode (capped to High)" },
287 + { id: "ultrathink", label: "Ultrathink" },
288 + ],
289 + [
290 + { id: "medium", label: "Medium" },
291 + { id: "high", label: "High", isDefault: true },
292 + { id: "xhigh", label: "Extra High (capped to High)" },
293 + { id: "max", label: "Max" },
294 + { id: "ultracode", label: "Ultracode" },
295 + { id: "ultrathink", label: "Ultrathink" },
296 + ],
297 + ]);
298 + // An effortMap that sends Extra High as max stays unmarked under an xhigh cap: the CLI runs
299 + // it at xhigh, which is what the label says.
300 + assert.deepStrictEqual(
301 + options("xhigh").map((model) => model?.map((option) => option.label)),
302 + [
303 + ["Medium", "High", "Extra High", "Max (capped to Extra High)", "Ultracode", "Ultrathink"],
304 + ["Medium", "High", "Extra High", "Max", "Ultracode", "Ultrathink"],
305 + ],
306 + );
307 +
308 + // A per-model cap applies without a top-level one and leaves other models uncapped.
309 + assert.deepStrictEqual(
310 + capClaudeCatalogEffort(catalog, models, [
311 + { modelMaxEffortLevels: new Map([["claude-plain", "high"]]) },
312 + ]).map((model) => {
313 + const effort = model.capabilities?.optionDescriptors?.[0];
314 + return effort?.type === "select" ? effort.options.map((option) => option.label) : [];
315 + }),
316 + [
317 + [
318 + "Medium",
319 + "High",
320 + "Extra High (capped to High)",
321 + "Max (capped to High)",
322 + "Ultracode (capped to High)",
323 + "Ultrathink",
324 + ],
325 + ["Medium", "High", "Extra High", "Max", "Ultracode", "Ultrathink"],
326 + ],
327 + );
328 +
329 + // Without an Extra High option (Opus 4.6), the CLI clamps an xhigh cap down to High.
330 + const noXhigh = {
331 + slug: "claude-no-xhigh",
332 + name: "claude-no-xhigh",
333 + isCustom: false,
334 + capabilities: {
335 + optionDescriptors: [
336 + {
337 + id: "effort",
338 + label: "Reasoning",
339 + type: "select" as const,
340 + options: [
341 + { id: "low", label: "Low" },
342 + { id: "medium", label: "Medium" },
343 + { id: "high", label: "High", isDefault: true },
344 + { id: "max", label: "Max" },
345 + ],
346 + },
347 + ],
348 + },
349 + };
350 + const [capped] = capClaudeCatalogEffort(
351 + { models: [] },
352 + [noXhigh],
353 + [{ maxEffortLevel: "xhigh" }],
354 + );
355 + const cappedEffort = capped?.capabilities?.optionDescriptors?.[0];
356 + assert.deepStrictEqual(
357 + cappedEffort?.type === "select" ? cappedEffort.options.map((option) => option.label) : [],
358 + ["Low", "Medium", "High", "Max (capped to High)"],
359 + );
360 + });
361 +
362 + it("leaves custom model effort labels alone under a cap", () => {
363 + const custom = {
364 + slug: "claude-custom-copy",
365 + name: "Copy",
366 + isCustom: true,
367 + capabilities: {
368 + optionDescriptors: [
369 + {
370 + id: "effort",
371 + label: "Reasoning",
372 + type: "select" as const,
373 + options: [
374 + { id: "high", label: "High", isDefault: true },
375 + { id: "max", label: "Max (capped to High)" },
376 + ],
377 + },
378 + ],
379 + },
380 + };
381 +
382 + assert.deepStrictEqual(
383 + capClaudeCatalogEffort({ models: [] }, [custom], [{ maxEffortLevel: "high" }]),
384 + [custom],
385 + );
386 + });
387 +
388 + it("resolves maxEffortLevel per settings source and per model key like Claude Code", () => {
389 + const opus = {
390 + slug: "claude-opus-5-5",
391 + name: "Opus 5.5",
392 + isCustom: false,
393 + aliases: ["opus", "opus-5.5", "claude-opus-5.5"],
394 + capabilities: {
395 + optionDescriptors: [
396 + {
397 + id: "effort",
398 + label: "Reasoning",
399 + type: "select" as const,
400 + options: [
401 + { id: "low", label: "Low" },
402 + { id: "medium", label: "Medium" },
403 + { id: "high", label: "High", isDefault: true },
404 + { id: "max", label: "Max" },
405 + ],
406 + },
407 + ],
408 + },
409 + };
410 + const catalog: ClaudeModelCatalog = {
411 + models: [
412 + { model: opus, runtime: {}, compatibility: {} },
413 + {
414 + model: {
415 + slug: "claude-opus-5",
416 + name: "Opus 5",
417 + isCustom: false,
418 + capabilities: { optionDescriptors: [] },
419 + },
420 + runtime: {},
421 + compatibility: {},
422 + },
423 + ],
424 + };
425 + const maxLabel = (sources: Parameters<typeof capClaudeCatalogEffort>[2]) => {
426 + const effort = capClaudeCatalogEffort(catalog, [opus], sources)[0]?.capabilities
427 + ?.optionDescriptors?.[0];
428 + return effort?.type === "select" ? effort.options.at(-1)?.label : undefined;
429 + };
430 + const perModel = (entries: Record<string, "low" | "medium" | "high" | "max">) => ({
431 + modelMaxEffortLevels: new Map(Object.entries(entries)),
432 + });
433 +
434 + // Claude Code matches family aliases and [1m] spellings case-insensitively.
435 + assert.strictEqual(maxLabel([perModel({ Opus: "medium" })]), "Max (capped to Medium)");
436 + assert.strictEqual(
437 + maxLabel([perModel({ "claude-opus-5-5[1M]": "medium" })]),
438 + "Max (capped to Medium)",
439 + );
440 + assert.strictEqual(maxLabel([perModel({ " OPUS[1m] ": "medium" })]), "Max (capped to Medium)");
441 + // Other keys name the most specific model id they contain, so dated and provider-prefixed ids
442 + // match while the catalog's dotted aliases and a less specific model id do not.
443 + for (const key of [
444 + "claude-opus-5-5-20260101",
445 + "CLAUDE-OPUS-5-5-20260101[1m]",
446 + "us.anthropic.claude-opus-5-5-v1:0",
447 + "claude-opus-5-5-latest",
448 + ]) {
449 + assert.strictEqual(maxLabel([perModel({ [key]: "medium" })]), "Max (capped to Medium)", key);
450 + }
451 + for (const key of ["claude-opus-5.5", "opus-5.5", "opus-5-5", "opus [1m]", "claude-opus-5"]) {
452 + assert.strictEqual(maxLabel([perModel({ [key]: "medium" })]), "Max", key);
453 + }
454 + // Keys naming the same model keep the lowest cap, and a `max` key does not exempt it.
455 + assert.strictEqual(
456 + maxLabel([perModel({ opus: "max", "claude-opus-5-5": "low" })]),
457 + "Max (capped to Low)",
458 + );
459 + // A per-model `max` only exempts the model from its own source's top-level cap.
460 + assert.strictEqual(
461 + maxLabel([{ maxEffortLevel: "medium", ...perModel({ opus: "max" }) }]),
462 + "Max",
463 + );
464 + assert.strictEqual(
465 + maxLabel([perModel({ opus: "max" }), { maxEffortLevel: "high" }]),
466 + "Max (capped to High)",
467 + );
468 + assert.strictEqual(
469 + maxLabel([{ maxEffortLevel: "medium" }, perModel({ opus: "high" })]),
470 + "Max (capped to Medium)",
471 + );
472 + });
473 });
apps/server/src/provider/ClaudeModelCatalog.ts
+132 -1
@@ -322,6 +322,137 @@ export function formatClaudeVersionUpgradeMessage(
322 return `Claude Code ${versionLabel} is too old for ${unavailable.model.name}. Upgrade to v${unavailable.compatibility.minVersion} or newer to access it.`;
323 }
324
325 +/** Claude Code's effort levels, lowest first. */
326 +export const CLAUDE_EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"] as const;
327 +export type ClaudeEffortLevel = (typeof CLAUDE_EFFORT_LEVELS)[number];
328 +
329 +function claudeEffortRank(level: string | undefined): number {
330 + return CLAUDE_EFFORT_LEVELS.indexOf(level as ClaudeEffortLevel);
331 +}
332 +
333 +/** One settings source's effort caps, with `modelSettings` keys as the user wrote them. */
334 +export interface ClaudeEffortCapSource {
335 + readonly maxEffortLevel?: ClaudeEffortLevel;
336 + readonly modelMaxEffortLevels?: ReadonlyMap<string, ClaudeEffortLevel>;
337 +}
338 +
339 +const CLAUDE_1M_SUFFIX = "[1m]";
340 +const CLAUDE_CODE_FAMILY_ALIASES: ReadonlySet<string> = new Set([
341 + "opus",
342 + "sonnet",
343 + "haiku",
344 + "fable",
345 +]);
346 +
347 +/**
348 + * Names the model a `modelSettings` key caps the way Claude Code does, which is narrower than the
349 + * catalog's aliases: only a family alias (optionally `[1m]`) resolves as an alias, and any other key
350 + * names the most specific model id it contains, so `claude-opus-5-5-20260101` and Bedrock ids match
351 + * while `claude-opus-5.5` matches nothing.
352 + */
353 +function resolveClaudeModelSettingsKey(
354 + catalog: ClaudeModelCatalog,
355 + key: string,
356 +): string | undefined {
357 + const lowered = key.trim().toLowerCase();
358 + const unsuffixed = lowered.endsWith(CLAUDE_1M_SUFFIX)
359 + ? lowered.slice(0, -CLAUDE_1M_SUFFIX.length)
360 + : lowered;
361 + if (CLAUDE_CODE_FAMILY_ALIASES.has(unsuffixed)) {
362 + return catalog.models.find(
363 + (entry) => !entry.model.isCustom && entry.model.aliases?.includes(unsuffixed),
364 + )?.model.slug;
365 + }
366 + let match: string | undefined;
367 + for (const { model } of catalog.models) {
368 + if (!model.isCustom && lowered.includes(model.slug) && model.slug.length > (match?.length ?? 0))
369 + match = model.slug;
370 + }
371 + return match;
372 +}
373 +
374 +/** Keys `modelSettings` caps by canonical slug, keeping the lowest cap when several keys name one model. */
375 +function resolveClaudeModelMaxEffortLevels(
376 + catalog: ClaudeModelCatalog,
377 + levels: ReadonlyMap<string, ClaudeEffortLevel> | undefined,
378 +): ReadonlyMap<string, ClaudeEffortLevel> {
379 + const resolved = new Map<string, ClaudeEffortLevel>();
380 + for (const [key, level] of levels ?? []) {
381 + const slug = resolveClaudeModelSettingsKey(catalog, key);
382 + if (!slug) continue;
383 + const current = resolved.get(slug);
384 + if (!current || claudeEffortRank(level) < claudeEffortRank(current)) resolved.set(slug, level);
385 + }
386 + return resolved;
387 +}
388 +
389 +/**
390 + * Claude Code clamps efforts above `maxEffortLevel` to the model's highest level under it, so
391 + * such options are relabelled, not removed, keeping stored selections valid. Per-model caps
392 + * replace their own source's top-level cap and `max` means none; across sources the lowest wins.
393 + */
394 +export function capClaudeCatalogEffort(
395 + catalog: ClaudeModelCatalog,
396 + models: ReadonlyArray<ServerProviderModel>,
397 + sources: ReadonlyArray<ClaudeEffortCapSource>,
398 +): ReadonlyArray<ServerProviderModel> {
399 + if (sources.length === 0) return models;
400 + const resolvedSources = sources.map((source) => ({
401 + maxEffortLevel: source.maxEffortLevel,
402 + modelMaxEffortLevels: resolveClaudeModelMaxEffortLevels(catalog, source.modelMaxEffortLevels),
403 + }));
404 + return models.map((model) => {
405 + // Custom model labels are user-authored, so they are left alone.
406 + if (model.isCustom || !model.capabilities?.optionDescriptors) return model;
407 + const modelMaxEffortLevel = resolvedSources.reduce<ClaudeEffortLevel | undefined>(
408 + (lowest, source) => {
409 + const level = source.modelMaxEffortLevels.get(model.slug) ?? source.maxEffortLevel;
410 + return level &&
411 + level !== "max" &&
412 + (!lowest || claudeEffortRank(level) < claudeEffortRank(lowest))
413 + ? level
414 + : lowest;
415 + },
416 + undefined,
417 + );
418 + if (!modelMaxEffortLevel) return model;
419 + const capRank = claudeEffortRank(modelMaxEffortLevel);
420 + return {
421 + ...model,
422 + capabilities: {
423 + ...model.capabilities,
424 + optionDescriptors: model.capabilities.optionDescriptors.map((descriptor) => {
425 + if (descriptor.id !== "effort" || descriptor.type !== "select") return descriptor;
426 + const cap = descriptor.options.reduce<{ rank: number; label: string } | undefined>(
427 + (best, option) => {
428 + const rank = claudeEffortRank(option.id);
429 + return rank >= 0 && rank <= capRank && rank > (best?.rank ?? -1)
430 + ? { rank, label: option.label }
431 + : best;
432 + },
433 + undefined,
434 + );
435 + if (!cap) return descriptor;
436 + return {
437 + ...descriptor,
438 + options: descriptor.options.map((option) => {
439 + const idRank = claudeEffortRank(option.id);
440 + const sentRank = claudeEffortRank(
441 + normalizeClaudeCatalogEffort(catalog, option.id, model.slug),
442 + );
443 + const displayedRank = idRank >= 0 ? idRank : sentRank;
444 + const runsRank = sentRank >= 0 ? sentRank : idRank;
445 + return displayedRank > cap.rank && runsRank > cap.rank
446 + ? { ...option, label: `${option.label} (capped to ${cap.label})` }
447 + : option;
448 + }),
449 + };
450 + }),
451 + },
452 + };
453 + });
454 +}
455 +
456 export function resolveClaudeCatalogEffort(
457 catalog: ClaudeModelCatalog,
458 model: string | null | undefined,
@@ -329,7 +460,7 @@ export function resolveClaudeCatalogEffort(
460 ): string | undefined {
461 if (!resolveClaudeCatalogModel(catalog, model)) {
462 const effort = raw?.trim();
332 - return effort && ["low", "medium", "high", "xhigh", "max"].includes(effort)
463 + return effort && (CLAUDE_EFFORT_LEVELS as ReadonlyArray<string>).includes(effort)
464 ? effort
465 : undefined;
466 }
apps/server/src/provider/ClaudeProvider.ts
+110 -18
@@ -59,6 +59,10 @@ import {
59 } from "./claudeUsageLimits.ts";
60 import {
61 BUNDLED_CLAUDE_MODEL_CATALOG,
62 + CLAUDE_EFFORT_LEVELS,
63 + capClaudeCatalogEffort,
64 + type ClaudeEffortCapSource,
65 + type ClaudeEffortLevel,
66 type ClaudeModelCatalog,
67 claudeReportedModels,
68 formatClaudeVersionUpgradeMessage,
@@ -272,8 +276,73 @@ export type ClaudeCapabilitiesProbe = {
276 /** Undefined means get_usage failed; absent windows on success mean no subscription windows, as with API keys. */
277 readonly usage?: Pick<SDKControlGetUsageResponse, "rate_limits_available" | "rate_limits">;
278 readonly usageCheckedAt?: string;
279 + /** Each settings source's `maxEffortLevel` caps; Claude Code clamps every higher effort. */
280 + readonly effortCapSources?: ReadonlyArray<ClaudeEffortCapSource>;
281 };
282
283 +// `getSettings` exists at runtime but is missing from the SDK's `Query` type, and older CLIs
284 +// reject the control request.
285 +type ClaudeSettingsQuery = {
286 + readonly getSettings?: () => Promise<{
287 + readonly effective?: unknown;
288 + readonly sources?: unknown;
289 + }>;
290 +};
291 +
292 +function parseClaudeMaxEffortLevel(value: unknown): ClaudeEffortLevel | undefined {
293 + return CLAUDE_EFFORT_LEVELS.find((level) => level === value);
294 +}
295 +
296 +function parseClaudeModelMaxEffortLevels(
297 + modelSettings: unknown,
298 +): ReadonlyMap<string, ClaudeEffortLevel> | undefined {
299 + if (!modelSettings || typeof modelSettings !== "object") return undefined;
300 + const levels = new Map<string, ClaudeEffortLevel>();
301 + for (const [model, settings] of Object.entries(modelSettings)) {
302 + const level = parseClaudeMaxEffortLevel(
303 + settings && typeof settings === "object"
304 + ? (settings as { readonly maxEffortLevel?: unknown }).maxEffortLevel
305 + : undefined,
306 + );
307 + if (level) levels.set(model, level);
308 + }
309 + return levels.size > 0 ? levels : undefined;
310 +}
311 +
312 +function parseClaudeEffortCapSource(settings: unknown): ClaudeEffortCapSource | undefined {
313 + if (!settings || typeof settings !== "object") return undefined;
314 + const { maxEffortLevel, modelSettings } = settings as {
315 + readonly maxEffortLevel?: unknown;
316 + readonly modelSettings?: unknown;
317 + };
318 + const level = parseClaudeMaxEffortLevel(maxEffortLevel);
319 + const modelMaxEffortLevels = parseClaudeModelMaxEffortLevels(modelSettings);
320 + return level || modelMaxEffortLevels
321 + ? {
322 + ...(level ? { maxEffortLevel: level } : {}),
323 + ...(modelMaxEffortLevels ? { modelMaxEffortLevels } : {}),
324 + }
325 + : undefined;
326 +}
327 +
328 +// `sources` holds each settings file's raw settings. CLIs that report only the merged `effective`
329 +// settings are read as a single source.
330 +function parseClaudeEffortCapSources(
331 + settings: { readonly effective?: unknown; readonly sources?: unknown } | undefined,
332 +): ReadonlyArray<ClaudeEffortCapSource> | undefined {
333 + const sources = Array.isArray(settings?.sources)
334 + ? settings.sources.flatMap((source) => {
335 + const parsed = parseClaudeEffortCapSource(
336 + source && typeof source === "object"
337 + ? (source as { readonly settings?: unknown }).settings
338 + : undefined,
339 + );
340 + return parsed ? [parsed] : [];
341 + })
342 + : [parseClaudeEffortCapSource(settings?.effective)].filter((source) => source !== undefined);
343 + return sources.length > 0 ? sources : undefined;
344 +}
345 +
346 function parseClaudeInitializationCommands(
347 commands: ReadonlyArray<ClaudeSlashCommand> | undefined,
348 ): ReadonlyArray<ServerProviderSlashCommand> {
@@ -362,7 +431,7 @@ function claudeGatewayDiscoveryGraceMs(environment: Readonly<Record<string, unkn
431
432 class ClaudeCapabilitiesProbeSdkError extends Schema.TaggedError<ClaudeCapabilitiesProbeSdkError>()(
433 "ClaudeCapabilitiesProbeSdkError",
365 - { operation: Schema.Literals(["initialize", "usage"]), cause: Schema.Defect() },
434 + { operation: Schema.Literals(["initialize", "usage", "settings"]), cause: Schema.Defect() },
435 ) {
436 override get message(): string {
437 return `Claude capability probe ${this.operation} failed.`;
@@ -374,7 +443,7 @@ const probeClaudeCapabilities = (
443 claudeSettings: ClaudeSettings,
444 environment?: NodeJS.ProcessEnv,
445 cwd?: string,
377 - includeUsage = true,
446 + includeStatus = true,
447 ) => {
448 const abort = new AbortController();
449 const abortProbe = Effect.sync(() => {
@@ -388,7 +457,7 @@ const probeClaudeCapabilities = (
457 );
458 const managedMcpConfig = yield* hasClaudeManagedMcpConfig();
459 // Workspace probes (no usage) discard models; the machine probe refreshes the shared cache.
391 - const graceMs = includeUsage
460 + const graceMs = includeStatus
461 ? claudeGatewayDiscoveryGraceMs({
462 ...claudeEnvironment,
463 ...(yield* readClaudeSettingsEnv(claudeSettings, cwd, claudeEnvironment)),
@@ -421,16 +490,31 @@ const probeClaudeCapabilities = (
490 // Usage has its own deadline so a slow optional request cannot discard initialization.
491 // Only the rate limits are read, so skip the local transcript scan that fills
492 // `behaviors`: with a few GB of transcripts it outlasts the deadline.
493 + // The effort caps are read in parallel under the same deadline; workspace probes skip both.
494 const usageCheckedAt = DateTime.formatIso(yield* DateTime.now);
425 - const usageResult = includeUsage
426 - ? yield* Effect.tryPromise({
427 - try: () =>
428 - q.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET({
429 - skipBehaviors: true,
430 - }),
431 - catch: (cause) => new ClaudeCapabilitiesProbeSdkError({ operation: "usage", cause }),
432 - }).pipe(Effect.timeout(DEFAULT_TIMEOUT_MS), Effect.result)
433 - : undefined;
495 + const { getSettings } = q as ClaudeSettingsQuery;
496 + const [usageResult, settingsResult] = yield* Effect.all(
497 + [
498 + includeStatus
499 + ? Effect.tryPromise({
500 + try: () =>
501 + q.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET({
502 + skipBehaviors: true,
503 + }),
504 + catch: (cause) =>
505 + new ClaudeCapabilitiesProbeSdkError({ operation: "usage", cause }),
506 + }).pipe(Effect.timeout(DEFAULT_TIMEOUT_MS), Effect.result)
507 + : Effect.undefined,
508 + includeStatus && getSettings
509 + ? Effect.tryPromise({
510 + try: () => getSettings.call(q),
511 + catch: (cause) =>
512 + new ClaudeCapabilitiesProbeSdkError({ operation: "settings", cause }),
513 + }).pipe(Effect.timeout(DEFAULT_TIMEOUT_MS), Effect.result)
514 + : Effect.undefined,
515 + ],
516 + { concurrency: "unbounded" },
517 + );
518 const usage =
519 usageResult && Result.isSuccess(usageResult)
520 ? {
@@ -438,6 +522,9 @@ const probeClaudeCapabilities = (
522 rate_limits: usageResult.success.rate_limits,
523 }
524 : undefined;
525 + const effortCapSources = parseClaudeEffortCapSources(
526 + settingsResult && Result.isSuccess(settingsResult) ? settingsResult.success : undefined,
527 + );
528 const account = init.account as
529 | {
530 readonly email?: string;
@@ -456,6 +543,7 @@ const probeClaudeCapabilities = (
543 slashCommands: parseClaudeInitializationCommands(init.commands),
544 ...(init.models?.length ? { models: init.models } : {}),
545 ...(usage ? { usage, usageCheckedAt } : {}),
546 + ...(effortCapSources ? { effortCapSources } : {}),
547 } satisfies ClaudeCapabilitiesProbe;
548 }).pipe(
549 Effect.tap(() =>
@@ -637,12 +725,16 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")(
725 probeResult && Result.isSuccess(probeResult) ? probeResult.success : undefined;
726 const probeFailure =
727 probeResult && Result.isFailure(probeResult) ? probeResult.failure : undefined;
640 - const models = claudeProviderModels(
641 - [
642 - ...resolveClaudeModelsForVersion(modelCatalog, parsedVersion),
643 - ...claudeReportedModels(modelCatalog, claudeSettings.customModels, capabilities?.models),
644 - ],
645 - claudeSettings.customModels,
728 + const models = capClaudeCatalogEffort(
729 + modelCatalog,
730 + claudeProviderModels(
731 + [
732 + ...resolveClaudeModelsForVersion(modelCatalog, parsedVersion),
733 + ...claudeReportedModels(modelCatalog, claudeSettings.customModels, capabilities?.models),
734 + ],
735 + claudeSettings.customModels,
736 + ),
737 + capabilities?.effortCapSources ?? [],
738 );
739 const skills = yield* discoverClaudeSkills(claudeSettings, cwd, resolvedEnvironment);
740 const slashCommands = [COMPACT_SLASH_COMMAND, ...(capabilities?.slashCommands ?? [])];
apps/server/src/provider/ProviderInstanceRegistry.test.ts
+87
@@ -468,6 +468,93 @@ describe("ProviderInstanceRegistry — multi-instance codex slice", () => {
468 }).pipe(Effect.provide(layerTest)),
469 );
470
471 + it.live("applies the lowest maxEffortLevel across Claude's settings sources", () =>
472 + Effect.gen(function* () {
473 + if (yield* HostProcess.isWindows) return;
474 +
475 + const fixtures = yield* makeTildeProviderFixtures();
476 + const claudeId = ProviderInstanceId.make("claude_source_effort_cap");
477 + const { registry } = yield* makeProviderInstanceRegistry<ClaudeDriverEnv>({
478 + drivers: [ClaudeDriver],
479 + configMap: {
480 + [claudeId]: {
481 + driver: ProviderDriverKind.make("claudeAgent"),
482 + enabled: true,
483 + environment: [
484 + {
485 + name: "T3_CLAUDE_SETTINGS_SOURCES",
486 + // The merged `effective` settings read as exempting Opus 5; the flag tier's
487 + // top-level cap still applies to it.
488 + value: JSON.stringify([
489 + {
490 + source: "userSettings",
491 + settings: { modelSettings: { "claude-opus-5": { maxEffortLevel: "max" } } },
492 + },
493 + { source: "flagSettings", settings: { maxEffortLevel: "high" } },
494 + ]),
495 + sensitive: false,
496 + },
497 + ],
498 + config: makeClaudeConfig({
499 + enabled: true,
500 + binaryPath: fixtures.claudeBinaryPath,
501 + homePath: fixtures.claudeHomePath,
502 + }),
503 + },
504 + },
505 + });
506 + const claude = yield* registry.getInstance(claudeId);
507 +
508 + const snapshot = yield* claude!.snapshot.refresh;
509 + const maxLabel = snapshot.models
510 + .find((model) => model.slug === "claude-opus-5")
511 + ?.capabilities?.optionDescriptors?.flatMap((descriptor) =>
512 + descriptor.id === "effort" && descriptor.type === "select"
513 + ? descriptor.options.filter((option) => option.id === "max")
514 + : [],
515 + )[0]?.label;
516 + expect(maxLabel).toBe("Max (capped to High)");
517 + }).pipe(Effect.provide(layerTest)),
518 + );
519 +
520 + it.live("keeps usage and uncapped efforts when the CLI rejects get_settings", () =>
521 + Effect.gen(function* () {
522 + if (yield* HostProcess.isWindows) return;
523 +
524 + const fixtures = yield* makeTildeProviderFixtures();
525 + const claudeId = ProviderInstanceId.make("claude_settings_unsupported");
526 + const { registry } = yield* makeProviderInstanceRegistry<ClaudeDriverEnv>({
527 + drivers: [ClaudeDriver],
528 + configMap: {
529 + [claudeId]: {
530 + driver: ProviderDriverKind.make("claudeAgent"),
531 + enabled: true,
532 + environment: [{ name: "T3_CLAUDE_SETTINGS_UNSUPPORTED", value: "1", sensitive: false }],
533 + config: makeClaudeConfig({
534 + enabled: true,
535 + binaryPath: fixtures.claudeBinaryPath,
536 + homePath: fixtures.claudeHomePath,
537 + }),
538 + },
539 + },
540 + });
541 + const claude = yield* registry.getInstance(claudeId);
542 +
543 + const snapshot = yield* claude!.snapshot.refresh;
544 + const effortLabels = snapshot.models.flatMap((model) =>
545 + (model.capabilities?.optionDescriptors ?? []).flatMap((descriptor) =>
546 + descriptor.id === "effort" && descriptor.type === "select"
547 + ? descriptor.options.map((option) => option.label)
548 + : [],
549 + ),
550 + );
551 + expect(effortLabels).toContain("Max");
552 + expect(effortLabels.some((label) => label.includes("capped"))).toBe(false);
553 + expect(snapshot.auth).toMatchObject({ status: "authenticated", email: "test@example.com" });
554 + expect(snapshot.usageLimits?.windows[0]?.usedPercent).toBe(100);
555 + }).pipe(Effect.provide(layerTest)),
556 + );
557 +
558 it.effect("scopes Claude's one-probe fallback to the logged-in organization", () =>
559 Effect.gen(function* () {
560 if (yield* HostProcess.isWindows) return;
apps/server/src/provider/testing/ProviderInstanceRegistryLive.fixture.mjs
+34
@@ -68,6 +68,40 @@ lines.on("line", (line) => {
68 );
69 return;
70 }
71 + if (message.request?.subtype === "get_settings" && process.env.T3_CLAUDE_SETTINGS_UNSUPPORTED) {
72 + process.stdout.write(
73 + JSON.stringify({
74 + type: "control_response",
75 + response: {
76 + subtype: "error",
77 + request_id: message.request_id,
78 + error: "Unsupported control request subtype: get_settings",
79 + },
80 + }) + "\n",
81 + );
82 + return;
83 + }
84 + if (message.request?.subtype === "get_settings") {
85 + const sources = JSON.parse(process.env.T3_CLAUDE_SETTINGS_SOURCES ?? "[]");
86 + // Like Claude Code, `effective` is the last-writer merge, which hides per-source caps.
87 + const effective = { modelSettings: {} };
88 + for (const { settings } of sources) {
89 + Object.assign(effective, settings, {
90 + modelSettings: Object.assign(effective.modelSettings, settings.modelSettings),
91 + });
92 + }
93 + process.stdout.write(
94 + JSON.stringify({
95 + type: "control_response",
96 + response: {
97 + subtype: "success",
98 + request_id: message.request_id,
99 + response: { effective, sources },
100 + },
101 + }) + "\n",
102 + );
103 + return;
104 + }
105 if (message.request?.subtype !== "initialize") return;
106 process.stdout.write(
107 JSON.stringify({