Skip to content

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

@AungMyoKyaw

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

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

Metadata

Metadata

Assignees

Labels

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions