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.
This commit is contained in:
Hibryda 2026-03-06 22:12:16 +01:00
parent 4c06b5f121
commit ce79ae671a
2 changed files with 17 additions and 7 deletions

View file

@ -66,8 +66,13 @@ function handleQuery(msg: QueryMessage) {
log(`Starting agent session ${sessionId}: claude ${args.join(" ")}`); log(`Starting agent session ${sessionId}: claude ${args.join(" ")}`);
const env = { ...Deno.env.toObject() }; // Strip all CLAUDE* env vars to prevent nesting detection by claude CLI
delete env.CLAUDECODE; const env: Record<string, string> = {};
for (const [key, value] of Object.entries(Deno.env.toObject())) {
if (!key.startsWith("CLAUDE")) {
env[key] = value;
}
}
const command = new Deno.Command("claude", { const command = new Deno.Command("claude", {
args, args,

View file

@ -89,13 +89,18 @@ function handleQuery(msg: QueryMessage) {
log(`Starting agent session ${sessionId}: claude ${args.join(' ')}`); 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<string, string> = {};
for (const [key, value] of Object.entries(process.env)) {
if (!key.startsWith('CLAUDE') && value !== undefined) {
cleanEnv[key] = value;
}
}
const child = spawn('claude', args, { const child = spawn('claude', args, {
cwd: cwd || process.cwd(), cwd: cwd || process.cwd(),
env: { env: cleanEnv,
...process.env,
// Unset CLAUDECODE to avoid nesting detection
CLAUDECODE: undefined,
},
stdio: ['pipe', 'pipe', 'pipe'], stdio: ['pipe', 'pipe', 'pipe'],
}); });