@devries-cameron20 / t3code Mirror · read-only / commits / 399df485a4
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(claude): version errors from a custom endpoint no longer say to run claude update (#34176)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Bin Jamshid committed Nov 11, 2026 at 11:11 UTC 399df485a4da38ad5df6c0b8365ebccc3701e020
4 files changed +106 -9
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+45 -1
@@ -6635,9 +6635,42 @@ describe("ClaudeAdapterV2 background wake turns", () => {
6635 expected:
6636 "Claude stopped: the prompt exceeds the model's context window. Run /compact or start a new thread.",
6637 },
6638 + ...[
6639 + {
6640 + name: "a model version error rewritten by a custom endpoint",
6641 + baseUrl: "https://gateway.example.test/v1",
6642 + installed: "2.1.322",
6643 + expected:
6644 + "The custom API endpoint gateway.example.test reported Claude Code 2.1.280, but this session runs Claude Code 2.1.322. Running claude update will not fix this; the endpoint or a proxy behind it rewrote the version.",
6645 + },
6646 + { name: "a model version error without a custom endpoint", installed: "2.1.322" },
6647 + {
6648 + name: "a model version error from a Claude Code still below the required version",
6649 + baseUrl: "https://gateway.example.test/v1",
6650 + installed: "2.1.285",
6651 + },
6652 + ].map((row) => {
6653 + const result =
6654 + "API Error: 400 Claude Code 2.1.280 does not support this model; version 2.1.290 or newer is required. Run 'claude update', or update the Claude desktop app, then try again.";
6655 + return {
6656 + ...row,
6657 + isError: true,
6658 + result,
6659 + errors: undefined,
6660 + apiErrorStatus: undefined,
6661 + terminalReason: undefined,
6662 + environment: {
6663 + CLAUDE_CONFIG_DIR: "/synthetic/no-claude-config",
6664 + ...(row.baseUrl === undefined ? {} : { ANTHROPIC_BASE_URL: row.baseUrl }),
6665 + },
6666 + expected: row.expected ?? result,
6667 + };
6668 + }),
6669 ])("reports terminal API error text for $name", (input) =>
6670 Effect.gen(function* () {
6640 - const harness = yield* makeWakeHarness;
6671 + const harness = yield* makeWakeHarnessWithOptions(
6672 + "environment" in input ? { environment: input.environment } : undefined,
6673 + );
6674 const now = yield* DateTime.now;
6675 yield* harness.runtime.startTurn(
6676 makeClaudeTestTurnInput({
@@ -6650,6 +6683,17 @@ describe("ClaudeAdapterV2 background wake turns", () => {
6683 }),
6684 );
6685 const apiErrorStatus = input.apiErrorStatus ?? 400;
6686 + if ("installed" in input) {
6687 + yield* harness.offerAndWait(
6688 + claudeSdkFrame({
6689 + type: "system",
6690 + subtype: "init",
6691 + uuid: "00000000-0000-4000-8000-000000000698",
6692 + session_id: WAKE_NATIVE_SESSION,
6693 + claude_code_version: input.installed,
6694 + }),
6695 + );
6696 + }
6697 yield* Queue.offer(
6698 harness.sdkMessages,
6699 makeResultFrame({
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+44 -1
@@ -84,6 +84,7 @@ import {
84 import { AgentScope } from "@t3tools/shared/AgentScope";
85 import * as HostProcess from "@t3tools/shared/HostProcess";
86 import { applyClaudePromptEffortPrefix } from "@t3tools/shared/model";
87 +import { compareSemverVersions } from "@t3tools/shared/semver";
88 import {
89 CLAUDE_RESUME_COMPACTION_COMPACT_ANSWER,
90 CLAUDE_RESUME_COMPACTION_NEVER_ANSWER,
@@ -165,7 +166,9 @@ import {
166 } from "../../provider/Drivers/ClaudeSkillDispatch.ts";
167 import {
168 claudeLaunchArgDirectories,
169 + customClaudeApiEndpointHost,
170 discoverClaudeSkills,
171 + readClaudeSettingsEnv,
172 } from "../../provider/Drivers/ClaudeSkills.ts";
173 import {
174 compileClaudeModelSelection,
@@ -4106,6 +4109,25 @@ function gatewayCooldownResetAt(
4109 : undefined;
4110 }
4111
4112 +const CLAUDE_UNSUPPORTED_VERSION_ERROR =
4113 + /^API Error: 400 Claude Code (\d+\.\d+\.\d+) does not support this model; version (\d+\.\d+\.\d+) or newer is required\./;
4114 +
4115 +/** The version a gateway sent in place of the session's own, when the session itself meets the requirement. */
4116 +function claudeRewrittenVersion(
4117 + message: SDKResultMessage,
4118 + sessionVersion: string | undefined,
4119 +): string | undefined {
4120 + if (message.subtype !== "success" || message.terminal_reason !== "api_error") return undefined;
4121 + const [, reported, required] = CLAUDE_UNSUPPORTED_VERSION_ERROR.exec(message.result.trim()) ?? [];
4122 + if (reported === undefined || required === undefined || sessionVersion === undefined) {
4123 + return undefined;
4124 + }
4125 + return compareSemverVersions(reported, sessionVersion) < 0 &&
4126 + compareSemverVersions(sessionVersion, required) >= 0
4127 + ? reported
4128 + : undefined;
4129 +}
4130 +
4131 function providerFailureFromResult(
4132 message: SDKResultMessage,
4133 receivedAt: DateTime.Utc,
@@ -4446,6 +4468,7 @@ interface ClaudeLiveQueryContext {
4468 receivedInit: boolean;
4469 // From system/init; feature-detects control requests such as MCP Apps.
4470 capabilities: ReadonlySet<string>;
4471 + claudeCodeVersion: string | undefined;
4472 permissionMode: PermissionMode;
4473 stopping: boolean;
4474 readonly subagentsFromEarlierProcesses: ReadonlySet<ActiveClaudeSubagent>;
@@ -10083,12 +10106,30 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
10106 // The CLI also labels 403 authentication_failed; show its text because login cannot grant access.
10107 const permissionDenied =
10108 message.subtype === "success" && message.api_error_status === 403;
10109 + const rewrittenVersion = claudeRewrittenVersion(message, liveQuery.claudeCodeVersion);
10110 + const endpointHost =
10111 + rewrittenVersion === undefined
10112 + ? undefined
10113 + : customClaudeApiEndpointHost(
10114 + (yield* readClaudeSettingsEnv(
10115 + adapterOptions.settings,
10116 + context.input.runtimePolicy.cwd ?? undefined,
10117 + adapterOptions.environment,
10118 + ).pipe(
10119 + Effect.provideService(FileSystem.FileSystem, fileSystem),
10120 + Effect.provideService(Path.Path, path),
10121 + )).ANTHROPIC_BASE_URL ?? adapterOptions.environment.ANTHROPIC_BASE_URL,
10122 + );
10123 + const rewrittenVersionError =
10124 + endpointHost === undefined
10125 + ? undefined
10126 + : `The custom API endpoint ${endpointHost} reported Claude Code ${rewrittenVersion}, but this session runs Claude Code ${liveQuery.claudeCodeVersion}. Running claude update will not fix this; the endpoint or a proxy behind it rewrote the version.`;
10127 const failureHint = permissionDenied
10128 ? message.result
10129 : (context.authenticationFailureMessage ??
10130 (usageLimited
10131 ? "Claude usage limit reached. Send the message again once the limit resets."
10091 - : undefined));
10132 + : rewrittenVersionError));
10133 // Usage-limited /compact reports success; fail it so queued messages wait for the limit to clear.
10134 const limitedCompaction =
10135 usageLimited && message.subtype === "success" && message.local_command === "compact"
@@ -11077,6 +11118,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
11118 openedPermissionMode: queryOptions.permissionMode,
11119 receivedInit: false,
11120 capabilities: new Set(),
11121 + claudeCodeVersion: undefined,
11122 permissionMode: queryOptions.permissionMode,
11123 stopping: false,
11124 handedOffSubagents: new Set(),
@@ -11117,6 +11159,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
11159 message.permissionMode ?? context.openedPermissionMode;
11160 context.receivedInit = true;
11161 context.capabilities = new Set(message.capabilities ?? []);
11162 + context.claudeCodeVersion = message.claude_code_version;
11163 }
11164 if (
11165 message.type === "system" &&
apps/server/src/provider/ClaudeProvider.ts
+6 -7
@@ -45,7 +45,11 @@ import {
45 hasClaudeManagedMcpConfig,
46 makeClaudeEnvironment,
47 } from "./Drivers/ClaudeHome.ts";
48 -import { discoverClaudeSkills, readClaudeSettingsEnv } from "./Drivers/ClaudeSkills.ts";
48 +import {
49 + customClaudeApiEndpointHost,
50 + discoverClaudeSkills,
51 + readClaudeSettingsEnv,
52 +} from "./Drivers/ClaudeSkills.ts";
53 import type { ProviderWorkspaceSnapshot } from "@t3tools/provider-core/server/driver";
54 import { makeUnavailableUsageLimits } from "@t3tools/provider-core/server/usageLimits";
55 import {
@@ -671,12 +675,7 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")(
675 const baseUrl =
676 (yield* readClaudeSettingsEnv(claudeSettings, cwd, resolvedEnvironment)).ANTHROPIC_BASE_URL ??
677 resolvedEnvironment.ANTHROPIC_BASE_URL;
674 - const endpoint = URL.parse(baseUrl?.trim() ?? "");
675 - const customApiEndpoint =
676 - endpoint !== null &&
677 - (endpoint.protocol === "http:" || endpoint.protocol === "https:") &&
678 - endpoint.hostname !== "" &&
679 - endpoint.hostname !== "api.anthropic.com";
678 + const customApiEndpoint = customClaudeApiEndpointHost(baseUrl) !== undefined;
679 if (!customApiEndpoint && claudeAuthStatus(capabilities) === "unauthenticated") {
680 const path = yield* Path.Path;
681 const configDir = (yield* makeClaudeEnvironment(claudeSettings, resolvedEnvironment))
apps/server/src/provider/Drivers/ClaudeSkills.ts
+11
@@ -472,6 +472,17 @@ export const readClaudeSettingsEnv = Effect.fn("readClaudeSettingsEnv")(function
472 return settingsEnv;
473 });
474
475 +/** The host of an `ANTHROPIC_BASE_URL` that is not Anthropic's own API. */
476 +export function customClaudeApiEndpointHost(baseUrl: string | undefined): string | undefined {
477 + const endpoint = URL.parse(baseUrl?.trim() ?? "");
478 + return endpoint !== null &&
479 + (endpoint.protocol === "http:" || endpoint.protocol === "https:") &&
480 + endpoint.hostname !== "" &&
481 + endpoint.hostname !== "api.anthropic.com"
482 + ? endpoint.hostname
483 + : undefined;
484 +}
485 +
486 // Claude's --add-dir is repeatable and variadic; parseCliArgs keeps only one value.
487 export function claudeLaunchArgDirectories(launchArgs?: string): ReadonlyArray<string> {
488 const directories: string[] = [];