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, 19:45 UTC
fix(server): custom Claude models named like a Claude Code alias reach the API unchanged (#34938)
Julius Marminge committed
Nov 12, 2026 at 00:14 UTC
5922408c3b069a68c68c5b16db437404815a95fe
2 files changed
+44
-2
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+25
@@ -99,6 +99,7 @@ import { ClaudeExecutableFileCheck } from "../../provider/Drivers/ClaudeExecutab
99
import {
100
BUNDLED_CLAUDE_MODEL_CATALOG,
101
type ClaudeModelCatalog,
102
+ scopeClaudeModelCatalog,
103
} from "../../provider/ClaudeModelCatalog.ts";
104
import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers";
105
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
@@ -394,6 +395,30 @@ describe("ClaudeAdapterV2 runtime query policy", () => {
395
});
396
});
397
398
+ it("sends a custom model named like a Claude Code alias to the API unchanged", () => {
399
+ const options = ClaudeAdapterV2.makeClaudeQueryOptions({
400
+ modelSelection: { instanceId: CLAUDE_TEST_MODEL_SELECTION.instanceId, model: "opus" },
401
+ modelCatalog: scopeClaudeModelCatalog(
402
+ BUNDLED_CLAUDE_MODEL_CATALOG,
403
+ CUSTOM_MODEL_CLAUDE_SETTINGS.customModels,
404
+ ),
405
+ nativeThreadId: "native-custom-alias",
406
+ resume: false,
407
+ cwd: "/workspace",
408
+ settings: CUSTOM_MODEL_CLAUDE_SETTINGS,
409
+ });
410
+ // Claude Code expands a bare alias to its own model unless ANTHROPIC_DEFAULT_<ALIAS>_MODEL overrides it.
411
+ const settingsEnv =
412
+ typeof options.settings === "object" && options.settings !== null
413
+ ? (options.settings as { env?: Record<string, string> }).env
414
+ : undefined;
415
+ const aliasOverride =
416
+ settingsEnv?.ANTHROPIC_DEFAULT_OPUS_MODEL ?? options.env?.ANTHROPIC_DEFAULT_OPUS_MODEL;
417
+ const requestedModel =
418
+ options.model === "opus" ? (aliasOverride ?? "claude-opus-5-5") : options.model;
419
+ assert.equal(requestedModel, "opus");
420
+ });
421
+
422
it("projects AskUserQuestion input with question text as the answer key", () => {
423
const preview = "\n **Proposed change**\n\n```ts\n\tconst enabled = true;\n```\n ";
424
assert.deepEqual(
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+19
-2
@@ -1939,6 +1939,8 @@ const subagentDeviceInstructions: HookCallback = () =>
1939
},
1940
});
1941
1942
+const CLAUDE_CODE_MODEL_ALIASES = new Set(["opus", "sonnet", "haiku", "fable"]);
1943
+
1944
export function makeClaudeQueryOptions(input: {
1945
readonly modelSelection: ModelSelection;
1946
readonly modelCatalog?: ClaudeModelCatalog;
@@ -2014,13 +2016,28 @@ export function makeClaudeQueryOptions(input: {
2016
...(typeof querySettings === "object" && querySettings !== null ? querySettings : {}),
2017
autoCompactWindow: Number(input.settings.autoCompactWindow),
2018
} as ClaudeSdkSettings);
2019
+ // Claude Code expands a bare alias to its own model, so a custom model with an alias's name
2020
+ // pins the alias to itself.
2021
+ const aliasOverrideEnv = CLAUDE_CODE_MODEL_ALIASES.has(compiledSelection.apiModelId)
2022
+ ? {
2023
+ [`ANTHROPIC_DEFAULT_${compiledSelection.apiModelId.toUpperCase()}_MODEL`]:
2024
+ compiledSelection.apiModelId,
2025
+ }
2026
+ : undefined;
2027
// A settings file path cannot take extra keys, so it goes through unchanged.
2028
const effectiveQuerySettings =
2019
- input.toolSearchOverride === undefined || typeof compactQuerySettings === "string"
2029
+ (input.toolSearchOverride === undefined && aliasOverrideEnv === undefined) ||
2030
+ typeof compactQuerySettings === "string"
2031
? compactQuerySettings
2032
: ({
2033
...compactQuerySettings,
2023
- env: { ...compactQuerySettings?.env, ENABLE_TOOL_SEARCH: input.toolSearchOverride },
2034
+ env: {
2035
+ ...compactQuerySettings?.env,
2036
+ ...aliasOverrideEnv,
2037
+ ...(input.toolSearchOverride === undefined
2038
+ ? {}
2039
+ : { ENABLE_TOOL_SEARCH: input.toolSearchOverride }),
2040
+ },
2041
} as ClaudeSdkSettings);
2042
const deviceInstructions = input.mcpServers !== undefined && input.deviceToolsAvailable === true;
2043
const options: ClaudeAgentSdkQueryOptions = {