Skip to content

Windows: console window pops up on every browse server start (subprocess spawns missing windowsHide) #2182

Closed

Description

@tomfluff

Summary

On Windows, a console window (a Windows Terminal window on Win11) pops up every time the browse server starts. Several console-subprocess spawns are missing windowsHide: true.

Environment

  • Windows 11 (10.0.26200), gstack v1.58.5.0
  • bun 1.3.14, node v22.23.1

Root cause

On Windows, spawning a console subprocess without windowsHide: true allocates a console window (windowsHide maps to the CREATE_NO_WINDOW creation flag; Node's default is false). Enumerating top-level windows (EnumWindows) during server start showed the popup owned by WindowsTerminal, running:

  • icacls.exe — ACL lockdown of state/log files at startup (file-permissions.ts, execFileSync)
  • tasklist.exe — PID liveness probe (error-handling.ts, via the Bun.spawnSync polyfill)

The Bun polyfill wrapper (bun-polyfill.cjs) also drops any windowsHide the caller passes, so per-call fixes wouldn't stick — best fixed centrally there. Also patched the detached server launcher (cli.ts) and the detached telemetry spawn (security.ts) defensively.

Fix

diff --git a/browse/src/bun-polyfill.cjs b/browse/src/bun-polyfill.cjs
index e0ada11..4307659 100644
--- a/browse/src/bun-polyfill.cjs
+++ b/browse/src/bun-polyfill.cjs
@@ -75,6 +75,7 @@ globalThis.Bun = {
       timeout: options.timeout,
       env: options.env,
       cwd: options.cwd,
+      windowsHide: true, // don't pop a console window for CLI tools (icacls, tasklist, …) on Windows
     });
 
     return {
@@ -91,6 +92,7 @@ globalThis.Bun = {
       stdio,
       env: options.env,
       cwd: options.cwd,
+      windowsHide: true, // don't pop a console window for CLI tools on Windows
     });
 
     return {
diff --git a/browse/src/cli.ts b/browse/src/cli.ts
index 59327b7..e4a9f91 100644
--- a/browse/src/cli.ts
+++ b/browse/src/cli.ts
@@ -323,7 +323,9 @@ async function startServer(extraEnv?: Record<string, string>): Promise<ServerSta
     const launcherCode =
       `const{spawn}=require('child_process');` +
       `spawn(process.execPath,[${JSON.stringify(NODE_SERVER_SCRIPT)}],` +
-      `{detached:true,stdio:['ignore','ignore','ignore'],env:Object.assign({},process.env,` +
+      // windowsHide: a detached child otherwise gets its own console window on
+      // Windows (Node default windowsHide:false) — suppress that popup.
+      `{detached:true,windowsHide:true,stdio:['ignore','ignore','ignore'],env:Object.assign({},process.env,` +
       `${extraEnvStr})}).unref()`;
     Bun.spawnSync(['node', '-e', launcherCode], { stdio: ['ignore', 'ignore', 'ignore'] });
   } else {
diff --git a/browse/src/file-permissions.ts b/browse/src/file-permissions.ts
index d3d404a..df204c7 100644
--- a/browse/src/file-permissions.ts
+++ b/browse/src/file-permissions.ts
@@ -71,7 +71,7 @@ export function restrictFilePermissions(filePath: string): void {
       execFileSync(
         'icacls',
         [filePath, '/inheritance:r', '/grant:r', `${user}:(F)`],
-        { stdio: 'ignore' },
+        { stdio: 'ignore', windowsHide: true },
       );
     } catch (err) {
       warnIcaclsFailure(filePath, err);
@@ -101,7 +101,7 @@ export function restrictDirectoryPermissions(dirPath: string): void {
       execFileSync(
         'icacls',
         [dirPath, '/inheritance:r', '/grant:r', `${user}:(OI)(CI)(F)`],
-        { stdio: 'ignore' },
+        { stdio: 'ignore', windowsHide: true },
       );
     } catch (err) {
       warnIcaclsFailure(dirPath, err);
diff --git a/browse/src/security.ts b/browse/src/security.ts
index d0e4039..fec8762 100644
--- a/browse/src/security.ts
+++ b/browse/src/security.ts
@@ -494,6 +494,7 @@ function reportAttemptTelemetry(record: AttemptRecord): void {
     const child = spawn(result.cmd, result.cmdArgs, {
       stdio: 'ignore',
       detached: true,
+      windowsHide: true, // detached child would otherwise pop a console window on Windows
     });
     // unref so this subprocess doesn't hold the event loop open
     child.unref();

Verification

Re-ran the EnumWindows diff around server start before/after — the icacls/tasklist Windows Terminal popups are gone. Windows-only; windowsHide is ignored on other platforms, so no behavior change elsewhere.

Note (separate, upstream)

There's a second popup source: Playwright's own browser spawn (chrome-headless-shell.exe) also lacks windowsHide in playwright-core's processLauncher.js. Filed separately upstream — not part of this change.

Activity

  1. tomfluff commented on Jul 12, 2026

    @tomfluff
    ContributorAuthor

    Still reproduces on v1.60.1.0. Re-verified the diff above and found a third popup source that the same central fix already covers, plus a detection gotcha that made me (briefly) conclude the fix didn't work.

    Third source: bun run terminal-agent.ts

    Beyond icacls and tasklist, a popup appears whose window title is the bun binary path:

    C:\Users\<user>\.bun\bin\bun.exe
    

    It comes from the terminal-agent:

    bun run <gstack>/browse/src/terminal-agent.ts        <- bun.exe
      parent: node <gstack>/browse/dist/server-node.mjs  <- the browse server
    

    spawnTerminalAgent() (browse/src/terminal-agent-control.ts) launches it via Bun.spawn(['bun', 'run', script], …). On Windows the browse server runs under node (server-node.mjs), so that Bun.spawn resolves to the bun-polyfill.cjs shim — i.e. it is already covered by the central windowsHide fix in the diff above. No extra change needed.

    Why it pops: the server is spawned detached and has no console of its own, so any console-subsystem child it spawns (here bun.exe) causes Windows to allocate a new console — with a window. Also note the server's watchdog respawns the terminal-agent when it dies, which is why the popup keeps recurring rather than appearing once.

    Detection gotcha (worth knowing before verifying)

    windowsHide → CREATE_NO_WINDOW does not stop the console from being created — it stops the console's window. A headless conhost.exe is still spawned as a child of the console app in both cases.

    So these two checks show no difference and will make you think the fix is a no-op:

    • counting conhost.exe processes
    • checking Process.MainWindowHandle on bun.exe (it's always 0 — on Win11 the window belongs to the console host, not the app)

    The signal is the Windows Terminal window (EnumWindows, as in the original report). A/B on the exact code path (console-less detached node parent → polyfill Bun.spawn → bun.exe), run twice:

    polyfill WindowsTerminal windows title
    unpatched 0 → 1 C:\Users\<user>\.bun\bin\bun.exe
    patched (diff above) 0 → 0 —

    One more verification trap

    A browse server started before the rebuild keeps running the old polyfill and keeps respawning agents, so the popups continue even after ./setup rebuilds the binary. The stale node …/server-node.mjs (and its bun.exe children) must be killed before testing, otherwise the fix looks ineffective.

    Related (upstream, separate)

    The 4th source, chrome-headless-shell.exe, is Playwright's own spawn and is tracked at microsoft/playwright#41630 (processLauncher.js missing windowsHide). Note the discussion there: an unconditional windowsHide: true in launchProcess() was previously landed (microsoft/playwright#38776) and then reverted (microsoft/playwright#39994) because it also hid the Inspector and codegen windows, which go through the same path — so that one needs to be opt-in for headless launches. Not applicable to the gstack-side spawns in this issue, which are all non-interactive CLI tools and the terminal-agent.

  2. biker2000on commented on Jul 13, 2026

    @biker2000on

    I independently reproduced the detached browse-server part of this on Windows 11 with gstack v1.58.5.0 and traced it to browse/src/cli.ts in startServer(). The Windows launcher creates a detached Node child without windowsHide, so the minimal fix for that persistent console window is:

    - {detached:true,stdio:['ignore','ignore','ignore'],env:...}
    + {detached:true,windowsHide:true,stdio:['ignore','ignore','ignore'],env:...}
    

    I applied that locally, rebuilt browse/dist/browse.exe, and restarted the old daemon so the rebuilt launcher was actually exercised. The focused daemonization regression suite passes (5/5), browse reports healthy, and repeated commands reuse the same server PID.

    I also added a static regression assertion around launcherCode so this cannot silently regress:

    expect(launcher).toMatch(/detached:true,windowsHide:true/);
    

    The broader patch in the issue body still looks right: fixing bun-polyfill.cjs centrally is necessary for the recurring bun terminal-agent and CLI-tool child windows, while windowsHide:true in cli.ts is the direct fix for the detached browse server itself. This affects any host using the same gstack browse runtime (Claude Code or Codex), rather than being host-specific.

  3. time-attack commented on Jul 15, 2026

    @time-attack
    Contributor

    @16francej Close this because the selected Windows browse-server console-window item already covers the same subprocess windowsHide problem.

  4. capy-ai commented on Oct 2, 2026

    @capy-ai
    Contributor

    Verified on main (v1.91.13.0): every child_process and Bun.spawn call in browse/src passes windowsHide, and the Node polyfill forwards it. browse/test/windows-spawn-hide.test.ts (a sweep over all spawn sites) and the polyfill tests pass natively on the windows-free-tests lane (run 37033755836). Fixed across v1.64–v1.67 (#2571, #2604). Thanks! If a console window still flashes on your machine, reply with your gstack version and we'll reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions