Skip to content

[Windows] Failed to spawn agent command: spawn with shell:false cannot run .cmd files #90

@sipoli007

Description

@sipoli007

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

  1. .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.

  2. 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.

  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions