The Problem
When using a Chromebook (Crostini) and connecting via SSH to a remote server, you might encounter a frustrating clipboard issue. Copy-paste works perfectly when running opencode alone, and it works fine when using byobu alone. However, when you run opencode inside a byobu session, copy-paste operations suddenly stop working.
Technical Environment Details
- Client: Chromebook running Linux via Crostini
- Connection: SSH to a remote server
- Tools:
byobu(usingtmuxbackend),opencode - Clipboard utility:
wl-copyis available but fails because there is noWAYLAND_DISPLAYavailable on the remote server.
Root Cause Analysis
The root cause of this issue lies in how tmux (which powers byobu) handles clipboard operations. When running over SSH, there is no Wayland or X11 display available on the remote server. While opencode might successfully attempt to use OSC-52 escape sequences to copy to the local clipboard, tmux acts as a middleman and actively blocks these clipboard escape sequences by default, preventing them from reaching your local terminal emulator.
What Didn’t Work
Before finding the correct solution, I tried a few approaches that failed:
- X11 Forwarding (
ssh -Xorssh -Y): I tried enabling X11 forwarding to pass the clipboard through. This failed because Crostini uses Wayland natively, and relying on XWayland for clipboard synchronization over SSH introduces latency and doesn’t play well withtmux. - Modifying
config.jsonClipboard Settings: I looked intoopencode’s configuration files to force different clipboard backends, but this did not bypass thetmuxbarrier.
The Final Working Solution
The fix requires configuring tmux to allow clipboard sequences to pass through. Add the following lines to your ~/.tmux.conf file on the remote server:
set -g set-clipboard on
set-option -g allow-passthrough on
After saving the file, reload your tmux configuration by running:
tmux source-file ~/.tmux.confWhy This Works: Understanding OSC-52
The magic behind this solution is OSC-52 (Operating System Command 52). It is an ANSI escape sequence that allows a remote application to send text directly to the local terminal emulator’s clipboard, bypassing the need for X11 forwarding or complex SSH tunnels.
When you copy text in opencode, it can output an OSC-52 escape sequence. * set -g set-clipboard on tells tmux to use the clipboard. * set-option -g allow-passthrough on is the crucial part: it enables tmux to pass the OSC-52 escape sequences directly through to your local terminal (in this case, your Chromebook’s terminal emulator). Once the sequence reaches your terminal emulator, it handles injecting the copied text into your Chromebook’s local clipboard.
Troubleshooting
If you are still experiencing issues after applying the solution above, check the following:
- Check Terminal Emulator Support: Ensure your local terminal emulator supports OSC-52. The default Crostini terminal does, but if you are using an alternative terminal app, verify its OSC-52 capabilities and ensure they are enabled in its settings.
- Verify Byobu Backend: Make sure
byobuis actually usingtmuxas its backend (this is the default in modern versions). You can check by runningbyobu-info. - Nested Sessions: If you have nested
tmuxorbyobusessions, you need to ensure the passthrough settings are applied to all layers, though it’s generally best to avoid nesting.