From 939b44b39fbe1eeea0d4c501e820f23ea5079c87 Mon Sep 17 00:00:00 2001 From: shanevcantwell <153727980+shanevcantwell@users.noreply.github.com> Date: Mon, 26 Jan 2026 18:51:11 -0700 Subject: [PATCH] fix: detect WSL remote for shell PATH resolution When Windows host connects to WSL remote, getEnvPathFromUserShell() was returning undefined because it checked only process.platform === "win32". Add remoteName parameter to getEnvPathFromUserShell() and use the isWindowsHostWithWslRemote pattern (consistent with resolveCommandForPlatform) to allow shell PATH detection for WSL remotes. Fixes #9737 Co-Authored-By: Claude Opus 4.5 --- core/context/mcp/MCPConnection.ts | 11 ++++++++--- core/util/shellPath.ts | 9 ++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/context/mcp/MCPConnection.ts b/core/context/mcp/MCPConnection.ts index 0271c1edd..882704c4f 100644 --- a/core/context/mcp/MCPConnection.ts +++ b/core/context/mcp/MCPConnection.ts @@ -563,10 +563,15 @@ Org-level secrets can only be used for MCP by Background Agents (https://docs.co // Set the initial PATH from process.env env.PATH = process.env.PATH; - // For non-Windows platforms, try to get the PATH from user shell - if (process.platform !== "win32") { + // For non-Windows platforms or WSL remotes, try to get the PATH from user shell + const ideInfo = await this.extras?.ide?.getIdeInfo(); + const isWindowsHostWithWslRemote = + process.platform === "win32" && ideInfo?.remoteName === "wsl"; + if (process.platform !== "win32" || isWindowsHostWithWslRemote) { try { - const shellEnvPath = await getEnvPathFromUserShell(); + const shellEnvPath = await getEnvPathFromUserShell( + ideInfo?.remoteName, + ); if (shellEnvPath && shellEnvPath !== process.env.PATH) { env.PATH = shellEnvPath; } diff --git a/core/util/shellPath.ts b/core/util/shellPath.ts index a33eeb45e..961307c28 100644 --- a/core/util/shellPath.ts +++ b/core/util/shellPath.ts @@ -2,9 +2,12 @@ import { exec } from "child_process"; import { promisify } from "util"; const execAsync = promisify(exec); -export async function getEnvPathFromUserShell(): Promise { - if (process.platform === "win32") { - console.warn(`${getEnvPathFromUserShell.name} not implemented for Windows`); +export async function getEnvPathFromUserShell( + remoteName?: string, +): Promise { + const isWindowsHostWithWslRemote = + process.platform === "win32" && remoteName === "wsl"; + if (process.platform === "win32" && !isWindowsHostWithWslRemote) { return undefined; }