[Bug] Windows shell resolution picks WSL bash.exe over Git Bash, breaking Windows commands #1437
Replies: 2 comments
Root cause analysis\n\nThe bug is in , function (line ~15-28).\n\nOn Windows, returns ALL matches in PATH order. WSL's entry point typically appears before Git Bash because is earlier in PATH. The function takes \u2014 the first match \u2014 without checking whether it is WSL bash.\n\nWSL bash runs in Linux mode and cannot execute Windows / shims. The function in handles known package managers (npmUsage: npm install install all the dependencies in your project All commands: Specify configs in the ini-formatted file: More configuration info: npm help config npm@10.9.7 /home/tony/.hermes/node/lib/node_modules/npm, , Version 10.33.0 (compiled to binary; bundled Node.js v20.11.1) These are common pnpm commands used in various situations, use 'pnpm help -a' to list all commands Manage your dependencies: Review your dependencies: Run your scripts: Other: Options: |
Root cause analysisThe bug is in On Windows, WSL bash runs in Linux mode and cannot execute Windows Suggested fixIn if (process.platform === "win32") {
try {
const result = spawnSync("where", ["bash.exe"], { encoding: "utf-8", timeout: 5000 });
if (result.status === 0 && result.stdout) {
const matches = result.stdout.trim().split(/\r?\n/);
// Prefer non-WSL bash: skip C:\Windows\System32\bash.exe which
// is the WSL entry point and runs in Linux mode — it cannot
// execute Windows .cmd/.bat shims.
const nonWsl = matches.find(
(m) => m && existsSync(m) && !m.toLowerCase().includes("\\system32\\")
);
if (nonWsl) return nonWsl;
// If only WSL bash exists, use it but log a warning so the
// user understands why Windows commands may fail.
const firstMatch = matches.find((m) => m && existsSync(m));
if (firstMatch) {
console.warn(
`[prime-agent] Using WSL bash (${firstMatch}). ` +
`Windows .cmd/.bat commands may not work correctly. ` +
`Install Git for Windows for full compatibility.`
);
return firstMatch;
}
}
} catch {
// Ignore errors
}
return null;
}Alternative approachIf the project prefers to avoid ImpactThis affects any Windows user with WSL installed but Git for Windows not installed. The current behavior silently picks the wrong shell, causing confusing failures in tool calls that spawn child processes. The fix is backward-compatible: users with Git Bash installed are unaffected (Git Bash is already found first by the |
Uh oh!
There was an error while loading. Please reload this page.
Affected area
Coding agent and CLI (Windows)
What happened?
On Windows with WSL installed, the shell resolution in
packages/coding-agent/src/utils/shell.tscan resolve to WSL'sbash.exeinstead of Git Bash. ThefindBashOnPath()function useswhere bash.exewhich may returnC:\Windows\System32\bash.exe(WSL's entry point) before Git Bash's location.WSL bash runs in Linux mode — it cannot execute Windows
.cmdor.batshims. TheshouldUseWindowsShell()function inpackages/coding-agent/src/utils/child-process.tshandles known package managers (npm,npx,pnpm,yarn,corepack), but arbitrary Windows commands passed through the bash tool would fail silently or produce confusing errors.The resolution order in
getShellConfig()is:shellPathfrom settingsProgram Files\Git\bin\bash.exebash.exeon PATH (Cygwin, MSYS2, WSL)Step 3 does not distinguish between MSYS2/Cygwin bash (which can run Windows commands) and WSL bash (which cannot). If Git for Windows is not installed but WSL is, Prime Agent silently picks the wrong shell.
Steps to reproduce
where bash.exereturnsC:\Windows\System32\bash.exefirst.prime-agentand execute a bash tool call that runs a Windows.cmdcommand.Expected behavior
The shell resolution should detect WSL bash and either:
The current
windows.mddocs list "WSL" as a valid bash source without noting this incompatibility.Prime Agent version
0.7.2 (source checkout at
main)Environment
Windows 11, WSL2 (Ubuntu), Node.js 24.x
Additional context
A potential fix would be to check if the resolved bash.exe path matches
C:\Windows\System32\bash.exe(or more robustly, check if the path containsSystem32) and either skip it or add a warning. The existing comment inshell.ts:81mentions WSL as a valid source, but the behavior is undocumented.Happy to test a fix on my Windows/WSL setup if maintainers consider this in scope.
All reactions