Skip to content

TUI unresponsive to keyboard input inside tmux: setRawMode fails with EBADF (errno 9) #24358

Closed

Description

@AungMyoKyaw

Bug Description

When running opencode inside a tmux session, the TUI renders correctly but is completely unresponsive to all keyboard input. No keys register — typing, arrow keys, Enter, Escape, Ctrl+C, keyboard shortcuts all silently ignored. The UI appears frozen. Works perfectly outside tmux.

Environment

  • OS: macOS (Apple Silicon, arm64)
  • Terminal: Ghostty
  • tmux: next-3.7
  • opencode version: 0.0.0-dev-202604251526 (April 25, 2026 dev build)
  • Installation: via Bun (bunx opencode-ai@latest)
  • Shell: zsh

Root Cause Found

The debug log (--print-logs --log-level DEBUG) reveals the failure:

ERROR service=server-proxy e=setRawMode failed with errno: 9 exception
ERROR service=server-proxy error=setRawMode failed with errno: 9 process error

errno 9 = EBADF (Bad file descriptor). The setRawMode() call tries to operate on a file descriptor that is not a valid terminal.

Why This Happens (TTY Discrepancy)

Inside tmux, the process environment differs from outside:

  • stdin (fd 0): IS a TTY — [ -t 0 ] returns true
  • stdout (fd 1): NOT a TTY — [ -t 1 ] returns false
  • tty command returns /dev/ttys006 (valid PTY)

Outside tmux, both stdin and stdout are TTYs.

Conclusion: setRawMode() is called on the stdout file descriptor (fd 1), which is not a TTY inside tmux, causing the EBADF failure. The correct file descriptor for raw mode is stdin (fd 0), since raw mode controls input buffering.

Reproduction Steps

  1. Start a tmux session: tmux
  2. Run opencode: opencode
  3. OpenCode TUI renders (UI elements visible)
  4. Try to type anything — no input is registered
  5. Run with debug logging: OPENCODE_LOG_LEVEL=DEBUG opencode --print-logs --log-level DEBUG 2>/tmp/op-debug.log
  6. Check the log for: setRawMode failed with errno: 9

What Was Tested (Bisect)

  • Tmux config is NOT the cause: Tested 7 progressive tmux configs (minimal → full), all produce same error
  • Confirmed: A minimal Bubble Tea v1.3.10 program (tea.WithAltScreen()) works correctly inside all tmux configs — keyboard input is received normally
  • Confirmed: stty shows terminal is in canonical mode (icanon) inside tmux, confirming raw mode was never set
  • Confirmed: Running outside tmux shows no setRawMode error

Workaround

None found. Setting extended-keys always, removing allow-passthrough, or using a minimal tmux configuration does not resolve the issue.

Possible Fix Direction

  • setRawMode() should use the stdin file descriptor (fd 0) instead of stdout (fd 1), since raw mode is about disabling input line buffering
  • Or opencode's TUI initialization should detect when stdout is not a TTY and fall back to stdin for raw mode control
  • Compare with Bubble Tea v1.3.10's NewProgram which works correctly inside tmux

Related Issues

  • #16351 — "TUI broken in tmux after 1.2.17" (identical symptoms, regression reverted)
  • OC-9232 — "setRawMode failed with errno: 5 (EIO)" when terminal disconnects
  • OC-8787 — Missing SIGHUP handler causes orphaned processes
  • OC-9972 — Terminal escape sequences printed on startup in tmux
  • #10610 — TUI leaves terminal in raw mode after exit

Logs

Complete error log:

INFO  2026-04-25T18:07:49 +252ms service=server-proxy version=0.0.0-dev-202604251526 args=["--print-logs"] process_role=main run_id=641a2824-b437-4873-9634-5bf28b0e7e70 opencode
ERROR 2026-04-25T18:07:50 +1124ms service=server-proxy e=setRawMode failed with errno: 9 exception
ERROR 2026-04-25T18:07:50 +1ms service=server-proxy error=setRawMode failed with errno: 9 process error

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Apr 25, 2026
  2. github-actions commented on Apr 25, 2026

    @github-actions
    Contributor

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

    If your problem persists on the current version and differs from the above (e.g. different root cause or environment), please clarify so maintainers can distinguish this from prior reports.

  3. lonelygo commented on Apr 26, 2026

    @lonelygo

    I also encountered the same problem. When starting opencode in tmux, only the TUI is visible, but any keyboard input does not respond, and the process can only be killed with kill -9. However, it works normally in the terminal.
    tmux 3.6a
    opencode 1.14.25
    os macos 26.4.1
    cmux 0.63.2

  4. polo871209 commented on Apr 26, 2026

    @polo871209

    I can confirm the same and 1.14.24 work for me I just downgrade

  5. mesterM12 commented on Apr 26, 2026

    @mesterM12

    I have had the same issue. using ghostty and tmux as well as using the default terminal app both fully hang when opened to the point where the entire app is unresponsive. I have downgraded to version 1.14.24 and everything seems to be working fine in that version. tmux 3.6a , opencode 1.14.25 ( the one with the issue ) , os macos 26.4.1 .

  6. kommander commented on Apr 26, 2026

    @kommander
    Contributor

    Did 1.14.26 improve?

  7. mesterM12 commented on Apr 26, 2026

    @mesterM12

    Yes the issue is resolved for me! thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

opentuiThis relates to changes in v1.0, now that opencode uses opentui

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions