fix: resolve 'spawn node ENOENT' when SDK spawns claude CLI#138
Open
nitayStain wants to merge 1 commit intoKeygraphHQ:mainfrom
Open
fix: resolve 'spawn node ENOENT' when SDK spawns claude CLI#138nitayStain wants to merge 1 commit intoKeygraphHQ:mainfrom
nitayStain wants to merge 1 commit intoKeygraphHQ:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Claude Agent SDK fails with
spawn node ENOENTwhen attempting to run any agent inside the Docker container.Root Cause
Two issues:
Missing CLI: The
claudeCLI (@anthropic-ai/claude-code) was not installed in the Docker image. The SDK'squery()function spawns it as a subprocess.Stripped PATH: The
envoption passed to the SDK contained onlyANTHROPIC_API_KEYandCLAUDE_CODE_MAX_OUTPUT_TOKENS. The SDK uses this as the complete environment for the spawned process, soPATHwas missing and theclaudescript (#!/usr/bin/env node) couldn't locatenode.Fix
npm install -g @anthropic-ai/claude-codeto install the CLI.process.envintosdkEnvsoPATHand other system variables are inherited by the spawned process.