Claude Code can't be spawned from node.js [BUG]

Resolved 💬 6 comments Opened Aug 22, 2025 by IgorSiilva Closed Jan 7, 2026

Environment

  • Claude CLI version: 1.0.48 (Claude Code)
  • Operating System: Linux 5.15.167.4-microsoft-standard-WSL2 (Ubuntu on WSL2)
  • Terminal: bash

Bug Description

Claude CLI hangs indefinitely when executed via Node.js spawn() with --print flag, even though it works correctly when run directly in terminal. The process never produces output and eventually times out.

Steps to Reproduce

  1. Create a Node.js script using child_process.spawn():
  const { spawn } = require('child_process');

  const claude = spawn('claude', ['--print', 'hello world'], {
      cwd: process.cwd(),
      stdio: ['pipe', 'pipe', 'pipe'],
      env: { ...process.env, FORCE_COLOR: '0' }
  });`
  1. Run the script
  2. Process hangs indefinitely with no stdout/stderr output
  3. Process must be killed manually (SIGTERM results in exit code 143)

Expected Behavior

Claude CLI should execute the command and return output via stdout, then exit with code 0, just like when run directly in terminal.

Actual Behavior

  • Process starts but never produces any output
  • No stdout or stderr data received
  • Process hangs until manually killed
  • When killed, exits with code 143 (SIGTERM)
  • Same behavior occurs with various flags: --dangerously-skip-permissions, --allowedTools, etc.

Additional Context

  • Direct terminal execution works perfectly: claude --print "hello world"
  • Issue occurs when trying to integrate Claude CLI into a Discord bot via HTTP server
  • Tested with different spawn configurations (stdio options, environment variables)
  • Problem persists across different prompts and command variations
  • Use case: Building a Discord bot that processes commands through Claude CLI programmatically

Question: What is the recommended way to execute Claude CLI programmatically from Node.js applications? Is there a specific configuration or approach that should be used for
non-interactive execution?

View original on GitHub ↗

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