From 51a7acb490693f932c0b4817861e3846c047cb17 Mon Sep 17 00:00:00 2001 From: Nitay Date: Mon, 16 Feb 2026 11:10:34 +0200 Subject: [PATCH] fix: resolve 'spawn node ENOENT' when SDK spawns claude CLI Two issues prevented the Claude Agent SDK from spawning the claude process inside the Docker container: 1. The claude CLI was not installed in the container. Added 'npm install -g @anthropic-ai/claude-code' to the Dockerfile. 2. The SDK's env option received only ANTHROPIC_API_KEY and CLAUDE_CODE_MAX_OUTPUT_TOKENS, stripping PATH and all other system environment variables. The spawned claude process (a #!/usr/bin/env node script) could not locate the node binary. Fixed by spreading process.env into sdkEnv so PATH and other required vars are inherited. Amp-Thread-ID: https://ampcode.com/threads/T-019c60b1-a01e-706b-b9d0-57c573dca354 Co-authored-by: Amp --- Dockerfile | 3 +++ src/ai/claude-executor.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Dockerfile b/Dockerfile index bcfb23cf..6f6236f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -120,6 +120,9 @@ RUN npm ci && \ # Copy application source code COPY . . +# Install Claude Code CLI (required by @anthropic-ai/claude-agent-sdk) +RUN npm install -g @anthropic-ai/claude-code + # Build TypeScript (mcp-server first, then main project) RUN cd mcp-server && npm run build && cd .. && npm run build diff --git a/src/ai/claude-executor.ts b/src/ai/claude-executor.ts index ceab2d67..40439abd 100644 --- a/src/ai/claude-executor.ts +++ b/src/ai/claude-executor.ts @@ -220,7 +220,10 @@ export async function runClaudePrompt( const mcpServers = buildMcpServers(sourceDir, agentName); // Build env vars to pass to SDK subprocesses + // Spread process.env first so PATH and other system vars are inherited, + // then override with Shannon-specific vars const sdkEnv: Record = { + ...Object.fromEntries(Object.entries(process.env).filter((entry): entry is [string, string] => entry[1] != null)), CLAUDE_CODE_MAX_OUTPUT_TOKENS: process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS || '64000', }; if (process.env.ANTHROPIC_API_KEY) {