Skip to content

bug: TUI exit closes terminal window on Windows #22003

@bamboodew

Description

@bamboodew

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

  1. Open Windows Terminal with cmd.exe
  2. Run opencode (or bun run dev from source)
  3. Press Ctrl+D to exit the TUI
  4. Expected: Terminal stays open, shell prompt appears, user can type
  5. 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

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions