Skip to content

bug: TUI exit closes terminal window on Windows #22003

Closed as not planned
Closed as not planned

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

Activity

  1. suqiernb commented on May 21, 2026

    @suqiernb
    • I encountered the same problem, using WezTerm & NuShell
      video
  2. ec36339 commented on Jul 3, 2026

    @ec36339

    Similar behavior with 1.17.13 and Bash in Windows Terminal.

  3. github-actions commented on Sep 2, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

  4. Elvin-zhujunde commented on Sep 14, 2026

    @Elvin-zhujunde

    If you are PowerShell, before starting, try setting $env:OTUI_USE_ALTERNATE_SCREEN=0 and then restart. The same applies to other terminals.

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

Metadata

Metadata

Assignees

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