Skip to content

fix(clipboard): add OSC 52 fallback for SSH/tmux environments - #7028

Closed
wonderflow wants to merge 1 commit into
anomalyco:devfrom
wonderflow:jianbo/fallback
Closed

fix(clipboard): add OSC 52 fallback for SSH/tmux environments#7028
wonderflow wants to merge 1 commit into
anomalyco:devfrom
wonderflow:jianbo/fallback

Conversation

@wonderflow

@wonderflowwonderflow commented Jan 6, 2026

Copy link
Copy Markdown

Problem

Clipboard copy operations (e.g., Ctrl+X Y to copy assistant message) silently fail when running opencode over SSH or in tmux on a remote Linux server without X11/Wayland display.

Root cause: The fallback path uses clipboardy, which relies on xsel/xclip and requires a local display ($DISPLAY or $WAYLAND_DISPLAY). In headless SSH/tmux environments, these tools aren't available or don't work, causing clipboard operations to fail silently.

Solution

Add OSC 52 escape sequence support as a fallback when clipboardy fails.
OSC 52 is a terminal escape sequence standard that allows applications to set the system clipboard through the terminal emulator. It's supported by:

  • iTerm2
  • kitty
  • Alacritty
  • Windows Terminal
  • tmux (with set-clipboard option)
  • Many other modern terminal emulators

Changes

  • Added copyViaOSC52() function that sends OSC 52 escape sequences
  • Handles tmux passthrough wrapping when $TMUX is set
  • Modified fallback logic: try clipboardy first → fall back to OSC 52 on failure

Behavior

EnvironmentBeforeAfter
macOS localosascript ✅osascript ✅ (unchanged)
Linux + X11/Waylandxclip/xsel/wl-copy ✅xclip/xsel/wl-copy ✅ (unchanged)
Windowspowershell ✅powershell ✅ (unchanged)
SSH/tmux (no display)clipboardy ❌ (silent fail)clipboardy → OSC 52 ✅

No breaking changes - existing behavior preserved for all native clipboard methods.

Testing

  1. SSH into a remote Linux server
  2. Run opencode in tmux with iTerm2 integration
  3. Get a response from the assistant
  4. Press Ctrl+X Y to copy the assistant's message
  5. Cmd+V on local machine to verify clipboard content

Prerequisite

  • Enable "Applications in terminal may access clipboard" in iTerm2 Preferences → General → Selection

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Results

No duplicates found.

The search for the current PR (7028: "fix(clipboard): add OSC 52 fallback for SSH/tmux environments") returned only the PR itself.

While there are other clipboard-related PRs in the repository:

These are addressing different clipboard issues and platforms, not the same SSH/tmux OSC 52 fallback feature being implemented in PR #7028.

@thdxr
thdxrforce-pushed the dev branch 3 times, most recently from f1ae801 to 08fa7f7CompareJanuary 30, 2026 14:37
@github-actionsgithub-actionsBot mentioned this pull request Feb 18, 2026
5 tasks
@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@wonderflow