The best way to control Claude Code, Codex and more from any computer or phone
fix(claude): turns use the downloaded model catalog (#31717)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 5, 2026 at 16:22 UTC
43cf364dd25e2ee5f5ff76de69b6a0676e27b813
3 files changed
+90
-42
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+71
-35
@@ -93,6 +93,10 @@ import { WorktreeToolkit } from "../../mcp/toolkits/worktree/tools.ts";
93
import { ThreadToolkit } from "../../mcp/toolkits/thread/tools.ts";
94
import { OrchestratorToolkit } from "../../mcp/toolkits/orchestrator/tools.ts";
95
import { ClaudeExecutableFileCheck } from "../../provider/Drivers/ClaudeExecutable.ts";
96
+import {
97
+ BUNDLED_CLAUDE_MODEL_CATALOG,
98
+ type ClaudeModelCatalog,
99
+} from "../../provider/ClaudeModelCatalog.ts";
100
import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers";
101
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
102
import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests";
@@ -3151,6 +3155,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
3155
readonly subagentLaunchToolUseId?: string;
3156
readonly nativeSessionId?: string;
3157
readonly settings?: ClaudeSettings;
3158
+ readonly modelCatalog?: Effect.Effect<ClaudeModelCatalog>;
3159
readonly freshQueueOnReopen?: boolean;
3160
readonly forkSession?: ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerShape["forkSession"];
3161
readonly allocateSessionId?: Effect.Effect<string>;
@@ -3210,6 +3215,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
3215
const adapter = yield* ClaudeAdapterV2.makeClaudeAdapterV2({
3216
instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
3217
settings: options?.settings ?? DEFAULT_CLAUDE_SETTINGS,
3218
+ ...(options?.modelCatalog === undefined ? {} : { modelCatalog: options.modelCatalog }),
3219
environment: options?.environment ?? {},
3220
attachmentsDir,
3221
fileSystem,
@@ -14892,44 +14898,74 @@ describe("ClaudeAdapterV2 background wake turns", () => {
14898
),
14899
);
14900
14895
- it.effect("sends Ultracode with any effort on a custom model", () =>
14896
- Effect.scoped(
14897
- Effect.gen(function* () {
14898
- const harness = yield* makeWakeHarnessWithOptions({
14899
- settings: ULTRACODE_CUSTOM_MODEL_CLAUDE_SETTINGS,
14900
- });
14901
- yield* harness.runtime.startTurn(
14902
- makeClaudeTestTurnInput({
14903
- threadId: harness.threadId,
14904
- providerThread: harness.providerThread,
14905
- now: yield* DateTime.now,
14906
- attemptId: RunAttemptId.make("attempt-custom-ultracode"),
14907
- text: "Plan the work.",
14908
- attachments: [],
14909
- modelSelection: {
14910
- instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
14911
- model: "claude-custom-tuned",
14912
- options: [
14913
- { id: "effort", value: "high" },
14914
- { id: "ultracode", value: true },
14915
- ],
14916
- },
14917
- }),
14918
- );
14919
- const options = harness.getOpenedOptions()!;
14920
- assert.equal(options.effort, "high");
14921
- assert.equal((options.settings as { ultracode?: boolean }).ultracode, true);
14922
- }).pipe(
14923
- Effect.provide(
14924
- Layer.mergeAll(
14925
- IdAllocator.layer,
14926
- McpProviderSessions.layer,
14927
- NodeServices.layer,
14928
- NodeCrypto.layer,
14901
+ it.effect.each([
14902
+ {
14903
+ source: "custom model",
14904
+ model: "claude-custom-tuned",
14905
+ harness: { settings: ULTRACODE_CUSTOM_MODEL_CLAUDE_SETTINGS },
14906
+ },
14907
+ {
14908
+ source: "downloaded catalog",
14909
+ model: "claude-sonnet-5",
14910
+ harness: {
14911
+ modelCatalog: Effect.succeed({
14912
+ models: BUNDLED_CLAUDE_MODEL_CATALOG.models.map((entry) =>
14913
+ entry.model.slug === "claude-sonnet-5"
14914
+ ? {
14915
+ ...entry,
14916
+ model: {
14917
+ ...entry.model,
14918
+ capabilities: {
14919
+ optionDescriptors: [
14920
+ ...(entry.model.capabilities?.optionDescriptors ?? []),
14921
+ { id: "ultracode", label: "Ultracode", type: "boolean" as const },
14922
+ ],
14923
+ },
14924
+ },
14925
+ }
14926
+ : entry,
14927
+ ),
14928
+ }),
14929
+ },
14930
+ },
14931
+ ])(
14932
+ "sends Ultracode with any effort on a model from the $source",
14933
+ ({ harness: harnessOptions, model }) =>
14934
+ Effect.scoped(
14935
+ Effect.gen(function* () {
14936
+ const harness = yield* makeWakeHarnessWithOptions(harnessOptions);
14937
+ yield* harness.runtime.startTurn(
14938
+ makeClaudeTestTurnInput({
14939
+ threadId: harness.threadId,
14940
+ providerThread: harness.providerThread,
14941
+ now: yield* DateTime.now,
14942
+ attemptId: RunAttemptId.make("attempt-custom-ultracode"),
14943
+ text: "Plan the work.",
14944
+ attachments: [],
14945
+ modelSelection: {
14946
+ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
14947
+ model,
14948
+ options: [
14949
+ { id: "effort", value: "high" },
14950
+ { id: "ultracode", value: true },
14951
+ ],
14952
+ },
14953
+ }),
14954
+ );
14955
+ const options = harness.getOpenedOptions()!;
14956
+ assert.equal(options.effort, "high");
14957
+ assert.equal((options.settings as { ultracode?: boolean }).ultracode, true);
14958
+ }).pipe(
14959
+ Effect.provide(
14960
+ Layer.mergeAll(
14961
+ IdAllocator.layer,
14962
+ McpProviderSessions.layer,
14963
+ NodeServices.layer,
14964
+ NodeCrypto.layer,
14965
+ ),
14966
),
14967
),
14968
),
14932
- ),
14969
);
14970
14971
it.effect("resolves a subagent's model and effort against the instance's custom models", () =>
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+14
-6
@@ -4830,6 +4830,7 @@ function claudeProposedPlan(input: unknown): string | null {
4830
export interface ClaudeAdapterV2Options {
4831
readonly instanceId: ProviderInstanceId;
4832
readonly settings: ClaudeSettings;
4833
+ readonly modelCatalog?: Effect.Effect<ClaudeModelCatalog>;
4834
readonly environment: NodeJS.ProcessEnv;
4835
readonly attachmentsDir: string;
4836
readonly fileSystem: FileSystem.FileSystem;
@@ -4853,15 +4854,20 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
4854
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
4855
const serverSettings = yield* Effect.serviceOption(ServerSettings.ServerSettingsService);
4856
const { attachmentsDir, fileSystem, path, random, idAllocator, queryRunner } = adapterOptions;
4856
- const modelCatalog = scopeClaudeModelCatalog(
4857
- BUNDLED_CLAUDE_MODEL_CATALOG,
4858
- adapterOptions.settings.customModels,
4857
+ const loadModelCatalog = (
4858
+ adapterOptions.modelCatalog ?? Effect.succeed(BUNDLED_CLAUDE_MODEL_CATALOG)
4859
+ ).pipe(
4860
+ Effect.map((catalog) => scopeClaudeModelCatalog(catalog, adapterOptions.settings.customModels)),
4861
);
4862
+ // Reloaded at each turn and steer so downloaded manifest updates apply without a release.
4863
+ let modelCatalog = yield* loadModelCatalog;
4864
// Results report the window Claude Code compacts against; outside the catalog it is the only source.
4865
const reportedContextWindows = new Map<string, number>();
4866
const claudeContextWindow = (modelSelection: ModelSelection): number | null =>
4863
- resolveClaudeCatalogContextWindowTokens(BUNDLED_CLAUDE_MODEL_CATALOG, modelSelection) ??
4864
- reportedContextWindows.get(compileClaudeModelSelection(modelSelection).apiModelId) ??
4867
+ resolveClaudeCatalogContextWindowTokens(modelCatalog, modelSelection) ??
4868
+ reportedContextWindows.get(
4869
+ compileClaudeModelSelection(modelSelection, modelCatalog).apiModelId,
4870
+ ) ??
4871
null;
4872
const continuationRequests = adapterOptions.continuationRequests ?? {
4873
offer: () => Effect.void,
@@ -11047,6 +11053,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
11053
11054
const startTurn = Effect.fn("ClaudeAdapterV2.startTurn")(
11055
function* (turnInput: ProviderAdapter.ProviderAdapterV2TurnInput) {
11056
+ modelCatalog = yield* loadModelCatalog;
11057
const startedAt = yield* DateTime.now;
11058
const nativeThreadId = yield* getNativeThreadId(turnInput.providerThread);
11059
const nativeTurnId = `turn:${turnInput.attemptId}`;
@@ -11525,6 +11532,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
11532
11533
const steerTurn = Effect.fn("ClaudeAdapterV2.steerTurn")(
11534
function* (turnInput: ProviderAdapter.ProviderAdapterV2SteerInput) {
11535
+ modelCatalog = yield* loadModelCatalog;
11536
// Measured from the request, not from when the moves are forked:
11537
// building the message and the moves can take clock time a timer
11538
// started later would not count, and the steer would wait past it.
@@ -12285,7 +12293,7 @@ export type ClaudeAdapterV2DriverEnv =
12293
export const createClaudeAdapterV2 = Effect.fn("ClaudeAdapterV2Driver.create")(
12294
function* (
12295
input: ProviderAdapterDriverCreateInput<ClaudeSettings>,
12288
- hooks: Pick<ClaudeAdapterV2Options, "scopedLimitNames" | "onUsageLimits"> = {},
12296
+ hooks: Pick<ClaudeAdapterV2Options, "scopedLimitNames" | "onUsageLimits" | "modelCatalog"> = {},
12297
) {
12298
const { instanceId, environment, enabled, config } = input;
12299
const fileSystem = yield* FileSystem.FileSystem;
apps/server/src/provider/Drivers/ClaudeDriver.ts
+5
-1
@@ -155,7 +155,11 @@ export const ClaudeDriver: ProviderDriver<ClaudeSettings, ClaudeDriverEnv, Path.
155
enabled,
156
config,
157
},
158
- { scopedLimitNames, onUsageLimits: (update) => snapshot.applyUsageLimits(update) },
158
+ {
159
+ scopedLimitNames,
160
+ onUsageLimits: (update) => snapshot.applyUsageLimits(update),
161
+ modelCatalog,
162
+ },
163
).pipe(
164
Effect.mapError(
165
(cause) =>