From c565bdc464bea6849f9c8cdba13249b7d2ccea3d Mon Sep 17 00:00:00 2001 From: shanevcantwell <153727980+shanevcantwell@users.noreply.github.com> Date: Mon, 19 Jan 2026 10:55:16 -0700 Subject: [PATCH] fix: use ide.runCommand when Windows host connects to WSL When the VS Code extension runs on Windows but connects to WSL, direct shell spawning fails because process.platform is "win32" but commands should execute in the Linux WSL environment. This caused: spawn powershell.exe ENOENT The fix detects this scenario and falls back to ide.runCommand(), letting VS Code handle the remote terminal execution properly. Fixes #9661 Co-Authored-By: Claude Opus 4.5 --- .../implementations/runTerminalCommand.ts | 11 ++++++++- .../runTerminalCommand.vitest.ts | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/core/tools/implementations/runTerminalCommand.ts b/core/tools/implementations/runTerminalCommand.ts index bed8aceb8..e3bb9374d 100644 --- a/core/tools/implementations/runTerminalCommand.ts +++ b/core/tools/implementations/runTerminalCommand.ts @@ -114,7 +114,16 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { const ideInfo = await extras.ide.getIdeInfo(); const toolCallId = extras.toolCallId || ""; - if (ENABLED_FOR_REMOTES.includes(ideInfo.remoteName)) { + // When extension host runs on Windows but connects to WSL, we can't spawn + // shells directly - the platform is "win32" but commands should run in Linux. + // Use ide.runCommand() instead to let VS Code handle the remote execution. + const isWindowsHostWithWslRemote = + process.platform === "win32" && ideInfo.remoteName === "wsl"; + + if ( + ENABLED_FOR_REMOTES.includes(ideInfo.remoteName) && + !isWindowsHostWithWslRemote + ) { // For streaming output if (extras.onPartialOutput) { try { diff --git a/core/tools/implementations/runTerminalCommand.vitest.ts b/core/tools/implementations/runTerminalCommand.vitest.ts index 089c85502..ea502f7c0 100644 --- a/core/tools/implementations/runTerminalCommand.vitest.ts +++ b/core/tools/implementations/runTerminalCommand.vitest.ts @@ -644,6 +644,30 @@ describe("runTerminalCommandImpl", () => { ).resolves.toBeDefined(); }); + it("should use ide.runCommand when Windows host connects to WSL", async () => { + // When extension runs on Windows but connects to WSL, we can't spawn + // shells directly - must use ide.runCommand instead + const originalPlatform = process.platform; + Object.defineProperty(process, "platform", { value: "win32" }); + + try { + const extras = createMockExtras({ remoteName: "wsl" }); + + const result = await runTerminalCommandImpl( + { command: "echo test" }, + extras, + ); + + // Should fall back to ide.runCommand, not try to spawn powershell.exe + expect(mockRunCommand).toHaveBeenCalledWith("echo test"); + expect(result[0].content).toContain("Terminal output not available"); + } finally { + Object.defineProperty(process, "platform", { + value: originalPlatform, + }); + } + }); + it("should handle dev-container environment", async () => { mockGetWorkspaceDirs.mockResolvedValue(["file:///workspace"]);