Description
On Windows (Windows Terminal + cmd.exe), exiting the TUI via Ctrl+D, /exit, or /quit causes the terminal window to close instead of returning to the shell prompt.
Steps to reproduce
- Open Windows Terminal with cmd.exe
- Run
opencode (or bun run dev from source)
- Press Ctrl+D to exit the TUI
- Expected: Terminal stays open, shell prompt appears, user can type
- Actual: Terminal window closes after a few seconds
Root cause
The worker's graceful shutdown process kills MCP server subprocesses (e.g. appliance-sql-guard, logic_guard). On Windows, these subprocess exits detach the main process from its console (GetConsoleWindow() transitions from a valid handle to 0x0). This causes cmd.exe to lose its console and exit, which closes the Windows Terminal tab.
Both worker.terminate() and await client.call("shutdown") trigger this — the former crashes the console immediately, the latter destroys it during MCP subprocess cleanup.
Diagnosed using kernel32 FFI monitoring (SetConsoleCtrlHandler + GetConsoleWindow polling). No CTRL_CLOSE_EVENT is fired — the console is silently detached.
Environment
- Windows 11 Pro
- Windows Terminal + cmd.exe
- Bun 1.3.12
- opencode 1.4.3
Description
On Windows (Windows Terminal + cmd.exe), exiting the TUI via Ctrl+D,
/exit, or/quitcauses the terminal window to close instead of returning to the shell prompt.Steps to reproduce
opencode(orbun run devfrom source)Root cause
The worker's graceful shutdown process kills MCP server subprocesses (e.g.
appliance-sql-guard,logic_guard). On Windows, these subprocess exits detach the main process from its console (GetConsoleWindow()transitions from a valid handle to0x0). This causescmd.exeto lose its console and exit, which closes the Windows Terminal tab.Both
worker.terminate()andawait client.call("shutdown")trigger this — the former crashes the console immediately, the latter destroys it during MCP subprocess cleanup.Diagnosed using kernel32 FFI monitoring (
SetConsoleCtrlHandler+GetConsoleWindowpolling). NoCTRL_CLOSE_EVENTis fired — the console is silently detached.Environment