Skip to content

fix: resolve 'spawn node ENOENT' when SDK spawns claude CLI#138

Open
nitayStain wants to merge 1 commit intoKeygraphHQ:mainfrom
nitayStain:fix/sdk-spawn-enoent
Open

fix: resolve 'spawn node ENOENT' when SDK spawns claude CLI#138
nitayStain wants to merge 1 commit intoKeygraphHQ:mainfrom
nitayStain:fix/sdk-spawn-enoent

Conversation

@nitayStain
Copy link

Problem

The Claude Agent SDK fails with spawn node ENOENT when attempting to run any agent inside the Docker container.

Root Cause

Two issues:

  1. Missing CLI: The claude CLI (@anthropic-ai/claude-code) was not installed in the Docker image. The SDK's query() function spawns it as a subprocess.

  2. Stripped PATH: The env option passed to the SDK contained only ANTHROPIC_API_KEY and CLAUDE_CODE_MAX_OUTPUT_TOKENS. The SDK uses this as the complete environment for the spawned process, so PATH was missing and the claude script (#!/usr/bin/env node) couldn't locate node.

Fix

  • Dockerfile: Added npm install -g @anthropic-ai/claude-code to install the CLI.
  • claude-executor.ts: Spread process.env into sdkEnv so PATH and other system variables are inherited by the spawned process.

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 <amp@ampcode.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant