From ce79ae671aa8245683c8d6a418fcd0f39f467f97 Mon Sep 17 00:00:00 2001 From: Hibryda Date: Fri, 6 Mar 2026 22:12:16 +0100 Subject: [PATCH] fix(v2): strip all CLAUDE* env vars in sidecar to prevent CLI nesting detection When BTerminal is launched from a Claude Code terminal, ~8 CLAUDE* env vars leak into the sidecar child processes. The claude CLI detects these as nesting indicators and silently hangs. Previously only CLAUDECODE was removed; now all CLAUDE-prefixed vars are stripped in both Node.js and Deno sidecar runners. --- v2/sidecar/agent-runner-deno.ts | 9 +++++++-- v2/sidecar/agent-runner.ts | 15 ++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/v2/sidecar/agent-runner-deno.ts b/v2/sidecar/agent-runner-deno.ts index 0808e36..6758d22 100644 --- a/v2/sidecar/agent-runner-deno.ts +++ b/v2/sidecar/agent-runner-deno.ts @@ -66,8 +66,13 @@ function handleQuery(msg: QueryMessage) { log(`Starting agent session ${sessionId}: claude ${args.join(" ")}`); - const env = { ...Deno.env.toObject() }; - delete env.CLAUDECODE; + // Strip all CLAUDE* env vars to prevent nesting detection by claude CLI + const env: Record = {}; + for (const [key, value] of Object.entries(Deno.env.toObject())) { + if (!key.startsWith("CLAUDE")) { + env[key] = value; + } + } const command = new Deno.Command("claude", { args, diff --git a/v2/sidecar/agent-runner.ts b/v2/sidecar/agent-runner.ts index b82bace..ce22c09 100644 --- a/v2/sidecar/agent-runner.ts +++ b/v2/sidecar/agent-runner.ts @@ -89,13 +89,18 @@ function handleQuery(msg: QueryMessage) { log(`Starting agent session ${sessionId}: claude ${args.join(' ')}`); + // Strip all CLAUDE* env vars to prevent nesting detection by claude CLI. + // When BTerminal is launched from a Claude Code terminal, these leak in. + const cleanEnv: Record = {}; + for (const [key, value] of Object.entries(process.env)) { + if (!key.startsWith('CLAUDE') && value !== undefined) { + cleanEnv[key] = value; + } + } + const child = spawn('claude', args, { cwd: cwd || process.cwd(), - env: { - ...process.env, - // Unset CLAUDECODE to avoid nesting detection - CLAUDECODE: undefined, - }, + env: cleanEnv, stdio: ['pipe', 'pipe', 'pipe'], });