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.
Support
| Terminal | Version | Support | Notes |
|---|---|---|---|
| VT220 | manual, 2nd ed., 1984 | No | OSC is not among the controls it recognizes (§4.2) |
| VT510 | manual, 1st ed., 1993 | No | ignores an OSC string (chapter 4) |
| xterm | patch 412, xterm-411a | Partly | off by default: SetSelection and GetSelection are refused unless allowWindowOps is set |
| libghostty-vt | 0f171f6 | Partly | sets the clipboard through its host; does not answer a query (OSC52-2) |
| Konsole | 26.11.70, a24c3d71 | Partly | sets or clears the clipboard and primary selection; does not answer ? |
| ConEmu | build 230724, its documentation | No | not in ConEmu’s list, ANSI escape codes |
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