Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(server): prevent probeClaudeCapabilities from wasting API requests (#2192)
reasv8dbcf92a0d12
diff --git a/apps/server/src/provider/Layers/ClaudeProvider.ts b/apps/server/src/provider/Layers/ClaudeProvider.tsindex 5274f8428..7c8a4c27a 100644--- a/apps/server/src/provider/Layers/ClaudeProvider.ts+++ b/apps/server/src/provider/Layers/ClaudeProvider.ts@@ -14,6 +14,7 @@ import { decodeJsonResult } from "@t3tools/shared/schemaJson";import {query as claudeQuery,type SlashCommand as ClaudeSlashCommand,+ type SDKUserMessage,} from "@anthropic-ai/claude-agent-sdk";import {@@ -480,13 +481,24 @@ function dedupeSlashCommands(return [...commandsByName.values()];}+function waitForAbortSignal(signal: AbortSignal): Promise<void> {+ if (signal.aborted) {+ return Promise.resolve();+ }+ return new Promise((resolve) => {+ signal.addEventListener("abort", () => resolve(), { once: true });+ });+}+/*** Probe account information by spawning a lightweight Claude Agent SDK* session and reading the initialization result.*- * The prompt is never sent to the Anthropic API — we abort immediately- * after the local initialization phase completes. This gives us the- * user's subscription type without incurring any token cost.+ * We pass a never-yielding AsyncIterable as the prompt so that no user+ * message is ever written to the subprocess stdin. This means the Claude+ * Code subprocess completes its local initialization IPC (returning+ * account info and slash commands) but never starts an API request to+ * Anthropic. We read the init data and then abort the subprocess.** This is used as a fallback when `claude auth status` does not include* subscription type information.@@ -495,12 +507,16 @@ const probeClaudeCapabilities = (binaryPath: string) => {const abort = new AbortController();return Effect.tryPromise(async () => {const q = claudeQuery({- prompt: ".",+ // Never yield — we only need initialization data, not a conversation.+ // This prevents any prompt from reaching the Anthropic API.+ // oxlint-disable-next-line require-yield+ prompt: (async function* (): AsyncGenerator<SDKUserMessage> {+ await waitForAbortSignal(abort.signal);+ })(),options: {persistSession: false,pathToClaudeCodeExecutable: binaryPath,abortController: abort,- maxTurns: 0,settingSources: ["user", "project", "local"],allowedTools: [],stderr: () => {},