Repository navigation
Description
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
- Run OpenCode in any project:
opencode . - Send a message to the agent, wait for a response.
- Exit via
/exit(not Ctrl+C — clean exit). - Move the mouse in the terminal window — random digits and brackets appear as text input.
- To capture raw proof:
script -q -c "opencode ." /tmp/oc_capture.log, exit, thenxxd /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
- Run OpenCode in any project:
opencode . - Send a message to the agent, wait for a response.
- Exit via
/exit(not Ctrl+C — clean exit). - Move the mouse in the terminal window — random digits and brackets appear as text input.
- To capture raw proof:
script -q -c "opencode ." /tmp/oc_capture.log, exit, thenxxd /tmp/oc_capture.log | tail -80.
Screenshot and/or share link
Operating System
Windows 11 + WSL2 (Ubuntu 24.04)
Terminal
Windows Terminal
Activity
github-actions commentedon Jun 14, 2026
This issue might be a duplicate of existing issues. Please check:
cleanupBeforeDestroy(); includes root cause analysis and upstream fix referenceKo-Valery commentedon Jun 14, 2026
Confirmed on OpenCode 1.17.6, WSL2 Ubuntu 24.04, Windows Terminal.
Captured via
script -q -c "opencode ." /tmp/oc.logand analyzed hex dump.Features ENABLED at startup but NOT disabled on exit via /exit:
Workaround
Add this wrapper function to
~/.bashrc:Ko-Valery commentedon Jun 14, 2026
Confirmed on OpenCode 1.17.6, WSL2 Ubuntu 24.04, Windows Terminal.
Captured via
script -q -c "opencode ." /tmp/oc.logand analyzed hex dump.Features ENABLED at startup but NOT disabled on exit via /exit:
Workaround
Add this wrapper function to
~/.bashrc:fix(zsh): clean up terminal after opencode TUI exit
github-actions commentedon Aug 14, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.