-
Notifications
You must be signed in to change notification settings - Fork 197
Description
TL;DR
The Claude Agent SDK (@anthropic-ai/[email protected]) fails to spawn the Claude Code CLI (@anthropic-ai/[email protected]) inside a Cloudflare Container with spawn /usr/local/bin/claude ENOENT, despite the binary being installed and the pathToClaudeCodeExecutable option being explicitly set.
Related claude-code issue: anthropics/claude-code#14464
Environment
| Component | Value |
|---|---|
@anthropic-ai/claude-agent-sdk |
0.1.72 (installed in /opt/claude-agent-sdk/) |
@anthropic-ai/claude-code |
2.0.72 (global install via npm install -g) |
| Base Image | docker.io/cloudflare/sandbox:0.6.6 |
| Node.js | v24 (from base image) |
| Runtime | Cloudflare Containers (Durable Objects) |
Error Details
Error Message:
Failed to spawn Claude Code process: spawn /usr/local/bin/claude ENOENT
Error Code: SPAWN_ERROR
Exit Code: 1
Retryable: false
Stack Trace:
Error: Failed to spawn Claude Code process: spawn /usr/local/bin/claude ENOENT
at ChildProcess.<anonymous> (file:///opt/claude-agent-sdk/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs:13223:28)
at ChildProcess.emit (node:events:524:28)
at ChildProcess._handle.onexit (node:internal/child_process:293:12)
SDK Configuration Used
import { query } from '@anthropic-ai/claude-agent-sdk';
const options = {
cwd,
permissionMode: 'bypassPermissions',
maxTurns: 100,
// Explicit path to bypass PATH lookup
pathToClaudeCodeExecutable: '/usr/local/bin/claude',
executable: 'node',
env: {
PATH: '/usr/local/bin:/usr/bin:/bin',
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY,
HOME: '/root',
NODE_ENV: 'production',
},
};
const response = await query({ prompt, options });Expected Behavior
The SDK should spawn /usr/local/bin/claude successfully because:
- The Dockerfile runs
npm install -g @anthropic-ai/[email protected]which creates/usr/local/bin/claude - We explicitly pass
pathToClaudeCodeExecutable: '/usr/local/bin/claude' - We explicitly pass
executable: 'node' - We explicitly pass
env.PATHincluding/usr/local/bin
Actual Behavior
The SDK throws ENOENT at sdk.mjs:13223 when attempting to spawn the process.
Key Observation
Pre-flight validation passes: Before calling query(), we verify the executable exists:
import { accessSync, constants } from 'fs';
accessSync('/usr/local/bin/claude', constants.X_OK); // This succeeds!This confirms the binary exists and is executable, but the SDK still fails with ENOENT.
Dockerfile (Relevant Sections)
FROM docker.io/cloudflare/sandbox:0.6.6
# Global install creates /usr/local/bin/claude
RUN npm install -g [email protected] && \
npm install -g @anthropic-ai/[email protected] && \
npm cache clean --force
# Local SDK installation
ARG CLAUDE_SDK_VERSION=0.1.72
RUN mkdir -p /opt/claude-agent-sdk && \
cd /opt/claude-agent-sdk && \
npm init -y && \
npm install "@anthropic-ai/claude-agent-sdk@${CLAUDE_SDK_VERSION}"
ENV PATH="/usr/local/bin:/usr/bin:/bin:/root/.local/bin:$PATH"Questions
-
At
sdk.mjs:13223, what exact command/path is being passed tochild_process.spawn()? Is it using ourpathToClaudeCodeExecutablevalue or something else? -
Does the SDK spawn the Claude Code CLI directly, or does it spawn an intermediate process (e.g.,
npx,node, or a wrapper script)? -
Are there any additional environment variables or options required for Docker/container environments that aren't documented?
-
Is there a debug mode or verbose logging option in the SDK to capture the actual spawn arguments?
-
Does SDK version
0.1.72have any known issues withpathToClaudeCodeExecutablebeing ignored?
Reproduction Steps
- Build container with the Dockerfile above
- Deploy to Cloudflare Containers (or any Docker environment)
- Call
query()from@anthropic-ai/claude-agent-sdk - Observe ENOENT error
Related Issues
- @anthropic-ai/claude-code SDK fails with "spawn node ENOENT" in Docker containers despite working CLI claude-code#4383 (similar PATH inheritance issue in Docker)
- spawn ENOENT when using pathToClaudeCodeExecutable in Docker container claude-code#14464 (cross-posted issue)