You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: mouse escape sequences garbled after TUI exit #20458
This is a separate issue from in-session mouse garbling (#3199 / PR #19520). The in-session bug is about fragmented SGR sequences leaking through StdinParser timeouts during active use. This bug occurs after the TUI has exited.
Root Cause
This is an upstream bug in @opentui/core's cleanupBeforeDestroy() method. During renderer destruction, stdin.setRawMode(false) is called (re-enabling terminal ECHO) before mouse tracking is disabled. Any mouse events arriving during this window get echoed as raw escape sequence bytes.
The correct ordering already exists in @opentui/core's suspend() method, which calls disableMouse() before setRawMode(false).
Move the mouse in the shell immediately after exit
Garbled escape sequences appear
Workaround
A patchedDependencies patch for @opentui/core can fix this by adding disableMouse() + stdin drain before setRawMode(false) in cleanupBeforeDestroy(). A PR with this patch is forthcoming.
Environment
macOS / Linux
Affects @opentui/core@0.1.90 and @opentui/core@0.1.95
Note that #18901 in particular is closely related — it describes the same core problem (mouse tracking not disabled on exit) from a slightly different angle (force-kill vs. normal exit). The root cause analysis in this issue may be relevant there as well.
I am seeing this same exit-time issue on Linux after closing OpenCode.
The raw text sometimes appears right after exit near my shell prompt. Examples:
997;1n
997;1n51;79;31M
Sometimes I see many of these, around 30 lines.
This happens across terminals:
Ghostty
Kitty
Alacritty
Environment:
OpenCode 1.14.25
tmux 3.6a
Arch Linux / Omarchy
Hyprland on Wayland
OpenCode path and version:
/home/nikita/.cache/.bun/bin/opencode
1.14.25
This seems separate from a Ghostty launcher crash I debugged. The escape text happens in any terminal, so it looks like OpenCode or OpenTUI cleanup is leaving terminal mouse/query responses to be echoed after exit.
At startup — before the TUI even renders, a stray sequence appears at the top:
^[[<35;83;40M
After exit — the sequence leaks into the shell prompt:
user@host:~/projects$ 35;83;40M
The sequence 35;83;40M is an SGR mouse report (coordinates 83;40, button 35) that gets echoed after the terminal has already left raw mode. This matches the root cause described in the issue — setRawMode(false) re-enabling ECHO before mouse tracking is fully disabled.
The OPENCODE_DISABLE_MOUSE=true workaround prevents the issue, but obviously disables mouse support entirely.
Happy to provide any additional debugging info if needed.
The terminal becomes unusable for typing until the VS Code terminal panel is closed and reopened. my ai said to add this when i asked about it: "reset, stty sane, and printf '\e[?1006l' all do not clear the buffered escape sequences."
Workaround: OPENCODE_DISABLE_MOUSE=1 works but kills mouse support inside the TUI - and using the mouse inside the tui is one of my favorite things.
This is a blocker for anyone using opencode inside VS Code + WSL.
Also reproduced on WSL2 + Windows Terminal (opencode 1.18.14): exit leaves garbled SGR mouse sequences like 35;58;30M… on the shell line.
I hit this issue too. on linux TUI terminal. this looks like a memory leak, the opencode process memory in top command grows much and TUI does not respond, and then the process crashes, the mouse escape sequences..
Decoded: three consecutive mouse events at row 32, columns 116→117→118 — i.e. a horizontal mouse movement captured mid-exit.
Extra data point: deliberately wiggling the mouse during the exit produces proportionally more fragments. The garbage scales with real-time mouse activity in the teardown window, which is consistent with the root cause described above: stdin.setRawMode(false) re-enables terminal ECHO before mouse tracking is disabled in cleanupBeforeDestroy(), so live mouse events arriving in that window get echoed back as plain text. After the exit completes, moving the mouse produces no further fragments (tracking does get disabled eventually, just too late).
No such issue on the Windows Desktop (GUI) build, where the terminal is not involved.
The x value reaches ~244, which matches the terminal width in columns - confirming these are echoed mouse events. The line is redrawn on every mouse movement, so the window also flickers until reset is run.
Workaround for Git Bash users (re-send the disable sequences after opencode exits):
Related but distinct trigger documented in #51600: on macOS/Bash, OpenCode v1 can become job-control stopped automatically after startup (confirmed SIGTTOU 22 in default mode and SIGTTIN 21 in attach mode). Because the stop bypasses teardown, mouse reporting remains enabled and produces the same 35;...M stream described here. --pure does not prevent it; temporarily running the TUI with Bash monitor mode disabled does. OpenCode v2.0.18 did not reproduce in the same PTY test.
Closing as a duplicate of #11748, which tracks mouse escape sequences showing up as garbled text in the terminal after OpenCode exits. Please add your platform and terminal details there.
Activity
github-actions commentedon Apr 1, 2026
This issue might be a duplicate of existing issues. Please check:
Note that #18901 in particular is closely related — it describes the same core problem (mouse tracking not disabled on exit) from a slightly different angle (force-kill vs. normal exit). The root cause analysis in this issue may be relevant there as well.
fix(tui): patch @opentui/core to prevent mouse garbling on exit and f…
fix(tui): patch @opentui/core to prevent mouse garbling on exit and f…
fix(tui): patch @opentui/core to prevent mouse garbling on exit and f…
nikitalbnv commentedon Apr 25, 2026
I am seeing this same exit-time issue on Linux after closing OpenCode.
The raw text sometimes appears right after exit near my shell prompt. Examples:
Sometimes I see many of these, around 30 lines.
This happens across terminals:
Environment:
OpenCode path and version:
This seems separate from a Ghostty launcher crash I debugged. The escape text happens in any terminal, so it looks like OpenCode or OpenTUI cleanup is leaving terminal mouse/query responses to be echoed after exit.
hertznsk commentedon Jun 7, 2026
+1, experiencing the same issue on Linux.
Environment:
Symptoms:
At startup — before the TUI even renders, a stray sequence appears at the top:
After exit — the sequence leaks into the shell prompt:
The sequence
35;83;40Mis an SGR mouse report (coordinates 83;40, button 35) that gets echoed after the terminal has already left raw mode. This matches the root cause described in the issue —setRawMode(false)re-enabling ECHO before mouse tracking is fully disabled.The
OPENCODE_DISABLE_MOUSE=trueworkaround prevents the issue, but obviously disables mouse support entirely.Happy to provide any additional debugging info if needed.
samuel-pro-ai commentedon Jun 12, 2026
Can confirm this is still happening on v1.17.3 (latest) with WSL Ubuntu + VS Code integrated terminal.
Reproduction:
The terminal becomes unusable for typing until the VS Code terminal panel is closed and reopened. my ai said to add this when i asked about it: "reset, stty sane, and printf '\e[?1006l' all do not clear the buffered escape sequences."
Workaround: OPENCODE_DISABLE_MOUSE=1 works but kills mouse support inside the TUI - and using the mouse inside the tui is one of my favorite things.
This is a blocker for anyone using opencode inside VS Code + WSL.
sheng-888 commentedon Aug 6, 2026
Also reproduced on WSL2 + Windows Terminal (opencode 1.18.14): exit leaves
garbled SGR mouse sequences like 35;58;30M… on the shell line.
tianq01 commentedon Aug 13, 2026
I hit this issue too. on linux TUI terminal. this looks like a memory leak, the opencode process memory in top command grows much and TUI does not respond, and then the process crashes, the mouse escape sequences..
WhiteGiverMa commentedon Aug 16, 2026
Confirming on WSL2 (Ubuntu 24.04) + Windows Terminal, OpenCode 1.18.18, bash.
Exiting via Ctrl+C / Ctrl+D leaves the same kind of SGR mouse fragments at the shell prompt:
Decoded: three consecutive mouse events at row 32, columns 116→117→118 — i.e. a horizontal mouse movement captured mid-exit.
Extra data point: deliberately wiggling the mouse during the exit produces proportionally more fragments. The garbage scales with real-time mouse activity in the teardown window, which is consistent with the root cause described above:
stdin.setRawMode(false)re-enables terminal ECHO before mouse tracking is disabled incleanupBeforeDestroy(), so live mouse events arriving in that window get echoed back as plain text. After the exit completes, moving the mouse produces no further fragments (tracking does get disabled eventually, just too late).No such issue on the Windows Desktop (GUI) build, where the terminal is not involved.
Hoping anomalyco/opentui#905 can land soon.
chriscarrollsmith commentedon Aug 20, 2026
I encountered this in MinGW/Git Bash (not WSL), so this is not exclusively a Linux issue.
lyhnbomb commentedon Sep 22, 2026
Also confirming this on a different platform: Windows + MinTTY (Git Bash), opencode 1.18.32.
Repro is the same: exit the TUI, then move the mouse at the shell prompt. The prompt line is flooded with the tail of SGR mouse sequences, e.g.:
35;125;49M35;123;49M35;122;49M35;122;48M35;121;48M...The x value reaches ~244, which matches the terminal width in columns - confirming these are echoed mouse events. The line is redrawn on every mouse movement, so the window also flickers until
resetis run.Workaround for Git Bash users (re-send the disable sequences after opencode exits):
djbclark commentedon Sep 27, 2026
Related but distinct trigger documented in #51600: on macOS/Bash, OpenCode v1 can become job-control stopped automatically after startup (confirmed SIGTTOU 22 in default mode and SIGTTIN 21 in attach mode). Because the stop bypasses teardown, mouse reporting remains enabled and produces the same
35;...Mstream described here.--puredoes not prevent it; temporarily running the TUI with Bash monitor mode disabled does. OpenCode v2.0.18 did not reproduce in the same PTY test.neriousy commentedon Oct 1, 2026
Closing as a duplicate of #11748, which tracks mouse escape sequences showing up as garbled text in the terminal after OpenCode exits. Please add your platform and terminal details there.