From a6866458ecaa105133bd99c7425880b8cfe3dd0c Mon Sep 17 00:00:00 2001 From: Prateek Date: Mon, 16 Feb 2026 05:51:05 +0530 Subject: [PATCH] fix: unset CLAUDECODE in spawned sessions to prevent nested session errors The spawn command was creating tmux sessions without calling agent.getEnvironment(), causing spawned sessions to inherit CLAUDECODE from the parent orchestrator session. This caused Claude to refuse to start with "cannot launch inside another Claude Code session" error. Now properly calls agent.getEnvironment() and merges those env vars (including CLAUDECODE="") into the tmux session creation. Fixes sessions ao-22 through ao-25 which were spawned but never had Claude running. Co-Authored-By: Claude Sonnet 4.5 --- packages/cli/src/commands/spawn.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/spawn.ts b/packages/cli/src/commands/spawn.ts index ddbf2083d..93890fad6 100644 --- a/packages/cli/src/commands/spawn.ts +++ b/packages/cli/src/commands/spawn.ts @@ -133,9 +133,17 @@ async function spawnSession( spinner.text = "Creating tmux session"; + // Get agent-specific environment variables (e.g., unset CLAUDECODE) + const agentEnv = agent.getEnvironment({ + sessionId: sessionName, + projectConfig: project, + issueId, + permissions: project.agentConfig?.permissions, + }); + // Create tmux session const envVar = `${prefix.toUpperCase().replace(/[^A-Z0-9_]/g, "_")}_SESSION`; - await exec("tmux", [ + const tmuxArgs = [ "new-session", "-d", "-s", @@ -152,7 +160,14 @@ async function spawnSession( `AO_DATA_DIR=${config.dataDir}`, "-e", "DIRENV_LOG_FORMAT=", - ]); + ]; + + // Add agent environment variables + for (const [key, value] of Object.entries(agentEnv)) { + tmuxArgs.push("-e", `${key}=${value}`); + } + + await exec("tmux", tmuxArgs); // Run post-create hooks before agent launch (so environment is ready) if (project.postCreate) {