Skip to content

fix(agents): quote bin path on Windows to support spaces in PATH#97

Open
lxyAK wants to merge 2 commits into
nexu-io:mainfrom
lxyAK:fix/windows-spawn-path-with-spaces
Open

fix(agents): quote bin path on Windows to support spaces in PATH#97
lxyAK wants to merge 2 commits into
nexu-io:mainfrom
lxyAK:fix/windows-spawn-path-with-spaces

Conversation

@lxyAK

@lxyAK lxyAK commented May 29, 2026

Copy link
Copy Markdown

Summary

  • On Windows, spawn with shell: true concatenates the binary path and argv into a single command string. When the resolved CLI binary lives under a directory with spaces (e.g. C:\Program Files\nodejs\node_global\claude.CMD), cmd.exe splits on the space and fails with 'C:\Program' is not recognized as an internal or external command.
  • Fix: wrap bin in double quotes when useShell is true, so cmd.exe correctly parses paths containing spaces.

Root cause

next/src/lib/agents/invoke.ts line 161 — spawn(bin!, argv, { shell: true }) on Windows passes the unquoted bin to cmd.exe /c, which breaks on spaces.

Test plan

  • On Windows 11 with Claude CLI installed at C:\Program Files\nodejs\node_global\claude.CMD, press Ctrl+Enter in the editor → agent spawns successfully and streams HTML
  • Verified SSE output shows event: start followed by event: delta (real content) instead of event: stderr + event: done (exit code 1)
  • Verify macOS/Linux behavior is unchanged (shell is not used on those platforms)

🤖 Generated with Claude Code

On Windows, `spawn` with `shell: true` concatenates the binary path
and argv into a single command string. When the resolved binary lives
under a directory with spaces (e.g. `C:\Program Files\...`), cmd.exe
splits on the space and fails with "'C:\Program' is not recognized".

Fix: wrap `bin` in double quotes when spawning through a shell.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@lefarcen lefarcen requested a review from nettee May 29, 2026 08:53
@lefarcen lefarcen added size/S Small change: 20-99 changed lines risk/medium Medium risk change type/bugfix Bug fix labels May 29, 2026

@nettee nettee left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the primary Windows launch path, but one Windows shell invocation still uses the unquoted binary path, so the PR's path-with-spaces bug is not fully resolved for OpenClaw.

🔁 Powered by Looper · runner=reviewer · agent=codex · An autonomous AI dev team for your GitHub repos.

// <text>` (argv-message), not interpolated into a shell command,
// so this does not introduce a shell-injection vector.
const useShell = process.platform === "win32";
child = spawn(useShell ? `"${bin}"` : bin!, argv, {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolveOpenclawAgentId(bin) is called just above this block for the OpenClaw path, and that helper still does spawn(bin, ["agents", "list"], { shell: process.platform === "win32" }) in next/src/lib/agents/detect.ts:363-366. On a Windows install under C:\Program Files\..., cmd.exe will split that probe exactly the same way it split the main launch path here, so OpenClaw still fails before this quoted spawn(...) ever runs. Because the helper catches the error and falls back to "main", the failure is also silent and can target the wrong agent when the configured OpenClaw agent id is not main. Please apply the same useShell ? \"${bin}"` : binhandling inresolveOpenclawAgentId`, and add regression coverage for the Windows probe path with a spaced binary location.

🔁 Powered by Looper · runner=reviewer · agent=codex · An autonomous AI dev team for your GitHub repos.

@nettee nettee left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lxyAK I re-reviewed the updated changed ranges and verified that both Windows shell entry points now quote the resolved binary path, including the OpenClaw agents list probe that was still broken on the previous head. I did not find any further actionable issues in the current diff. Nice follow-up on closing out the Windows path-with-spaces case.

🔁 Powered by Looper · runner=reviewer · agent=codex · An autonomous AI dev team for your GitHub repos.

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

Labels

risk/medium Medium risk change size/S Small change: 20-99 changed lines type/bugfix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants