Skip to content

fix: route through cmd /c on Windows to fix ENOENT when spawning claude#5

Open
zerojarvis wants to merge 1 commit into
ShiftinBits:mainfrom
zerojarvis:fix/windows-spawn
Open

fix: route through cmd /c on Windows to fix ENOENT when spawning claude#5
zerojarvis wants to merge 1 commit into
ShiftinBits:mainfrom
zerojarvis:fix/windows-spawn

Conversation

@zerojarvis

Copy link
Copy Markdown

Problem

On Windows, child_process.spawn('claude', ...) fails with ENOENT because npm installs claude as a .cmd batch file that Node cannot execute directly without shell: true.

ClawdCommit shows this error in VS Code:

"claude" CLI not found. Install Claude Code and ensure it is in your PATH.

...even when claude is correctly installed and works in the terminal.

Root cause

npm on Windows creates three shims for any global package:

File Type spawn usable?
claude Unix shebang script No - Windows cannot exec shebang scripts
claude.cmd CMD batch file No - requires shell:true or cmd /c
claude.ps1 PowerShell script No - .PS1 not in default PATHEXT

Node's spawn (without shell:true) finds the extensionless Unix script and fails with ENOENT.

Fix

On Windows, route through cmd /c claude instead of spawning claude directly. This lets cmd.exe resolve the .cmd shim natively. Arguments are still passed as a discrete array (not a concatenated shell string), which avoids the quoting and newline pitfalls of shell: true.

Tests

  • Added routes through cmd /c on Windows test that stubs process.platform to win32
  • Updated the platform-agnostic spawn-argument tests to use expect.any(String) for the command name so they pass on both Windows and non-Windows CI
  • All 106 existing tests continue to pass

Verified on

Windows 11, Node v24.16.0, Claude Code CLI v2.1.177

Node child_process.spawn(claude) fails with ENOENT on Windows
because npm installs claude as a .cmd batch file, which cannot be
executed directly without shell:true. Routing through cmd /c claude
passes all arguments as discrete array elements, avoiding the
quoting and newline pitfalls of shell:true.

Adds a test asserting the Windows code path and updates the
platform-agnostic spawn-argument tests to match either command name.
@snyk-io

snyk-io Bot commented Jun 15, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant