From e26572941bd38546f628cbe5b307b2954573722e Mon Sep 17 00:00:00 2001 From: pomelo-nwu Date: Mon, 10 Nov 2025 14:50:32 +0800 Subject: [PATCH] fix(core): use start /b for background execution on Windows --- packages/core/src/tools/shell.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts index b5f48672..90a75eeb 100644 --- a/packages/core/src/tools/shell.ts +++ b/packages/core/src/tools/shell.ts @@ -139,9 +139,21 @@ export class ShellToolInvocation extends BaseToolInvocation< const shouldRunInBackground = this.params.is_background; let finalCommand = processedCommand; - // If explicitly marked as background and doesn't already end with &, add it - if (shouldRunInBackground && !finalCommand.trim().endsWith('&')) { - finalCommand = finalCommand.trim() + ' &'; + // Handle background execution differently for Windows and Unix systems + if (shouldRunInBackground) { + if (isWindows) { + // Windows uses 'start /b' for background execution + // Check if command already starts with 'start /b' to avoid double wrapping + const trimmed = finalCommand.trim(); + if (!trimmed.toLowerCase().startsWith('start /b')) { + finalCommand = `start /b ${trimmed}`; + } + } else { + // Unix systems use '&' for background execution + if (!finalCommand.trim().endsWith('&')) { + finalCommand = finalCommand.trim() + ' &'; + } + } } // pgrep is not available on Windows, so we can't get background PIDs