From 17a32b14d48eaeca28ed79fe5950b73ba8301522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=AFs=20Betts?= Date: Wed, 20 Nov 2024 14:41:53 +0100 Subject: [PATCH 1/2] Use detached: true on Windows Unfortunately, the fix in #55 was not sufficient - the behavior of spawn depends on the "console'ness" of the originally launched process, which has the effect of development behavior for Claude Desktop on Windows being different than in production, since the launching process is Claude.exe (a Win32 Subsystem app) vs `yarn start` which is effectively a Console Subsystem app. --- src/client/stdio.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/stdio.ts b/src/client/stdio.ts index 1871091..af9841f 100644 --- a/src/client/stdio.ts +++ b/src/client/stdio.ts @@ -112,6 +112,7 @@ export class StdioClientTransport implements Transport { env: this._serverParams.env ?? getDefaultEnvironment(), stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"], shell: false, + detached: process.platform === "win32", signal: this._abortController.signal, }, ); From e0c821cad9f887abf8307f86e8f0ed81ea6a6990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=AFs=20Betts?= Date: Wed, 20 Nov 2024 15:54:13 +0100 Subject: [PATCH 2/2] Special-case this fix to Electron apps --- src/client/stdio.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/client/stdio.ts b/src/client/stdio.ts index af9841f..4c78b35 100644 --- a/src/client/stdio.ts +++ b/src/client/stdio.ts @@ -112,9 +112,18 @@ export class StdioClientTransport implements Transport { env: this._serverParams.env ?? getDefaultEnvironment(), stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"], shell: false, - detached: process.platform === "win32", signal: this._abortController.signal, - }, + + // NB: The behavior of detached varies based on platform, and also + // is different based on whether the process is a Win32 Subsystem + // process or a Console Subsystem process. Strangely, the behavior + // of detached is almost 1:1 the opposite in Electron+Windows vs + // what is documented on the node.js website, and also is different + // based on whether you launch Electron in a development environment + // (i.e. via `electron-forge start`) vs a production environment + // (i.e. YourApp.exe). + detached: process.platform === "win32" && isElectron(), + } ); this._process.on("error", (error) => { @@ -188,3 +197,7 @@ export class StdioClientTransport implements Transport { }); } } + +function isElectron() { + return "type" in process; +}