fix(agents): quote bin path on Windows to support spaces in PATH#97
fix(agents): quote bin path on Windows to support spaces in PATH#97lxyAK wants to merge 2 commits into
Conversation
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>
nettee
left a comment
There was a problem hiding this comment.
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, { |
There was a problem hiding this comment.
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.
nettee
left a comment
There was a problem hiding this comment.
@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.
Summary
spawnwithshell: trueconcatenates 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.exesplits on the space and fails with'C:\Program' is not recognized as an internal or external command.binin double quotes whenuseShellis true, socmd.execorrectly parses paths containing spaces.Root cause
next/src/lib/agents/invoke.tsline 161 —spawn(bin!, argv, { shell: true })on Windows passes the unquotedbintocmd.exe /c, which breaks on spaces.Test plan
C:\Program Files\nodejs\node_global\claude.CMD, press Ctrl+Enter in the editor → agent spawns successfully and streams HTMLevent: startfollowed byevent: delta(real content) instead ofevent: stderr+event: done(exit code 1)🤖 Generated with Claude Code