@devries-cameron20 / t3code-1 / commits / 1854e14d09
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): recognize a Claude proxy set in Claude's settings.json (#26937)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>

Md Ehsanul Haque committed Oct 31, 2026 at 03:47 UTC 1854e14d0943c9c80913d797bc8fa7eafc765e9c
3 files changed +121 -10
apps/server/src/provider/ClaudeProvider.ts
+9 -5
@@ -37,7 +37,7 @@ import {
37 } from "@t3tools/provider-core/server/snapshotProbe";
38 import { resolveClaudeSdkExecutablePath } from "./Drivers/ClaudeExecutable.ts";
39 import { hasClaudeManagedMcpConfig, makeClaudeEnvironment } from "./Drivers/ClaudeHome.ts";
40 -import { discoverClaudeSkills } from "./Drivers/ClaudeSkills.ts";
40 +import { discoverClaudeSkills, readClaudeSettingsBaseUrl } from "./Drivers/ClaudeSkills.ts";
41 import type { ProviderWorkspaceSnapshot } from "@t3tools/provider-core/server/driver";
42 import { makeUnavailableUsageLimits } from "@t3tools/provider-core/server/usageLimits";
43 import {
@@ -600,7 +600,10 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")(
600 }
601
602 // First-party account fields cannot verify custom endpoint credentials.
603 - const endpoint = URL.parse(resolvedEnvironment.ANTHROPIC_BASE_URL?.trim() ?? "");
603 + const baseUrl =
604 + (yield* readClaudeSettingsBaseUrl(claudeSettings, cwd, resolvedEnvironment)) ??
605 + resolvedEnvironment.ANTHROPIC_BASE_URL;
606 + const endpoint = URL.parse(baseUrl?.trim() ?? "");
607 const customApiEndpoint =
608 endpoint !== null &&
609 (endpoint.protocol === "http:" || endpoint.protocol === "https:") &&
@@ -625,13 +628,14 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")(
628 });
629 }
630
631 + // A proxy's ANTHROPIC_AUTH_TOKEN reads as an API key; the endpoint is what the token is for.
632 const authMetadata =
633 + apiProviderAuthMetadata(capabilities.apiProvider) ??
634 + (customApiEndpoint ? { type: "customEndpoint", label: "Custom API endpoint" } : undefined) ??
635 claudeAuthMetadata({
636 subscriptionType: capabilities.subscriptionType,
637 authMethod: capabilities.tokenSource,
632 - }) ??
633 - apiProviderAuthMetadata(capabilities.apiProvider) ??
634 - (customApiEndpoint ? { type: "customEndpoint", label: "Custom API endpoint" } : undefined);
638 + });
639 const usageCheckedAt = capabilities.usageCheckedAt ?? checkedAt;
640 const usageLimits = !capabilities.usage
641 ? makeUnavailableUsageLimits({ checkedAt, reason: "probeFailed" })
apps/server/src/provider/Drivers/ClaudeSkills.ts
+40 -2
@@ -119,7 +119,8 @@ function claudeManagedSettingsPath(
119 return "/etc/claude-code/managed-settings.json";
120 }
121
122 -function skillOverrideSettingsPaths(
122 +/** Claude Code settings files, lowest precedence first. */
123 +function claudeSettingsPaths(
124 path: Path.Path,
125 configDirPath: string,
126 cwd: string | undefined,
@@ -247,7 +248,7 @@ const readSkillSettings = Effect.fn("readSkillSettings")(function* (
248 const enabledPlugins = new Map<string, boolean>();
249 const repositoryRoot = cwd === undefined ? undefined : yield* findRepositoryRoot(cwd);
250
250 - for (const settingsPath of skillOverrideSettingsPaths(
251 + for (const settingsPath of claudeSettingsPaths(
252 path,
253 configDirPath,
254 cwd,
@@ -427,6 +428,43 @@ const resolveClaudeConfigDirPath = Effect.fn("resolveClaudeConfigDirPath")(funct
428 return path.join(home, ".claude");
429 });
430
431 +const SettingsBaseUrl = fromLenientJson(
432 + Schema.Struct({
433 + env: Schema.optional(Schema.Struct({ ANTHROPIC_BASE_URL: Schema.optional(Schema.String) })),
434 + }),
435 +);
436 +const decodeSettingsBaseUrl = Schema.decodeUnknownEffect(SettingsBaseUrl);
437 +
438 +/** ANTHROPIC_BASE_URL from Claude's settings `env`, which Claude Code applies over the process env. */
439 +export const readClaudeSettingsBaseUrl = Effect.fn("readClaudeSettingsBaseUrl")(function* (
440 + config: Pick<ClaudeSettings, "homePath">,
441 + cwd: string | undefined,
442 + environment: NodeJS.ProcessEnv,
443 +): Effect.fn.Return<string | undefined, never, FileSystem.FileSystem | Path.Path> {
444 + const fileSystem = yield* FileSystem.FileSystem;
445 + const path = yield* Path.Path;
446 + const platform = yield* HostProcess.Platform;
447 + const configDirPath = yield* resolveClaudeConfigDirPath(config, environment, cwd);
448 + let baseUrl: string | undefined;
449 + for (const settingsPath of claudeSettingsPaths(
450 + path,
451 + configDirPath,
452 + undefined,
453 + platform,
454 + environment,
455 + )) {
456 + const contents = yield* fileSystem
457 + .readFileString(settingsPath)
458 + .pipe(Effect.orElseSucceed(() => undefined));
459 + if (contents === undefined) continue;
460 + const parsed = yield* decodeSettingsBaseUrl(contents).pipe(
461 + Effect.orElseSucceed(() => undefined),
462 + );
463 + baseUrl = parsed?.env?.ANTHROPIC_BASE_URL ?? baseUrl;
464 + }
465 + return baseUrl;
466 +});
467 +
468 // Claude's --add-dir is repeatable and variadic; parseCliArgs keeps only one value.
469 export function claudeLaunchArgDirectories(launchArgs?: string): ReadonlyArray<string> {
470 const directories: string[] = [];
apps/server/src/provider/ProviderRegistry.test.ts
+72 -3
@@ -1,7 +1,4 @@
1 -import * as HostProcess from "@t3tools/shared/HostProcess";
1 import * as CodexErrors from "effect-codex-app-server/errors";
3 -import * as Path from "effect/Path";
4 -import * as FileSystem from "effect/FileSystem";
2 import { vi } from "vite-plus/test";
3 import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
4 import * as CodexInstallation from "./CodexInstallation.ts";
@@ -14,7 +11,9 @@ import * as Deferred from "effect/Deferred";
11 import * as Effect from "effect/Effect";
12 import * as Exit from "effect/Exit";
13 import * as Fiber from "effect/Fiber";
14 +import * as FileSystem from "effect/FileSystem";
15 import * as Layer from "effect/Layer";
16 +import * as Path from "effect/Path";
17 import * as PubSub from "effect/PubSub";
18 import * as Ref from "effect/Ref";
19 import * as Schema from "effect/Schema";
@@ -38,6 +37,7 @@ import {
37 } from "@t3tools/contracts";
38 import { HttpClient, HttpClientResponse } from "effect/http";
39 import { ChildProcessSpawner } from "effect/process";
40 +import * as HostProcess from "@t3tools/shared/HostProcess";
41 import { deepMerge } from "@t3tools/shared/Struct";
42 import { createModelCapabilities } from "@t3tools/shared/model";
43 import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";
@@ -340,6 +340,13 @@ const layerTestNodeServices = Layer.mergeAll(
340 Layer.succeed(ServerEnvironment.ServerEnvironmentIdentity, {
341 getEnvironmentId: Effect.succeed(EnvironmentId.make("00000000-0000-4000-8000-000000000001")),
342 }),
343 + // An empty home, so the developer's own Claude settings never reach provider probes.
344 + Layer.effect(
345 + HostProcess.HomeDirectory,
346 + Effect.gen(function* () {
347 + return yield* (yield* FileSystem.FileSystem).makeTempDirectoryScoped();
348 + }),
349 + ).pipe(Layer.provide(NodeServices.layer)),
350 );
351
352 it.layer(
@@ -2539,6 +2546,68 @@ it.layer(
2546 ),
2547 );
2548
2549 + it.effect.each([
2550 + {
2551 + settings: { env: { ANTHROPIC_BASE_URL: "https://hub.example.ts.net:8317" } },
2552 + baseUrl: "https://api.anthropic.com",
2553 + type: "customEndpoint",
2554 + label: "Custom API endpoint",
2555 + },
2556 + {
2557 + settings: { env: { ANTHROPIC_BASE_URL: "https://api.anthropic.com" } },
2558 + baseUrl: "https://proxy.example",
2559 + type: "apiKey",
2560 + label: "Claude API Key",
2561 + },
2562 + {
2563 + settings: {},
2564 + baseUrl: "https://proxy.example",
2565 + type: "customEndpoint",
2566 + label: "Custom API endpoint",
2567 + },
2568 + ])(
2569 + "uses the settings endpoint before the process endpoint: $type / $baseUrl",
2570 + ({ settings, baseUrl, type, label }) =>
2571 + Effect.gen(function* () {
2572 + const fileSystem = yield* FileSystem.FileSystem;
2573 + const path = yield* Path.Path;
2574 + const configDir = yield* fileSystem.makeTempDirectoryScoped({
2575 + prefix: "t3-claude-settings-",
2576 + });
2577 + yield* fileSystem.writeFileString(
2578 + path.join(configDir, "settings.json"),
2579 + JSON.stringify(settings),
2580 + );
2581 + const stateDir = yield* fileSystem.makeTempDirectoryScoped();
2582 + yield* fileSystem.makeDirectory(path.join(stateDir, ".claude"));
2583 + yield* fileSystem.writeFileString(
2584 + path.join(stateDir, ".claude", "settings.json"),
2585 + JSON.stringify({ env: { ANTHROPIC_BASE_URL: "https://state-dir.example" } }),
2586 + );
2587 + const status = yield* checkClaudeProviderStatus(
2588 + { ...defaultClaudeSettings, homePath: configDir },
2589 + claudeCapabilities({
2590 + tokenSource: "ANTHROPIC_AUTH_TOKEN",
2591 + apiKeySource: "none",
2592 + apiProvider: "firstParty",
2593 + }),
2594 + { ANTHROPIC_BASE_URL: baseUrl },
2595 + stateDir,
2596 + );
2597 + assert.strictEqual(status.status, "ready");
2598 + assert.strictEqual(status.auth.type, type);
2599 + assert.strictEqual(status.auth.label, label);
2600 + }).pipe(
2601 + Effect.provide(
2602 + layerMockSpawner((args) => {
2603 + const joined = args.join(" ");
2604 + if (joined === "--version") return { stdout: "1.0.0\n", stderr: "", code: 0 };
2605 + throw new Error(`Unexpected args: ${joined}`);
2606 + }),
2607 + ),
2608 + ),
2609 + );
2610 +
2611 it.effect.each([
2612 "https://api.anthropic.com",
2613 "https://api.anthropic.com:443",