Skip to content

tui: clipboard copy silently fails inside tmux (OpenTUI wraps OSC 52 in DCS passthrough that tmux drops) #59134

Closed as duplicate

Description

@gdevenyi

Summary

Copying from the OpenCode TUI silently fails to reach the system clipboard when OpenCode runs inside tmux. The root cause is in OpenTUI (anomalyco/opentui, the TUI toolkit OpenCode's terminal UI is built on), not in tmux: OpenTUI wraps its OSC 52 clipboard write in a tmux DCS passthrough escape, which tmux (3.3+) silently drops unless allow-passthrough is enabled. A plain (unwrapped) OSC 52 works fine through tmux's set-clipboard on path, so wrapping the clipboard write appears to be counterproductive.

Environment

  • opencode version: 2.1.4 (latest)
  • OS: Linux x86_64 (7.2.9-x64v3-xanmod1)
  • Terminal: WezTerm (OSC 52-capable) → tmux 3.4 (TERM=tmux-256color inside); tmux reports client_termfeatures includes clipboard
  • Shell: /bin/bash
  • Install/channel: npm (@opencode/cli), release
  • Active plugins: @slkiser/opencode-quota@latest
  • tmux config: set -g set-clipboard on; allow-passthrough left at its default (off)

Reproduction

  1. Start tmux 3.4 with default options plus set -g set-clipboard on, inside an OSC 52-capable terminal.

  2. Sanity-check the clipboard chain from a shell pane — this works:

    printf '\033]52;c;%s\033\\' "$(printf 'hello' | base64)"

    Pasting into a GUI app yields hello. ✔

  3. In the OpenCode TUI, copy something: <leader>y (messages.copy, leader defaults to ctrl+x), or select text (copy-on-select is the default terminal.copy mode).

  4. Paste into a GUI app → nothing is pasted. No tmux paste buffer is created either.

Reproducible consistently.

Expected Behavior

Copy (messages.copy, copy-on-select) puts the text on the system clipboard when running inside tmux with set-clipboard on and an OSC 52-capable outer terminal — the plain-OSC 52 test above proves the chain works.

Actual Behavior

The copy action completes without any error, but the clipboard is unchanged.

Root cause: when OpenTUI detects tmux, Terminal.writeClipboard() wraps the OSC 52 sequence in a tmux DCS passthrough (ESC Ptmux; <ESC-doubled OSC 52> ESC \) instead of emitting it plainly — see writeClipboard in opentui packages/core/src/zig/terminal.zig. tmux ≥ 3.3 silently discards passthrough sequences unless allow-passthrough is enabled, so the write never reaches the outer terminal.

Additional Context

  • Setting set -s allow-passthrough on in ~/.tmux.conf fixes it (verified). But every tmux layer must opt in, and the failure mode is completely silent — clipboard.ts write() reports success when the terminal destination status is merely "attempted".
  • Since a plain OSC 52 works through tmux's set-clipboard on (tmux forwards it to the outer terminal itself), consider not wrapping clipboard writes for tmux, or documenting the allow-passthrough requirement.
  • The host-clipboard fallback (xclip/wl-copy) doesn't help in SSH panes without a display, which is where this bites most.
  • Nested tmux (e.g. opencode inside tmux on a remote host inside local tmux): OpenTUI wraps only a single level, so each layer needs the right option even with the workaround.

Activity

  1. opencode-agent commented on Oct 26, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed write-up and root-cause analysis! I think this is a duplicate of #50208. That issue reports the same thing on v2: inside tmux with allow-passthrough off, copying shows success but the outer clipboard never changes, and comments there also confirm that set -s allow-passthrough on works around it.

    Possible duplicates and related issues, ordered from most to least likely:

    Your findings would be very useful on #50208: OpenTUI's writeClipboard wraps the OSC 52 write in a DCS passthrough, plain OSC 52 works through set-clipboard on, and clipboard.ts counts "attempted" as success. Please consider adding them there.

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.

  2. opencode-agent commented on Oct 27, 2026

    @opencode-agent
    Contributor

    We haven't heard back, so I'm closing this as a duplicate of #50208. It covers the same problem: inside tmux with allow-passthrough off, copying in the TUI silently fails to reach the outer clipboard. Please follow that issue for updates. Your root-cause notes would be a helpful addition there: OpenTUI's writeClipboard wraps OSC 52 in a tmux DCS passthrough, a plain OSC 52 works through set-clipboard on, and clipboard.ts counts "attempted" as success. Until it's fixed, set -s allow-passthrough on works around it.

    If your problem turns out to be different from #50208, reply here and explain how. Thanks again for the thorough report!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions