Description
On Windows, pressing Ctrl+C to exit the application causes raw ANSI escape sequences (color codes) to be printed to the terminal after the process terminates. Exiting via the exit command works cleanly without this issue.
Root Cause
The @opentui/core renderer registers SIGINT (and other signal) handlers by default via addExitListeners(). On Windows, the app disables ENABLE_PROCESSED_INPUT so that Ctrl+C is delivered as a keyboard event instead of a signal. However, a race condition exists in the 100ms polling guard — Bun's runtime can momentarily re-enable the flag between polls. When Ctrl+C is pressed during this window, it generates SIGINT instead of a keyboard event, and opentui's handler calls renderer.destroy() directly, bypassing the app's graceful exit flow (process.exit, unguard, worker shutdown).
Steps to reproduce
- Run
opencode on Windows (PowerShell or Windows Terminal)
- Press
Ctrl+C to exit
- Observe raw ANSI escape codes printed in the terminal after exit
Expected behavior
The application should exit cleanly without printing any ANSI escape codes, the same as when using the exit command.
OpenCode version
v1.1.60
Operating System
Windows 11
Terminal
Windows Terminal / PowerShell
Description
On Windows, pressing Ctrl+C to exit the application causes raw ANSI escape sequences (color codes) to be printed to the terminal after the process terminates. Exiting via the
exitcommand works cleanly without this issue.Root Cause
The
@opentui/corerenderer registersSIGINT(and other signal) handlers by default viaaddExitListeners(). On Windows, the app disablesENABLE_PROCESSED_INPUTso that Ctrl+C is delivered as a keyboard event instead of a signal. However, a race condition exists in the 100ms polling guard — Bun's runtime can momentarily re-enable the flag between polls. When Ctrl+C is pressed during this window, it generatesSIGINTinstead of a keyboard event, and opentui's handler callsrenderer.destroy()directly, bypassing the app's graceful exit flow (process.exit,unguard, worker shutdown).Steps to reproduce
opencodeon Windows (PowerShell or Windows Terminal)Ctrl+Cto exitExpected behavior
The application should exit cleanly without printing any ANSI escape codes, the same as when using the
exitcommand.OpenCode version
v1.1.60
Operating System
Windows 11
Terminal
Windows Terminal / PowerShell