From 988eee65a4faabedbceacb695a86638dc6ec2519 Mon Sep 17 00:00:00 2001 From: Gershom Rogers Date: Fri, 13 Feb 2026 08:00:57 -0500 Subject: [PATCH] fix(sdk): strip CLAUDECODE env var when spawning Claude Code process MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude Code 2.1+ sets a CLAUDECODE environment variable and refuses to launch if it detects it already present, treating it as a nested session. Since happy-cli legitimately spawns Claude Code as a child process (not a nested session), the env var must be stripped before spawning. Without this fix, every remote session immediately crashes with "Claude Code process exited with code 1" and retries 3 times before giving up. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/claude/sdk/query.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/claude/sdk/query.ts b/src/claude/sdk/query.ts index 5ec76736..a22825b6 100644 --- a/src/claude/sdk/query.ts +++ b/src/claude/sdk/query.ts @@ -340,7 +340,10 @@ export function query(config: { // Spawn Claude Code process // Use clean env for global claude to avoid local node_modules/.bin taking precedence - const spawnEnv = isCommandOnly ? getCleanEnv() : process.env + // Always strip CLAUDECODE env var to prevent nested-session detection (Claude Code 2.1+) + const baseEnv = isCommandOnly ? getCleanEnv() : { ...process.env } + delete baseEnv.CLAUDECODE + const spawnEnv = baseEnv logDebug(`Spawning Claude Code process: ${spawnCommand} ${spawnArgs.join(' ')} (using ${isCommandOnly ? 'clean' : 'normal'} env)`) const child = spawn(spawnCommand, spawnArgs, {