Skip to content

TUI broken in tmux after 1.2.17 (found root cause) #16351

Closed

Description

@asaf92

EDIT: solved in 1.2.25

Bug

Starting with v1.2.17, the TUI intermittently breaks when running inside tmux. The text input area renders as a grey box (maybe it's my terminal background color, default Ubuntu terminal), typing and keyboard shortcuts don't work, and mouse movements inject raw SGR escape sequences as text (e.g. ^[[<35;164;12M). The issue does not occur outside tmux, although there are some rendering bugs when switching tabs in the terminal

Image

Root cause

The regression was introduced by commit 3ebebe0 ("fix(process): prevent orphaned opencode subprocesses on shutdown")

Reverting thread.ts and worker.ts from 1.2.17 version to their 1.2.16 version seems to solve the issue. I also tested with a modified 1.2.20 version and it also fixed it.

Environment

Environment

  • OS: Ubuntu 22.04 Linux x64
  • Terminal: GNOME Terminal (default Ubuntu terminal)
  • tmux: 3.2a
  • tmux config: set -g default-terminal "tmux-256color", set -ga terminal-overrides ",256col:Tc", no set mouse on, no extended-keys

Plugins

None

OpenCode version

1.2.17 and 1.2.20

Steps to reproduce

  1. Open a tmux session (tested with tmux 3.2a)
  2. Run opencode (v1.2.17 or later)
  3. The textarea loses its styling/borders and appears as a plain region against the terminal background
  4. Typing text and pressing Enter does not send the prompt
  5. Ctrl+P does not open the action palette
  6. Moving the mouse injects raw escape sequences into the input area
  7. Text extends beyond the original text area boundaries and wraps

The bug is intermittent — it doesn't always reproduce on first launch, but reproduces consistently across multiple attempts. It has never been observed with v1.2.16.

Screenshot and/or share link

No response

Operating System

Ubuntu 22.04

Terminal

Default Ubuntu terminal

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Mar 6, 2026
  2. hrez commented on Mar 7, 2026

    @hrez

    The bug is intermittent — it doesn't always reproduce on first launch, but reproduces consistently across multiple attempts. It has never been observed with v1.2.16

    It's 100% reproducible for me. No newer opencode version works under tmux including 1.2.21. I have to revert to 1.2.16 for opencode to be usable.
    environment: tmux 3.2a, 22.04.1-Ubuntu

  3. tobwen commented on Mar 8, 2026

    @tobwen
    Contributor

    Damnit, we worked on the exactly same problem and nearly have equal screenshots. I just provided a PR. Let's hope it will get merged: #16565

  4. hrez commented on Mar 8, 2026

    @hrez

    Unfortunately 1.2.22 does not fix this. So, #16565 isn't the whole story.

  5. Almazick commented on Mar 9, 2026

    @Almazick

    Same problem here. I just updated to 1.2.22, and OpenCode in the CLI is completely unusable. I don’t understand how this issue has been going on for a week and nobody noticed, when you can’t even use OpenCode at all.

  6. iloveferrari commented on Mar 9, 2026

    @iloveferrari

    你opencode打开的工程里是不是包含了.git目录?如果有你删了试试?

  7. jwkicklighter commented on Mar 9, 2026

    @jwkicklighter

    Same issue on MacOS with tmux 3.5a and 3.6a

  8. thdxr commented on Mar 9, 2026

    @thdxr
    Member

    what we were seeing is some terminals send SIGHUP to the process when the tab is closed and because opencode didn't handle it, it would hang

    we added exiting on SIGHUP

    i personally use tmux and haven't seen an issue - can someone track down why tmux is sending SIGHUP?

  9. thdxr commented on Mar 9, 2026

    @thdxr
    Member

    it's also possible it's not related to the SIGHUP change
    i need more information than what is being provided here - i can't reproduce any of it

    what does "completely unusable" mean

  10. tobwen commented on Mar 9, 2026

    @tobwen
    Contributor

    My 2 cent (I'm poor):

    My special issue #16564 was fixed with #16565. I cherry picked every commit, traced the function calls and figured out that the second stop() puts PuTTY and other terminal emulators in a bad state... And a simple reset or control-characters couldn't reset it.

    As I discussed in Discord, the real problem might be more upstream in the stop() functtion in OpenTUI. All this Alternate Screen is horror, since it uses a separate buffer in terminal emulators and when there's screen or tmux in between, it can be even worse. I has to do with the SGR Mouse Mode of xterm-aware/non-fully-aware applications, I guess.

    I think of writing a small OpenTUI test application, but the annoying thing is: I wasn't able to automate the testing, since it needs mouse interaction. Maybe I could write an application, which reads the characters on the screen so that bisecting and debugging is easier.

    what does "completely unusable" mean

    See the picture posted by me and in the first post... You literally can't use opencode anymore, when you're in this state. These escape sequences not even fill the monitor, it makes keyboard interaction impossible.

  11. thdxr commented on Mar 9, 2026

    @thdxr
    Member

    we traced down at least one of the issues to these binds in tmux conf - investigating further

    bind -n M-[ select-window -t -1
    bind -n M-] select-window -t +1
    
  12. jwkicklighter commented on Mar 9, 2026

    @jwkicklighter

    Yep, that was from my config on X. I confirmed that removing the select-window binds got rid of the problem for me.

    My config is based on the Omarchy config with a few keybinds changed, in case that's relevant to anyone else.

  13. asaf92 commented on Mar 10, 2026

    @asaf92
    Author

    For what it's worth, I don't have any select-window bindings:

    # Use Ctrl-a as prefix instead of Ctrl-b
    set -g prefix C-a
    unbind C-b
    bind C-a send-prefix
    
    # vi keys in copy-mode
    set -g mode-keys vi
    unbind -T copy-mode-vi v
    bind   -T copy-mode-vi v send -X begin-selection
    unbind -T copy-mode-vi C-v
    bind   -T copy-mode-vi C-v  send -X rectangle-toggle
    
    # Yank goes straight to clipboard if desired
    # X11: xclip
    bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'xclip -selection clipboard -in'
    
    # Enable OSC52 clipboard integration if terminal supports it
    set -g set-clipboard on
    
    # Start window/pane numbering at 1
    set -g base-index 1
    setw -g pane-base-index 1
    
    # Color support
    set -g default-terminal "tmux-256color"
    set -as terminal-overrides ",*:Tc"
    
    # Pane switching
    is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
        | grep -iqE '^[^TXZ ]+ +(n?vim|Neovim)'"
    
    bind -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
    bind -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
    bind -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
    bind -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
    
    # New panes/windows open in the same directory
    bind '"' split-window -v -c "#{pane_current_path}"
    bind % split-window -h -c "#{pane_current_path}"
    bind c new-window -c "#{pane_current_path}"

    One thing I noticed:
    ctrl+p doesn't work, it just types ^P into the "grey buffer" thing, but if I follow up with enter or ctrl+m then it does work and open the menu.

  14. roccolycos commented on Mar 10, 2026

    @roccolycos

    same error in 1.2.24

  15. Almazick commented on Mar 10, 2026

    @Almazick

    Everything works from beta version bunx opencode-ai@beta

  16. hrez commented on Mar 10, 2026

    @hrez

    what does "completely unusable" mean

    tab doesn't switch agents, cntl-p only inserts ^P, arrows don't work, esc doesn't work, enter or shift-enter or cntr-enter or cntr-j just adds a new line. So, can't even send a prompt at all. That's why it's unusable.
    The regression came in 1.2.17. Which makes it one of the commits from 1.2.16.

    P.S. I have neither M-[ nor select-window in .tmux.conf

  17. dronax commented on Mar 10, 2026

    @dronax

    I faced the same issue with same environment (tmux and wsl), now i am using local build instead of the packaged build. It is working without any issue.

  18. asaf92 commented on Mar 10, 2026

    @asaf92
    Author

    I can also confirm that a local build (using commit 5ec5d1dac) seems to work

  19. tobwen commented on Mar 10, 2026

    @tobwen
    Contributor

    Funny, an older build worked only when it's in ~/.opencode/bin/opencode. When I moved it somewhere else, it broke. I really gave up debugging this.

  20. tobwen commented on Mar 10, 2026

    @tobwen
    Contributor

    Everything works from beta version bunx opencode-ai@beta

    @asaf92 In your local build? Because your PR got closed.

  21. asaf92 commented on Mar 11, 2026

    @asaf92
    Author

    Everything works from beta version bunx opencode-ai@beta

    @asaf92 In your local build? Because your PR got closed.

    Yeah no need for the PR. Try to build the latest dev branch

  22. karamanliev commented on Mar 12, 2026

    @karamanliev

    opencode works fine for me in a regular tmux window or pane, but I usually run it in a scratch popup, where I see the same broken behavior shown in the OP’s screenshot.

    It happens in both an arch linux desktop PC and a ubuntu 24.04 laptop. Both PCs have 1.2.24 installed.

    Image
  23. asaf92 commented on Mar 13, 2026

    @asaf92
    Author

    Works in 1.2.25

  24. thdxr commented on Mar 21, 2026

    @thdxr
    Member

    do you mind checking latest beta to see if it still works right? npx opencode-ai@beta

  25. hrez commented on Mar 22, 2026

    @hrez

    do you mind checking latest beta to see if it still works right? npx opencode-ai@beta

    0.0.0-beta-202603212143 works fine

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingopentuiThis 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