Skip to content

fix(windows): resolve CLI detection and process spawning on Windows#1092

Open
MabuhayDesignsandCo wants to merge 3 commits intoruvnet:mainfrom
MabuhayDesignsandCo:fix/windows-cli-detection
Open

fix(windows): resolve CLI detection and process spawning on Windows#1092
MabuhayDesignsandCo wants to merge 3 commits intoruvnet:mainfrom
MabuhayDesignsandCo:fix/windows-cli-detection

Conversation

@MabuhayDesignsandCo
Copy link

Summary

Fixes Windows compatibility issues where claude-flow fails to detect Claude Code CLI and fails to spawn processes correctly on Windows.

Root cause: On Windows, the which command doesn't exist (it's where), and spawn/spawnSync/execSync calls need shell: true to resolve executables from PATH.

Changes

File Fix
hive-mind.ts Use where instead of which on win32 for Claude CLI detection
hive-mind.ts Enable shell: process.platform === 'win32' for claude process spawn
auto-install.ts Enable shell for npm spawnSync on Windows for PATH resolution
headless-worker-executor.ts Enable shell for claude --version check and claude spawn
doctor.ts Enable shell for npm install in installClaudeCode()

Additional Windows issues found (not in this PR)

During investigation, 47+ additional instances of missing Windows compatibility were identified across the codebase:

  • statusline-generator.ts: Unix-style 2>/dev/null redirections, missing shell options
  • init.ts: Unix-style & background operator, 2>/dev/null redirections
  • security.ts: Missing shell options for npm audit commands
  • browser-tools.ts: Missing shell for agent-browser spawn
  • gcs.ts: Hardcoded /tmp paths (should use os.tmpdir())
  • container-worker-pool.ts: Missing shell for docker spawn
  • Various other files with Unix-specific shell assumptions

Recommendation: Consider adding a shared shellOption() helper:

const shellOption = () => process.platform === 'win32';

Testing

Tested on:

  • OS: Windows 11
  • Shell: PowerShell + Git Bash
  • Node.js: v22+ (via nvm)
  • Claude Code: v2.1.34
  • claude-flow: v3.1.0-alpha.3

All three core scenarios now work:

  1. claude-flow doctor correctly detects Claude Code CLI
  2. claude-flow swarm successfully spawns Claude instances
  3. claude-flow mcp start auto-installs packages via npm

Closes #615

MabuhayDesignsandCo and others added 3 commits February 6, 2026 22:48
On Windows, `which` is not available — use `where` instead for CLI
detection. Additionally, spawn/spawnSync/execSync calls need
`shell: true` (or `shell: process.platform === 'win32'`) to resolve
executables from PATH on Windows.

Fixes:
- hive-mind.ts: Use `where` on win32 for claude CLI detection
- hive-mind.ts: Enable shell for claude process spawn on Windows
- auto-install.ts: Enable shell for npm spawn on Windows
- headless-worker-executor.ts: Enable shell for claude version check
  and claude process spawn on Windows
- doctor.ts: Enable shell for npm install on Windows

Closes ruvnet#615

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Instead of using shell: true (which routes through cmd.exe and introduces
command injection risks and process orphaning), resolve the claude command
to its absolute filesystem path on Windows.

Adds resolve-command.ts utility:
- resolveCommand(): scans PATH for .cmd/.bat/.exe on Windows
- isCommandAvailable(): cross-platform command existence check

This eliminates:
- Command injection via cmd.exe metacharacter escaping weaknesses
- Process orphaning where kill() targets cmd.exe instead of claude
- No-op shell options on execSync calls (which always use a shell)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove unused `join` import from path module
- Replace dynamic `require('child_process')` with top-level ESM import

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Windows PowerShell (+ nvm) Compatibility Issues

1 participant