Skip to content

Commit 1fc5493

Browse files
authored
🤖 fix: prevent Windows bash windows from stealing focus (#901)
On Windows, when spawning bash processes (via Git Bash or WSL), the default behavior creates visible console windows that steal focus. Add `windowsHide: true` to all `spawn()` calls that run background bash or ssh processes. This prevents the console windows from appearing. The terminal service spawn calls intentionally remain visible since they're meant to open user-facing terminal windows. **Fixed locations:** - `LocalBaseRuntime.ts`: exec() and runInitHook() - `bashExecutionService.ts`: executeStreaming() - `SSHRuntime.ts`: exec(), execSSHCommand(), and bundle creation _Generated with `mux`_
1 parent 700253c commit 1fc5493

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/node/runtime/LocalBaseRuntime.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export abstract class LocalBaseRuntime implements Runtime {
9191
// NOTE: detached:true does NOT cause bash to wait for background jobs when using 'exit' event
9292
// instead of 'close' event. The 'exit' event fires when bash exits, ignoring background children.
9393
detached: true,
94+
// Prevent console window from appearing on Windows (WSL bash spawns steal focus otherwise)
95+
windowsHide: true,
9496
});
9597

9698
// Wrap in DisposableProcess for automatic cleanup
@@ -373,6 +375,8 @@ export abstract class LocalBaseRuntime implements Runtime {
373375
...process.env,
374376
...getInitHookEnv(projectPath, runtimeType),
375377
},
378+
// Prevent console window from appearing on Windows
379+
windowsHide: true,
376380
});
377381

378382
proc.stdout.on("data", (data: Buffer) => {

src/node/runtime/SSHRuntime.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ export class SSHRuntime implements Runtime {
185185
// Spawn ssh command
186186
const sshProcess = spawn("ssh", sshArgs, {
187187
stdio: ["pipe", "pipe", "pipe"],
188+
// Prevent console window from appearing on Windows
189+
windowsHide: true,
188190
});
189191

190192
// Wrap in DisposableProcess for automatic cleanup
@@ -408,7 +410,10 @@ export class SSHRuntime implements Runtime {
408410
sshArgs.push(this.config.host, command);
409411

410412
return new Promise((resolve, reject) => {
411-
const proc = spawn("ssh", sshArgs);
413+
const proc = spawn("ssh", sshArgs, {
414+
// Prevent console window from appearing on Windows
415+
windowsHide: true,
416+
});
412417
let stdout = "";
413418
let stderr = "";
414419
let timedOut = false;
@@ -591,7 +596,10 @@ export class SSHRuntime implements Runtime {
591596

592597
log.debug(`Creating bundle: ${command}`);
593598
const bashPath = getBashPath();
594-
const proc = spawn(bashPath, ["-c", command]);
599+
const proc = spawn(bashPath, ["-c", command], {
600+
// Prevent console window from appearing on Windows
601+
windowsHide: true,
602+
});
595603

596604
const cleanup = streamProcessToLogger(proc, initLogger, {
597605
logStdout: false,

src/node/services/bashExecutionService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ export class BashExecutionService {
138138
// When bash spawns background processes, detached:true allows killing
139139
// the entire group via process.kill(-pid)
140140
detached: config.detached ?? true,
141+
// Prevent console window from appearing on Windows (WSL bash spawns steal focus otherwise)
142+
windowsHide: true,
141143
});
142144

143145
log.debug(`BashExecutionService: Spawned process with PID ${child.pid ?? "unknown"}`);

0 commit comments

Comments
 (0)