OSC 52 Manipulate Selection Data
Let a program set or read the clipboard, even over ssh.
OSC 52 ; Pc ; Pd ST
OSC 52 ; Pc ; Pd ST puts Pd, which is base64, on the clipboard. Pc names which: c the clipboard, p the primary selection, q the secondary, s the selection xterm is configured to use, 0 to 7 X’s cut buffers; left empty, it means s 0. Pd of ? asks for the contents instead, and the answer is OSC 52 ; Pc ; base64 ST. Anything else that is not base64 clears it. Because it travels in the terminal’s own data stream, it works where nothing else can reach the clipboard, from a program on the far side of an ssh connection.
It is xterm’s, and a default xterm does not do it. Reading the clipboard lets any program that writes to the terminal see whatever was last copied, and writing it lets one replace what you are about to paste, so both are among the window operations that are off unless the allowWindowOps resource is set: SetSelection and GetSelection are in the default disallowedWindowOps (main.h, ManipulateSelectionData). Such a terminal consumes the sequence and does nothing.
libghostty-vt parses the sequence and hands it to its host through the CLIPBOARD_WRITE and CLIPBOARD_READ callbacks; with none installed, it does nothing either. Whether to install them, and whether to ask the person at the keyboard first, is the host’s choice, as allowing them is in xterm. The runner installs neither, matching a default xterm, so the cases pass. Ghostty itself has a clipboard-read and a clipboard-write setting for the same choice.
Validation
OSC52-1: Setting the clipboard changes nothing on screen
A
\e]52;c;SGVsbG8=\a # "Hello"
B
|AB____|
cursor 1,3
reply none
OSC52-2: A question is not answered
\e]52;c;?\a
\e]52;;?\e\\
|______|
reply none