@devries-cameron20 / t3code Mirror · read-only / commits / 8dbcf92a0d
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 25, 06:15 UTC

fix(server): prevent probeClaudeCapabilities from wasting API requests (#2192)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

reasv committed Apr 20, 2026 at 02:13 UTC 8dbcf92a0d125050988474f258df3e55c538efec
1 file changed +21 -5
apps/server/src/provider/Layers/ClaudeProvider.ts
+21 -5
@@ -14,6 +14,7 @@ import { decodeJsonResult } from "@t3tools/shared/schemaJson";
14 import {
15 query as claudeQuery,
16 type SlashCommand as ClaudeSlashCommand,
17 + type SDKUserMessage,
18 } from "@anthropic-ai/claude-agent-sdk";
19
20 import {
@@ -480,13 +481,24 @@ function dedupeSlashCommands(
481 return [...commandsByName.values()];
482 }
483
484 +function waitForAbortSignal(signal: AbortSignal): Promise<void> {
485 + if (signal.aborted) {
486 + return Promise.resolve();
487 + }
488 + return new Promise((resolve) => {
489 + signal.addEventListener("abort", () => resolve(), { once: true });
490 + });
491 +}
492 +
493 /**
494 * Probe account information by spawning a lightweight Claude Agent SDK
495 * session and reading the initialization result.
496 *
487 - * The prompt is never sent to the Anthropic API — we abort immediately
488 - * after the local initialization phase completes. This gives us the
489 - * user's subscription type without incurring any token cost.
497 + * We pass a never-yielding AsyncIterable as the prompt so that no user
498 + * message is ever written to the subprocess stdin. This means the Claude
499 + * Code subprocess completes its local initialization IPC (returning
500 + * account info and slash commands) but never starts an API request to
501 + * Anthropic. We read the init data and then abort the subprocess.
502 *
503 * This is used as a fallback when `claude auth status` does not include
504 * subscription type information.
@@ -495,12 +507,16 @@ const probeClaudeCapabilities = (binaryPath: string) => {
507 const abort = new AbortController();
508 return Effect.tryPromise(async () => {
509 const q = claudeQuery({
498 - prompt: ".",
510 + // Never yield — we only need initialization data, not a conversation.
511 + // This prevents any prompt from reaching the Anthropic API.
512 + // oxlint-disable-next-line require-yield
513 + prompt: (async function* (): AsyncGenerator<SDKUserMessage> {
514 + await waitForAbortSignal(abort.signal);
515 + })(),
516 options: {
517 persistSession: false,
518 pathToClaudeCodeExecutable: binaryPath,
519 abortController: abort,
503 - maxTurns: 0,
520 settingSources: ["user", "project", "local"],
521 allowedTools: [],
522 stderr: () => {},