-
Notifications
You must be signed in to change notification settings - Fork 164
[Windows] Failed to spawn agent command: spawn with shell:false cannot run .cmd files #90
Description
Description
When acpx uses Node.js child_process.spawn to launch subprocesses on Windows with shell: false, it fails to properly recognize and execute .cmd files like npx.cmd.
Current Code Pattern
spawn('npx.cmd', ['claude'], { shell: false, ... })
Problems on Windows
-
.cmd files require a shell: When shell: false, Node.js cannot directly execute .cmd files because they are not native executables - they require cmd.exe to interpret them.
-
Path with spaces not handled: The default Node.js path D:\Program Files\nodejs\npx.cmd contains spaces, which can cause additional issues when not properly quoted or handled.
-
Error behavior: The spawn call may fail with ENOENT (file not found) error.
Error Message
Failed to spawn agent command: D:\Program Files\nodejs\npx.cmd
Root Cause
The .cmd batch files on Windows are not directly executable - they need to be run through cmd.exe.
Recommended Solutions
Option 1: Use shell: true
spawn('npx.cmd', ['claude'], { shell: true })
Option 2: Explicitly use cmd.exe (Recommended)
spawn('cmd.exe', ['/c', 'npx', 'claude'], { shell: false })
Option 3: Use npx directly without .cmd extension
spawn('D:/Program Files/nodejs/npx', ['claude'])
Environment
- OS: Windows 10/11
- Node.js: v22.x
- acpx: 0.1.15
Expected Behavior
acpx should successfully spawn subprocesses on Windows without requiring users to manually configure shell execution.