Skip to content

Commit 2ba978e

Browse files
committed
fix(server): a logged-out Claude CLI no longer reports as authenticated
The capability probe resolves even when Claude Code has no credentials, so treating a completed probe as proof of sign-in left provider cards claiming a healthy account that could not run a single turn. Signed-off-by: Yordis Prieto <[email protected]>
1 parent 7379933 commit 2ba978e

3 files changed

Lines changed: 148 additions & 0 deletions

File tree

‎apps/server/src/provider/Layers/ClaudeCapabilitiesProbe.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ it.layer(NodeServices.layer)("Claude capability probe SDK boundary", (it) => {
9696
9797
subscriptionType: "pro",
9898
tokenSource: "oauth",
99+
apiKeySource: undefined,
99100
apiProvider: undefined,
100101
slashCommands: [
101102
{

‎apps/server/src/provider/Layers/ClaudeProvider.ts‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,38 @@ function apiProviderAuthMetadata(
164164
return apiProvider === "bedrock" ? { type: "bedrock", label: "Amazon Bedrock" } : undefined;
165165
}
166166

167+
/**
168+
* Whether the SDK's account payload evidences a credential the CLI can use.
169+
*
170+
* The capability probe resolves for a logged-out CLI, so a completed probe only
171+
* proves Claude Code started. `tokenSource: "none"` is the CLI reporting it
172+
* found no token at all, and is the one shape that disproves authentication.
173+
* Everything else either names a credential or, on a third-party backend, omits
174+
* these fields by design because auth lives with AWS or gcloud instead.
175+
*
176+
* Silence is deliberately not disproof. Profile-authenticated installs report no
177+
* token source, and a CLI too old to send an account payload reports nothing at
178+
* all; treating either as logged out would sign working setups out of Settings.
179+
* `apiKeySource` is only ever set when a key was actually found, so it has no
180+
* "no key" sentinel to confuse with one.
181+
*/
182+
export function claudeAuthStatus(
183+
capabilities: Pick<
184+
ClaudeCapabilitiesProbe,
185+
"email" | "subscriptionType" | "tokenSource" | "apiKeySource" | "apiProvider"
186+
>,
187+
): "authenticated" | "unauthenticated" {
188+
if (capabilities.apiProvider !== undefined && capabilities.apiProvider !== "firstParty") {
189+
return "authenticated";
190+
}
191+
if (capabilities.tokenSource !== "none") return "authenticated";
192+
// An `ANTHROPIC_API_KEY` install reports no token source but is authenticated
193+
// all the same, so the key and account fields still get a say.
194+
return capabilities.apiKeySource || capabilities.email || capabilities.subscriptionType
195+
? "authenticated"
196+
: "unauthenticated";
197+
}
198+
167199
// ── SDK capability probe ────────────────────────────────────────────
168200

169201
// Amazon Bedrock initializes far slower than first-party auth: the SDK boots the
@@ -229,6 +261,8 @@ type ClaudeCapabilitiesProbe = {
229261
readonly email: string | undefined;
230262
readonly subscriptionType: string | undefined;
231263
readonly tokenSource: string | undefined;
264+
/** Where the CLI found an API key, when it authenticates with one. */
265+
readonly apiKeySource: string | undefined;
232266
/**
233267
* Active API backend reported by the SDK's `AccountInfo`. Anthropic OAuth
234268
* login only applies when `"firstParty"`; for Amazon Bedrock (`"bedrock"`)
@@ -378,13 +412,15 @@ const probeClaudeCapabilities = (
378412
readonly email?: string;
379413
readonly subscriptionType?: string;
380414
readonly tokenSource?: string;
415+
readonly apiKeySource?: string;
381416
readonly apiProvider?: string;
382417
}
383418
| undefined;
384419
return {
385420
email: account?.email,
386421
subscriptionType: account?.subscriptionType,
387422
tokenSource: account?.tokenSource,
423+
apiKeySource: account?.apiKeySource,
388424
apiProvider: account?.apiProvider,
389425
slashCommands: parseClaudeInitializationCommands(init.commands),
390426
...(usage ? { usage } : {}),
@@ -558,6 +594,24 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")(
558594
});
559595
}
560596

597+
if (claudeAuthStatus(capabilities) === "unauthenticated") {
598+
return buildServerProvider({
599+
presentation: CLAUDE_PRESENTATION,
600+
enabled: claudeSettings.enabled,
601+
checkedAt,
602+
models,
603+
slashCommands: dedupedSlashCommands,
604+
skills,
605+
probe: {
606+
installed: true,
607+
version: parsedVersion,
608+
status: "error",
609+
auth: { status: "unauthenticated" },
610+
message: "Claude Code is not authenticated. Run `claude auth login` and try again.",
611+
},
612+
});
613+
}
614+
561615
const authMetadata =
562616
claudeAuthMetadata({
563617
subscriptionType: capabilities.subscriptionType,

‎apps/server/src/provider/Layers/ProviderRegistry.test.ts‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ type TestClaudeCapabilities = {
156156
readonly email: string | undefined;
157157
readonly subscriptionType: string | undefined;
158158
readonly tokenSource: string | undefined;
159+
readonly apiKeySource: string | undefined;
159160
readonly apiProvider: string | undefined;
160161
readonly slashCommands: ReadonlyArray<ServerProviderSlashCommand>;
161162
};
@@ -166,6 +167,7 @@ function claudeCapabilities(overrides: Partial<TestClaudeCapabilities> = {}) {
166167
email: undefined,
167168
subscriptionType: undefined,
168169
tokenSource: undefined,
170+
apiKeySource: undefined,
169171
apiProvider: undefined,
170172
slashCommands: [],
171173
...overrides,
@@ -2972,6 +2974,96 @@ it.layer(Layer.mergeAll(TestNodeServices, ServerSettingsModule.layerTest(), Test
29722974
),
29732975
);
29742976

2977+
it.effect("reports a logged-out CLI as unauthenticated", () =>
2978+
Effect.gen(function* () {
2979+
// The capability probe resolves for a logged-out CLI, so `tokenSource:
2980+
// "none"` is the only thing separating it from an authenticated one.
2981+
const status = yield* checkClaudeProviderStatus(
2982+
defaultClaudeSettings,
2983+
claudeCapabilities({ tokenSource: "none", apiProvider: "firstParty" }),
2984+
);
2985+
assert.strictEqual(status.status, "error");
2986+
assert.strictEqual(status.auth.status, "unauthenticated");
2987+
}).pipe(
2988+
Effect.provide(
2989+
mockSpawnerLayer((args) => {
2990+
const joined = args.join(" ");
2991+
if (joined === "--version") return { stdout: "1.0.0\n", stderr: "", code: 0 };
2992+
throw new Error(`Unexpected args: ${joined}`);
2993+
}),
2994+
),
2995+
),
2996+
);
2997+
2998+
it.effect("keeps an API key install authenticated when it reports no token source", () =>
2999+
Effect.gen(function* () {
3000+
// `ANTHROPIC_API_KEY` never populates `tokenSource`, so reading that
3001+
// field alone would log the install out.
3002+
const status = yield* checkClaudeProviderStatus(
3003+
defaultClaudeSettings,
3004+
claudeCapabilities({
3005+
tokenSource: "none",
3006+
apiKeySource: "ANTHROPIC_API_KEY",
3007+
apiProvider: "firstParty",
3008+
}),
3009+
);
3010+
assert.strictEqual(status.status, "ready");
3011+
assert.strictEqual(status.auth.status, "authenticated");
3012+
}).pipe(
3013+
Effect.provide(
3014+
mockSpawnerLayer((args) => {
3015+
const joined = args.join(" ");
3016+
if (joined === "--version") return { stdout: "1.0.0\n", stderr: "", code: 0 };
3017+
throw new Error(`Unexpected args: ${joined}`);
3018+
}),
3019+
),
3020+
),
3021+
);
3022+
3023+
it.effect("keeps a third-party backend authenticated without any token source", () =>
3024+
Effect.gen(function* () {
3025+
// Bedrock and Vertex authenticate outside the CLI, so the account
3026+
// payload is empty by design rather than because nobody logged in.
3027+
const status = yield* checkClaudeProviderStatus(
3028+
defaultClaudeSettings,
3029+
claudeCapabilities({ tokenSource: "none", apiProvider: "bedrock" }),
3030+
);
3031+
assert.strictEqual(status.status, "ready");
3032+
assert.strictEqual(status.auth.status, "authenticated");
3033+
}).pipe(
3034+
Effect.provide(
3035+
mockSpawnerLayer((args) => {
3036+
const joined = args.join(" ");
3037+
if (joined === "--version") return { stdout: "1.0.0\n", stderr: "", code: 0 };
3038+
throw new Error(`Unexpected args: ${joined}`);
3039+
}),
3040+
),
3041+
),
3042+
);
3043+
3044+
it.effect("keeps a CLI that says nothing about its account authenticated", () =>
3045+
Effect.gen(function* () {
3046+
// Profile-authenticated installs report no token source at all, and a
3047+
// CLI too old to send an account payload reports nothing whatsoever.
3048+
// Only `tokenSource: "none"` disproves authentication; saying nothing
3049+
// is not the same as saying no.
3050+
const status = yield* checkClaudeProviderStatus(
3051+
defaultClaudeSettings,
3052+
claudeCapabilities(),
3053+
);
3054+
assert.strictEqual(status.status, "ready");
3055+
assert.strictEqual(status.auth.status, "authenticated");
3056+
}).pipe(
3057+
Effect.provide(
3058+
mockSpawnerLayer((args) => {
3059+
const joined = args.join(" ");
3060+
if (joined === "--version") return { stdout: "1.0.0\n", stderr: "", code: 0 };
3061+
throw new Error(`Unexpected args: ${joined}`);
3062+
}),
3063+
),
3064+
),
3065+
);
3066+
29753067
it.effect("returns a display label for claude subscription types", () =>
29763068
Effect.gen(function* () {
29773069
const status = yield* checkClaudeProviderStatus(
@@ -3009,6 +3101,7 @@ it.layer(Layer.mergeAll(TestNodeServices, ServerSettingsModule.layerTest(), Test
30093101
email: undefined,
30103102
subscriptionType: undefined,
30113103
tokenSource: undefined,
3104+
apiKeySource: undefined,
30123105
apiProvider: undefined,
30133106
slashCommands: [],
30143107
usage: { rate_limits_available: true, rate_limits: {} },

0 commit comments

Comments
 (0)