Skip to content

fix(windows): stop console windows flashing on every host spawn#115

Merged
juacker merged 1 commit into
mainfrom
fix/windows-console-flash
Jul 22, 2026
Merged

fix(windows): stop console windows flashing on every host spawn#115
juacker merged 1 commit into
mainfrom
fix/windows-console-flash

Conversation

@juacker

@juacker juacker commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Problem

On Windows, every host process CLAI spawns briefly flashes a console window: the startup which/where provider probes (two flashes per cold boot), editor/terminal detection, opening a file with the system default app (explorer.exe), opening an editor (.cmd shims like code.cmd), the where PATHEXT resolution, provider CLI sessions, stdio MCP servers, git for skill sources, taskkill tree-kills, and bash_exec children.

Root cause: CLAI's desktop binary is a GUI-subsystem app with no console of its own, so CreateProcessW allocates a brand-new visible console for every console-subsystem child unless the spawn passes CREATE_NO_WINDOW.

Fix

  • New src-tauri/src/windows_console.rs: HideConsoleWindow trait with hide_console_window() for std::process::Command and tokio::process::Command — applies creation_flags(CREATE_NO_WINDOW) on Windows, no-op elsewhere, so call sites stay platform-unconditional.
  • Applied at every background spawn site: providers::get_host_command (all which/where/version/xdg-mime probes), providers::build_host_cli_command_impl (provider CLI sessions), system_apps::resolve_windows_program's where probe, spawn_host_detached hidden paths (editors, explorer.exe/open/xdg-open), stdio MCP server spawns, git for skill sources, taskkill, and the unsupported-sandbox runner (bash_exec on Windows).
  • spawn_host_detached now takes an explicit HostWindow::{Hidden,Visible}: terminal launches stay Visible (for cmd/powershell the console window is the launched terminal; wt draws its own window either way), and custom editor commands stay Visible (a console custom editor like vim would otherwise run invisibly holding the file).
  • windows-sys gains the Win32_System_Threading feature for the CREATE_NO_WINDOW constant.

Verification

  • cargo test --lib: 802/802 passed (incl. 2 new smoke tests covering both command types); clippy and rustfmt clean.
  • Independent static review (2 rounds): round 1 production_quality with 3 minor findings, all fixed; round 2 production_quality, zero findings.
  • ⚠️ #[cfg(windows)] paths are eye-verified only (dev host is Linux) — please confirm the Windows CI build, and ideally one manual smoke on Windows: cold boot (no flashes), open file/editor (no flash), open terminal (window still appears).

CLAI's desktop binary is a GUI-subsystem app, so every console-subsystem
child it spawns makes CreateProcessW allocate a new visible console: the
startup which/where probes, editor/terminal detection, .cmd editor shims,
explorer.exe file-open, provider CLI sessions, stdio MCP servers, git for
skill sources, taskkill tree-kills and bash_exec children all flashed a
console window on Windows.

Add a HideConsoleWindow trait (CREATE_NO_WINDOW on Windows, no-op
elsewhere) for std and tokio Commands and apply it at every spawn site
except terminal launches, where the visible console IS the product
(cmd/PowerShell fallbacks); spawn_host_detached now takes an explicit
HostWindow::{Hidden,Visible} so that decision is typed at the call site.
@juacker
juacker marked this pull request as ready for review July 22, 2026 22:11
@juacker
juacker merged commit 3003aaf into main Jul 22, 2026
2 checks passed
@juacker
juacker deleted the fix/windows-console-flash branch July 22, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant