[Windows] Raw ANSI escape codes printed after Ctrl+C exit #9159

Open
opened 2026-02-16 18:11:47 -05:00 by yindo · 1 comment
Owner

Originally created by @j-token on GitHub (Feb 12, 2026).

Originally assigned to: @kommander on GitHub.

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

  1. Run opencode on Windows (PowerShell or Windows Terminal)
  2. Press Ctrl+C to exit
  3. 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

Originally created by @j-token on GitHub (Feb 12, 2026). Originally assigned to: @kommander on GitHub. ### 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 1. Run `opencode` on Windows (PowerShell or Windows Terminal) 2. Press `Ctrl+C` to exit 3. 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
yindo added the windowsopentui labels 2026-02-16 18:11:47 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 12, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #10945: [Windows] Raw ANSI escape codes flooding console & "Unable to connect" errors during tool execution (v1.1.36)
  • #7062: Pressing Ctrl+C in input field outputs ANSI escape sequences/garbled text
  • #12664: Terminal output becomes garbled after running for a while and also when pressing Ctrl+C
  • #6912: Ctrl+C does not disable mouse tracking, causing raw escape sequences to flood terminal (Windows)

These issues all describe similar symptoms of raw ANSI escape codes being printed to the terminal after Ctrl+C on Windows, which may be the same underlying bug with different manifestations.

@github-actions[bot] commented on GitHub (Feb 12, 2026): This issue might be a duplicate of existing issues. Please check: - #10945: [Windows] Raw ANSI escape codes flooding console & "Unable to connect" errors during tool execution (v1.1.36) - #7062: Pressing Ctrl+C in input field outputs ANSI escape sequences/garbled text - #12664: Terminal output becomes garbled after running for a while and also when pressing Ctrl+C - #6912: Ctrl+C does not disable mouse tracking, causing raw escape sequences to flood terminal (Windows) These issues all describe similar symptoms of raw ANSI escape codes being printed to the terminal after Ctrl+C on Windows, which may be the same underlying bug with different manifestations.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9159