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
Stale stdin bytes leak to shell after exit on POSIX (space on prompt, blocks ctrl+d) #17081
After exiting opencode on Linux/macOS, stale bytes sometimes remain in the kernel's tty input buffer and are read by the parent shell. The most common symptom is a space character appearing on the shell prompt line, which blocks ctrl+d (EOF) from terminating the shell since readline requires an empty line.
During @opentui/core's finalizeDestroy(), the stdin data listener is removed and raw mode is disabled, but the kernel's tty input buffer is not flushed. Any bytes that arrived between the last stdin read and the mode switch (e.g. key release events from the Kitty keyboard protocol, or other in-flight terminal data) persist in the cooked-mode line discipline buffer. When the process exits, the shell inherits these bytes.
On Windows this was already handled — win32FlushInputBuffer() calls FlushConsoleInputBuffer via kernel32 FFI after renderer.destroy(). There was no POSIX equivalent.
Notably, @opentui/core's own resume() method drains stdin (while (this.stdin.read() !== null) {}), but finalizeDestroy() does not — nor does it call stdin.pause() like suspend() does.
Fix
Add a cross-platform flushInputBuffer() that calls tcflush(STDIN_FILENO, TCIFLUSH) on POSIX via libc FFI (libc.so.6 on Linux, libSystem.B.dylib on macOS), alongside the existing Windows FlushConsoleInputBuffer path. Call it after renderer.destroy() in both exit paths (exit.tsx and the ErrorComponent in app.tsx).
Also rename win32.ts → console.ts since it now contains cross-platform code, and drop the win32 prefix from flushInputBuffer (the two Windows-only functions retain their prefix).
Another POSIX data point: opencode 1.17.9, Ubuntu 24.04.4 (kernel 6.17.0-1025-oem), Alacritty (Wayland), zsh, no tmux/SSH. On exit via Ctrl+C or Ctrl+D the TTY stays in raw mode (no echo, can't type) until a 2nd Ctrl+C or stty sane. Workaround: zsh precmd hook running stty sane. Filed #34397 before finding this — closing that as duplicate.
Activity
Dreeoo commentedon Jun 29, 2026
Another POSIX data point: opencode 1.17.9, Ubuntu 24.04.4 (kernel 6.17.0-1025-oem), Alacritty (Wayland), zsh, no tmux/SSH. On exit via Ctrl+C or Ctrl+D the TTY stays in raw mode (no echo, can't type) until a 2nd Ctrl+C or
stty sane. Workaround: zsh precmd hook runningstty sane. Filed #34397 before finding this — closing that as duplicate.