From 08b162f9a9477ad72b8f2ca7e9bc31eb1ce604e7 Mon Sep 17 00:00:00 2001 From: Rahul Sehrawat Date: Fri, 10 Apr 2026 00:11:50 -0700 Subject: [PATCH] fix: unset CLAUDECODE env var to allow Agent SDK inside Claude Code sessions When OpenAlice is launched from within a Claude Code terminal session, the CLAUDECODE environment variable is inherited by the process. When the Agent SDK then spawns a Claude Code subprocess, it detects this variable and refuses to start with "Claude Code cannot be launched inside another Claude Code session" (exit code 1). Fix: delete CLAUDECODE from the spawned process environment so the subprocess starts cleanly. This is safe because each Agent SDK query is an independent, non-interactive session. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/ai-providers/agent-sdk/query.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ai-providers/agent-sdk/query.ts b/src/ai-providers/agent-sdk/query.ts index b96311c3..91d9c352 100644 --- a/src/ai-providers/agent-sdk/query.ts +++ b/src/ai-providers/agent-sdk/query.ts @@ -122,6 +122,8 @@ export async function askAgentSdk( const isOAuthMode = loginMethod === 'claudeai' const env: Record = { ...process.env } + // Allow spawning inside an existing Claude Code session + delete env.CLAUDECODE if (isOAuthMode) { // Force OAuth by removing any inherited API key delete env.ANTHROPIC_API_KEY