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 22, 23:15 UTC
fix(server): custom Claude endpoint no longer reads as logged out (#21169)
Co-authored-by: Claude Code <noreply@anthropic.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Arta committed
Oct 20, 2026 at 07:57 UTC
51d1f6f623dd5f7fd9a8ef10eb939aac5b3badd5
2 files changed
+87
-2
apps/server/src/provider/ClaudeProvider.ts
+11
-2
@@ -622,7 +622,14 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")(
622
});
623
}
624
625
- if (claudeAuthStatus(capabilities) === "unauthenticated") {
625
+ // First-party account fields cannot verify custom endpoint credentials.
626
+ const endpoint = URL.parse(resolvedEnvironment.ANTHROPIC_BASE_URL?.trim() ?? "");
627
+ const customApiEndpoint =
628
+ endpoint !== null &&
629
+ (endpoint.protocol === "http:" || endpoint.protocol === "https:") &&
630
+ endpoint.hostname !== "" &&
631
+ endpoint.hostname !== "api.anthropic.com";
632
+ if (!customApiEndpoint && claudeAuthStatus(capabilities) === "unauthenticated") {
633
return buildServerProvider({
634
presentation: CLAUDE_PRESENTATION,
635
enabled: claudeSettings.enabled,
@@ -644,7 +651,9 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")(
651
claudeAuthMetadata({
652
subscriptionType: capabilities.subscriptionType,
653
authMethod: capabilities.tokenSource,
647
- }) ?? apiProviderAuthMetadata(capabilities.apiProvider);
654
+ }) ??
655
+ apiProviderAuthMetadata(capabilities.apiProvider) ??
656
+ (customApiEndpoint ? { type: "customEndpoint", label: "Custom API endpoint" } : undefined);
657
const usageLimits = !capabilities.usage
658
? makeUnavailableUsageLimits({ checkedAt, reason: "probeFailed" })
659
: scopedLimitNames
apps/server/src/provider/ProviderRegistry.test.ts
+76
@@ -70,6 +70,7 @@ import type {
70
import * as ProviderInstanceRegistry from "./ProviderInstanceRegistry.ts";
71
import * as ProviderRegistry from "./ProviderRegistry.ts";
72
import { ProviderDriverError } from "./Errors.ts";
73
+import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
74
import {
75
makeManualOnlyProviderMaintenanceCapabilities,
76
makeProviderMaintenanceCapabilities,
@@ -4105,6 +4106,7 @@ it.layer(
4106
apiKeySource: "none",
4107
apiProvider: "firstParty",
4108
}),
4109
+ { ANTHROPIC_BASE_URL: "" },
4110
);
4111
assert.strictEqual(status.status, "error");
4112
assert.strictEqual(status.auth.status, "unauthenticated");
@@ -4119,6 +4121,80 @@ it.layer(
4121
),
4122
);
4123
4124
+ it.effect.each([
4125
+ { source: "inherited HTTPS endpoint", baseUrl: "https://proxy.example/api", overrides: [] },
4126
+ {
4127
+ source: "instance HTTP endpoint overriding Anthropic",
4128
+ baseUrl: "https://api.anthropic.com",
4129
+ overrides: [
4130
+ { name: "ANTHROPIC_BASE_URL", value: "http://localhost:8080", sensitive: false },
4131
+ ],
4132
+ },
4133
+ ])("keeps Claude ready with an empty first-party account: $source", ({ baseUrl, overrides }) =>
4134
+ Effect.gen(function* () {
4135
+ const environment = yield* mergeProviderInstanceEnvironment(overrides, {
4136
+ ANTHROPIC_BASE_URL: baseUrl,
4137
+ });
4138
+ const status = yield* checkClaudeProviderStatus(
4139
+ defaultClaudeSettings,
4140
+ claudeCapabilities({
4141
+ tokenSource: "none",
4142
+ apiKeySource: "none",
4143
+ apiProvider: "firstParty",
4144
+ }),
4145
+ environment,
4146
+ );
4147
+ assert.strictEqual(status.status, "ready");
4148
+ assert.strictEqual(status.auth.status, "authenticated");
4149
+ assert.strictEqual(status.auth.type, "customEndpoint");
4150
+ assert.strictEqual(status.auth.label, "Custom API endpoint");
4151
+ }).pipe(
4152
+ Effect.provide(
4153
+ layerMockSpawner((args) => {
4154
+ const joined = args.join(" ");
4155
+ if (joined === "--version") return { stdout: "1.0.0\n", stderr: "", code: 0 };
4156
+ throw new Error(`Unexpected args: ${joined}`);
4157
+ }),
4158
+ ),
4159
+ ),
4160
+ );
4161
+
4162
+ it.effect.each([
4163
+ "https://api.anthropic.com",
4164
+ "https://api.anthropic.com:443",
4165
+ "https://api.anthropic.com:8443",
4166
+ "openrouter.ai/api",
4167
+ "localhost:8080",
4168
+ "ftp://proxy.example",
4169
+ ])("keeps Claude logged out when the instance endpoint is %s", (baseUrl) =>
4170
+ Effect.gen(function* () {
4171
+ const environment = yield* mergeProviderInstanceEnvironment(
4172
+ [{ name: "ANTHROPIC_BASE_URL", value: baseUrl, sensitive: false }],
4173
+ { ANTHROPIC_BASE_URL: "https://proxy.example/api" },
4174
+ );
4175
+ const status = yield* checkClaudeProviderStatus(
4176
+ defaultClaudeSettings,
4177
+ claudeCapabilities({
4178
+ tokenSource: "none",
4179
+ apiKeySource: "none",
4180
+ apiProvider: "firstParty",
4181
+ }),
4182
+ environment,
4183
+ );
4184
+ assert.strictEqual(status.status, "error");
4185
+ assert.strictEqual(status.auth.status, "unauthenticated");
4186
+ assert.strictEqual(status.auth.type, undefined);
4187
+ }).pipe(
4188
+ Effect.provide(
4189
+ layerMockSpawner((args) => {
4190
+ const joined = args.join(" ");
4191
+ if (joined === "--version") return { stdout: "1.0.0\n", stderr: "", code: 0 };
4192
+ throw new Error(`Unexpected args: ${joined}`);
4193
+ }),
4194
+ ),
4195
+ ),
4196
+ );
4197
+
4198
it.effect("keeps an API key install authenticated when it reports no token source", () =>
4199
Effect.gen(function* () {
4200
// `ANTHROPIC_API_KEY` never populates `tokenSource`, so reading that