Adding an independent data point: the underlying mouse-tracking leak reproduces outside WSL2, on a completely different platform, and is still present in current opencode — with byte-level evidence of exactly what gets left behind, plus workarounds that operate on the right layer.
Environment
- opencode
1.18.34 (npm global; the TUI is opentui-based — the session opens with the \e]99;i=opentui-notifications announce)
- Host: Windows 11 (10.0.26200), OpenSSH for Windows,
DefaultShell = Git Bash (MINGW64, bash 5.3.15)
- Client: Windows Terminal, plain
ssh -tt <host> opencode
What the byte stream shows (captured with a small pty harness around ssh -tt, timestamps aligned)
Startup:
\e[?1000h \e[?1002h \e[?1003h \e[?1006h
Exit via Ctrl+C — the entire teardown:
\e]22;\a \e[>4;0m \e[?2004l \e[?1049l \e[?2031l \e]0;\a \e[0 q \e[?25l \e[H \e[K ...
It restores bracketed paste (2004), the alternate screen (1049), mode 2031, cursor style and visibility — but the full capture contains zero occurrences of \e[?1000l, \e[?1002l, \e[?1003l or \e[?1006l. The terminal is left in all-motion mouse reporting (1003 + SGR 1006) after the TUI is gone.
Fallout — back at the shell prompt, every pointer movement over the window makes the terminal send \e[<35;<col>;<row>M (motion, no button) into the shell, which prints it literally:
$ 35;48;15M35;46;16M35;45;17M35;44;18M35;44;19M…
I reproduced that exact garbage by writing a single SGR report (\e[<35;48;15M) to the bash prompt on the host — it echoes 35;48;15M. I suspect this is also the shape behind the "mouse input spam" here and in #5046: with the TUI gone, the reports keep coming — from the terminal, not from opencode. (Whether WSL2 additionally turns the leftover reporting into a SIGPWR storm is a separate question, but the leaked mouse state is real on its own, platform-independent, and trivial to trigger.)
Reproduce
ssh -tt <host> opencode — any host, any terminal
- Exit with Ctrl+C
- Move the mouse over the terminal → motion reports accumulate at the prompt
Workarounds that work — the ones tried in the OP (trap "" PWR, setsid, TERM changes) act on the wrong layer: the leftover state lives in the terminal, so the fix is to emit the mouse-off reset, not to trap signals.
One-off, at the affected prompt:
printf '\033[?1000l\033[?1002l\033[?1003l\033[?1005l\033[?1006l\033[?1015l\033[?1016l'
Permanent, in the host's ~/.bashrc (resets at every prompt; TUIs re-enable the modes when they start; the guard keeps it from stacking):
__tty_reset_mouse() {
printf '\033[?1000l\033[?1002l\033[?1003l\033[?1005l\033[?1006l\033[?1015l\033[?1016l'
}
case ";${PROMPT_COMMAND:-};" in
*";__tty_reset_mouse;"*) ;;
*) PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }__tty_reset_mouse" ;;
esac
Or wrap the launch command and restore right after exit:
oc() {
opencode --auto "$@"
local rc=$?
[[ -t 1 ]] && printf '\033[?1000l\033[?1002l\033[?1003l\033[?1005l\033[?1006l\033[?1015l\033[?1016l'
return $rc
}
The real fix is presumably a small addition to the opentui teardown: emit the mouse-mode disables next to the existing ?2004l / ?1049l restores. Happy to share the raw captures if useful.