feat: add OSC 52 clipboard fallback for remote sessions#94
Merged
agavra merged 1 commit intoagavra:mainfrom Jan 15, 2026
Merged
feat: add OSC 52 clipboard fallback for remote sessions#94agavra merged 1 commit intoagavra:mainfrom
agavra merged 1 commit intoagavra:mainfrom
Conversation
Problem ------- The current clipboard implementation using arboard relies on system clipboard access (X11, Wayland, or platform-native APIs). This fails silently in common development scenarios: - SSH sessions to remote servers or VMs - Docker/Podman containers without X11 forwarding - WSL without proper clipboard integration - Headless servers and CI environments - tmux/screen sessions on remote machines Solution -------- This commit adds OSC 52 as a fallback when arboard fails. The clipboard export now: 1. Attempts arboard (system clipboard) first 2. Falls back to OSC 52 if arboard fails 3. Reports which method was used in the status message What is OSC 52? --------------- OSC 52 is an ANSI escape sequence (Operating System Command agavra#52) that instructs the terminal emulator to copy text to the system clipboard. The format is: ESC ] 52 ; c ; <base64-encoded-text> BEL The key insight is that escape sequences are interpreted by the LOCAL terminal emulator, not the remote system. When you SSH into a server and an application emits OSC 52, the bytes travel back through the SSH connection and your local terminal handles the clipboard operation. This means clipboard access "just works" over SSH without requiring: - X11 forwarding (-X flag) - Additional tools like xclip/xsel on the remote - Complex clipboard synchronization setups Terminal Support ---------------- OSC 52 is widely supported by modern terminals: - iTerm2 (macOS) - enabled by default - Alacritty - enabled by default - kitty - enabled by default - Windows Terminal - enabled by default - foot - enabled by default - WezTerm - enabled by default - xterm - requires: allowWindowOps: true - gnome-terminal - requires: gsettings set org.gnome.Terminal.Legacy.Settings enable-osc52 true (GNOME 45+) - tmux - requires: set -g set-clipboard on For terminals that support it, no user configuration is typically needed. The feature works transparently. Dependency Impact ----------------- This adds base64 v0.22 as a direct dependency. However, base64 is already present in the dependency tree as a transitive dependency via: syntect -> plist -> base64 Testing ------- Added 4 new unit tests covering: - Correct OSC 52 escape sequence format - Empty string handling - Unicode/emoji encoding - Round-trip encoding of actual markdown content The implementation is refactored to accept a generic Writer, making it fully testable without capturing stdout.
agavra
approved these changes
Jan 15, 2026
Owner
agavra
left a comment
There was a problem hiding this comment.
LGTM! Thanks for the fix, would be great to be able to use this in a tmux session or part of ssh.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The current clipboard implementation using arboard relies on system clipboard access (X11, Wayland, or platform-native APIs). This fails silently in common development scenarios:
Solution
This commit adds OSC 52 as a fallback when arboard fails. The clipboard export now:
What is OSC 52?
OSC 52 is an ANSI escape sequence (Operating System Command #52) that instructs the terminal emulator to copy text to the system clipboard. The format is: ESC ] 52 ; c ; BEL
The key insight is that escape sequences are interpreted by the LOCAL terminal emulator, not the remote system. When you SSH into a server and an application emits OSC 52, the bytes travel back through the SSH connection and your local terminal handles the clipboard operation.
This means clipboard access "just works" over SSH without requiring:
Terminal Support
OSC 52 is widely supported by modern terminals:
For terminals that support it, no user configuration is typically needed. The feature works transparently.
Dependency Impact
This adds base64 v0.22 as a direct dependency. However, base64 is already present in the dependency tree as a transitive dependency via:
syntect -> plist -> base64
Testing
Added 4 new unit tests covering:
The implementation is refactored to accept a generic Writer, making it fully testable without capturing stdout.