@anthropic-ai/claude-code SDK fails with "spawn node ENOENT" in Docker containers despite working CLI

Resolved 💬 11 comments Opened Jul 25, 2025 by JeanHaiz Closed Feb 3, 2026

Claude wrote the below entirely, happy to help if I missed something

–––––––––––––––––––––––

Bug Type: SDK/Docker Integration Issue

Severity: High - Prevents SDK usage in containerized environments

Description

The @anthropic-ai/claude-code SDK consistently fails with spawn node ENOENT error when running inside
Docker containers, despite all manual spawn operations working correctly.

Environment

  • SDK Version: @anthropic-ai/claude-code@1.0.59
  • Node Version: 22.14.0
  • Platform: Docker container (linux/amd64)
  • Base Image: node:22.14.0
  • Claude CLI Version: 1.0.60

Reproduction Steps

  1. Install @anthropic-ai/claude-code@1.0.59 in a Docker container
  2. Install Claude CLI globally (npm install -g @anthropic-ai/claude-code)
  3. Use the SDK's query() function with any configuration
  4. Observe the spawn failure

Expected Behavior

The SDK should successfully spawn the Claude Code process and execute commands.

Actual Behavior

Error: Failed to spawn Claude Code process: spawn node ENOENT
at ChildProcess.<anonymous> (file:///app/node_modules/@anthropic-ai/claude-code/sdk.mjs:235:23)

Debug Evidence

✅ What Works:

  • Direct node --version: Returns v22.14.0
  • Direct claude --version: Returns 1.0.60 (Claude Code)
  • Direct node /usr/local/bin/claude --version: Returns 1.0.60 (Claude Code)
  • Manual spawn with exact SDK command: Works perfectly

❌ What Fails:

  • SDK query() function: Always fails with spawn node ENOENT

PATH Information

PATH=/usr/local/bin:/usr/bin:/bin:/app/node_modules/.bin:...
Available node executables: /usr/local/bin/node, /usr/bin/node, /bin/node

Code Example

import { query } from '@anthropic-ai/claude-code';

// This fails with spawn node ENOENT
for await (const message of query({
prompt: "test",
options: {
permissionMode: 'bypassPermissions',
pathToClaudeCodeExecutable: '/usr/local/bin/claude'
}
})) {
// Never reached
}

Workaround

Direct CLI invocation works:
const claudeProcess = spawn('node', ['/usr/local/bin/claude', '--version']);
// This works perfectly

Root Cause Analysis

The SDK's internal spawn mechanism in sdk.mjs:235 appears to have environment inheritance issues in
Docker containers, despite the same spawn command working when called manually.

To reproduce this issue:

  1. Create a Docker container with Node.js 22.14.0
  2. Install the Claude Code SDK
  3. Try to use the query() function
  4. Observe the consistent failure

This bug makes the SDK unusable in Docker/containerized environments, which is a significant limitation
for CI/CD and deployment scenarios.

View original on GitHub ↗

This issue has 11 comments on GitHub. Read the full discussion on GitHub ↗