Skip to content

TUI: incomplete terminal teardown on exit — mouse tracking, alt-screen, bracketed paste left enabled #32336

Closed as not planned

Description

@Ko-Valery

Description

When OpenCode TUI exits (via /exit), several terminal features that were enabled at startup are not disabled. This leaves the terminal in a broken state: mouse movements print garbage characters (numbers/escape codes), bracketed paste is stuck on, and the alternate screen buffer may not be properly restored.

The only fix is to manually run reset or close and reopen the terminal window.

Environment

  • OpenCode version: latest (installed via curl -fsSL https://opencode.ai/install | bash)
  • OS: Windows 11 + WSL2 (Ubuntu 24.04)
  • Terminal: Windows Terminal
  • Shell: bash 5.2

Plugins

@opencode-ai/plugin: "1.17.1" (in .opencode/package.json).

OpenCode version

1.17.6

Steps to reproduce

  1. Run OpenCode in any project: opencode .
  2. Send a message to the agent, wait for a response.
  3. Exit via /exit (not Ctrl+C — clean exit).
  4. Move the mouse in the terminal window — random digits and brackets appear as text input.
  5. To capture raw proof: script -q -c "opencode ." /tmp/oc_capture.log, exit, then xxd /tmp/oc_capture.log | tail -80.

Analysis of raw capture

Enabled at startup (confirmed in hex dump):

\033[?1049h   # alternate screen buffer ON
\033[?1000h   # basic mouse tracking ON
\033[?1002h   # button-event mouse tracking ON
\033[?1003h   # any-event mouse tracking ON
\033[?1006h   # SGR mouse mode ON
\033[?2004h   # bracketed paste ON
\033[?1004h   # focus reporting ON

Disabled on exit (confirmed in hex dump):

\033[?25h     # show cursor
\033[?9001l   # some internal feature off
\033[?1004l   # focus reporting OFF

Missing on exit — the following are never disabled:

\033[?1049l   # alternate screen buffer OFF — MISSING
\033[?1000l   # basic mouse tracking OFF — MISSING
\033[?1002l   # button-event mouse tracking OFF — MISSING
\033[?1003l   # any-event mouse tracking OFF — MISSING
\033[?1006l   # SGR mouse mode OFF — MISSING
\033[?2004l   # bracketed paste OFF — MISSING

Consequence

SGR mouse mode (\033[?1006h) encodes mouse events as \033[<button;column;rowm escape sequences. With tracking still enabled after exit, every mouse movement injects these sequences into the shell input — the numbers and brackets the user sees.

Expected behavior

All terminal features enabled at startup should be explicitly disabled on exit, restoring the terminal to its original state.

Workaround

Add this wrapper function to ~/.bashrc:

oc() {
    opencode "$@"
    stty sane
    printf '\033[?1049l\033[?1000l\033[?1002l\033[?1003l\033[?1006l\033[?2004l\033[?1004l'
    reset
}

Plugins

@opencode-ai/plugin: "1.17.1"

OpenCode version

1.17.6

Steps to reproduce

  1. Run OpenCode in any project: opencode .
  2. Send a message to the agent, wait for a response.
  3. Exit via /exit (not Ctrl+C — clean exit).
  4. Move the mouse in the terminal window — random digits and brackets appear as text input.
  5. To capture raw proof: script -q -c "opencode ." /tmp/oc_capture.log, exit, then xxd /tmp/oc_capture.log | tail -80.

Screenshot and/or share link

Image

Operating System

Windows 11 + WSL2 (Ubuntu 24.04)

Terminal

Windows Terminal

Activity

  1. github-actions commented on Jun 14, 2026

    @github-actions
    Contributor

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

  2. Ko-Valery commented on Jun 14, 2026

    @Ko-Valery
    Author

    Confirmed on OpenCode 1.17.6, WSL2 Ubuntu 24.04, Windows Terminal.
    Captured via script -q -c "opencode ." /tmp/oc.log and analyzed hex dump.

    Features ENABLED at startup but NOT disabled on exit via /exit:

    Feature Enable seq Disable seq on exit
    Alt screen buffer \033[?1049h MISSING
    Mouse basic \033[?1000h MISSING
    Mouse button \033[?1002h MISSING
    Mouse any \033[?1003h MISSING
    SGR mouse \033[?1006h MISSING
    Bracketed paste \033[?2004h MISSING
    Focus reporting \033[?1004h OK (\033[?1004l)

    Workaround

    Add this wrapper function to ~/.bashrc:

    oc() {
        opencode "$@"
        stty sane
        printf '\033[?1049l\033[?1000l\033[?1002l\033[?1003l\033[?1006l\033[?2004l\033[?1004l'
        reset
    }
  3. Ko-Valery commented on Jun 14, 2026

    @Ko-Valery
    Author

    Confirmed on OpenCode 1.17.6, WSL2 Ubuntu 24.04, Windows Terminal.
    Captured via script -q -c "opencode ." /tmp/oc.log and analyzed hex dump.

    Features ENABLED at startup but NOT disabled on exit via /exit:

    Feature Enable seq Disable seq on exit
    Alt screen buffer \033[?1049h MISSING
    Mouse basic \033[?1000h MISSING
    Mouse button \033[?1002h MISSING
    Mouse any \033[?1003h MISSING
    SGR mouse \033[?1006h MISSING
    Bracketed paste \033[?2004h MISSING
    Focus reporting \033[?1004h OK (\033[?1004l)

    Workaround

    Add this wrapper function to ~/.bashrc:

    oc() {
        opencode "$@"
        stty sane
        printf '\033[?1049l\033[?1000l\033[?1002l\033[?1003l\033[?1006l\033[?2004l\033[?1004l'
        reset
    }
  4. github-actions commented on Aug 14, 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