@@ -1939,6 +1939,8 @@ const subagentDeviceInstructions: HookCallback = () =>
19391939 },
19401940 });
19411941
1942+ const CLAUDE_CODE_MODEL_ALIASES = new Set(["opus", "sonnet", "haiku", "fable"]);
1943+
19421944export function makeClaudeQueryOptions(input: {
19431945 readonly modelSelection: ModelSelection;
19441946 readonly modelCatalog?: ClaudeModelCatalog;
@@ -2014,13 +2016,28 @@ export function makeClaudeQueryOptions(input: {
20142016 ...(typeof querySettings === "object" && querySettings !== null ? querySettings : {}),
20152017 autoCompactWindow: Number(input.settings.autoCompactWindow),
20162018 } 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;
20172027 // A settings file path cannot take extra keys, so it goes through unchanged.
20182028 const effectiveQuerySettings =
2019- input.toolSearchOverride === undefined || typeof compactQuerySettings === "string"
2029+ (input.toolSearchOverride === undefined && aliasOverrideEnv === undefined) ||
2030+ typeof compactQuerySettings === "string"
20202031 ? compactQuerySettings
20212032 : ({
20222033 ...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+ },
20242041 } as ClaudeSdkSettings);
20252042 const deviceInstructions = input.mcpServers !== undefined && input.deviceToolsAvailable === true;
20262043 const options: ClaudeAgentSdkQueryOptions = {
0 commit comments