Skip to content

[Windows] Terminal left with raw ANSI escape codes after crash (PowerShell) #21277

Closed as not planned

Description

@jeankrlo2929

Bug description

When OpenCode crashes or exits unexpectedly on Windows (PowerShell), the terminal is left in a broken state showing raw ANSI escape sequences as literal text at the bottom of the screen, e.g.:

555;59;86m

The terminal cursor may also be hidden, requiring the user to close and reopen PowerShell to recover.

Environment

  • OS: Windows 10
  • Terminal: PowerShell 5.1
  • OpenCode version: 1.3.17
  • Install method: npm (npm install -g opencode-ai)

Expected behavior

On crash or unexpected exit, OpenCode should reset the terminal state (\x1b[0m, \x1b[?25h) before exiting, similar to how other TUI apps (e.g., vim, btop) handle SIGINT/panic cleanup.

Workaround

Wrapping the npm launcher (opencode.ps1) in a PowerShell try/finally block that runs [Console]::ResetColor() and Write-Host -NoNewline "$([char]27)[0m$([char]27)[?25h" mitigates the visible symptom but does not fix the root cause.

Suggested fix

In the crash/exit handler of the binary, add terminal reset before process exit:

  • Send \x1b[0m (reset all attributes)
  • Send \x1b[?25h (show cursor)
  • Call the platform terminal restore function if using a TUI library

Activity

  1. github-actions commented on Apr 7, 2026

    @github-actions
    Contributor

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

    If these existing issues cover your problem, please consider referencing them rather than opening a new one. If your issue is distinct (e.g., a regression or different scenario), please clarify the difference.

  2. added a commit that references this issue on Apr 7, 2026
    f203b17
  3. joket1999 commented on Apr 8, 2026

    @joket1999

    The same with me. After upgrading to 1.4.0, the probability of crashing increased. It's practically unusable now. (I've posted this several times.)

    OS: Ubuntu Server 24.04 LTS
    OpenCode version: 1.4.0
    Install method: npm (npm install -g opencode-ai@latest)

  4. adminxxt commented on Jun 18, 2026

    @adminxxt

    Has it been resolved? How to solve @joket1999
    

  5. joket1999 commented on Jul 23, 2026

    @joket1999

    Has it been resolved? How to solve @joket1999

    This problem hasn't occurred now, but I guess it's caused by insufficient memory. Because there are often many temporary files in the /tmp directory in my virtual machine, which takes up a lot of memory. Later, I paid more attention to the usage in the /tmp directory and cleared the cache, so it didn't appear again. @adminxxt

  6. github-actions commented on Sep 23, 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.

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