From d7a6f1e2525cb07878312c0ec44d2b93d23320c6 Mon Sep 17 00:00:00 2001 From: Miguel Morales Date: Mon, 1 Jun 2026 11:19:36 -0600 Subject: [PATCH] Use direct WSL exec for absolute agent commands In WSL mode, launch simple absolute-path agent commands with `wsl.exe --cd --exec ...args` instead of routing them through the nested shell wrapper. This avoids fragile `sh -c` quoting behavior when launching agents from Windows into WSL, especially for executable+argv CLIs such as OpenCode, Codex, Claude Code, and similar tools. The existing shell-wrapper path is preserved for commands that may need shell semantics, including relative commands, PATH injection via `additionalPath`, or commands containing shell metacharacters. This keeps compatibility with existing configurations that rely on shell expansion or login-shell behavior while allowing straightforward WSL executables to launch without unnecessary quoting layers. --- src/utils/platform.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/utils/platform.ts b/src/utils/platform.ts index 6f013c7..84c321f 100644 --- a/src/utils/platform.ts +++ b/src/utils/platform.ts @@ -307,13 +307,29 @@ export function wrapCommandForWsl( pathPrefix = `export PATH="${escapePathForShell(wslPath)}:$PATH"; `; } - const innerCommand = `${pathPrefix}cd ${escapeShellArgBash(wslCwd)} && ${command}${argsString}`; - wslArgs.push("sh", "-c", buildWslShellWrapper(innerCommand)); + const commandIsAbsoluteWslPath = command.startsWith("/"); + const commandHasShellSyntax = /[\s"'`$&|;<>(){}[\]*?!\\]/.test(command); + const canUseDirectExec = + commandIsAbsoluteWslPath && + !commandHasShellSyntax && + !additionalPath; - return { - command: "C:\\Windows\\System32\\wsl.exe", - args: wslArgs, - }; + if (canUseDirectExec) { + wslArgs.push("--cd", wslCwd, "--exec", command, ...args); + + return { + command: "C:\\Windows\\System32\\wsl.exe", + args: wslArgs, + }; + } + + const innerCommand = `${pathPrefix}cd ${escapeShellArgBash(wslCwd)} && ${command}${argsString}`; + wslArgs.push("sh", "-c", buildWslShellWrapper(innerCommand)); + + return { + command: "C:\\Windows\\System32\\wsl.exe", + args: wslArgs, + }; } /**