^[control-codes
live in libghostty-vt

Operating system commands

OSC 52 Manipulate Selection Data

View as Markdown

Let a program set or read the clipboard, even over ssh.

OSC 52 ; Pc ; Pd ST
ECMA-48
§8.3.89 OSC – Operating System Command, p. 51
xterm
Operating System Commands

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

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984NoOSC is not among the controls it recognizes (§4.2)
VT510manual, 1st ed., 1993Noignores an OSC string (chapter 4)
xtermpatch 412, xterm-411aPartlyoff by default: SetSelection and GetSelection are refused unless allowWindowOps is set
libghostty-vt0f171f6Partlysets the clipboard through its host; does not answer a query (OSC52-2)
Konsole26.11.70, a24c3d71Partlysets or clears the clipboard and primary selection; does not answer ?
ConEmubuild 230724, its documentationNonot 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
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.