Skip to main content

OSC 52 read

AI-Generated Content
This page was generated with the assistance of AI and may contain inaccuracies. It is intended as a placeholder for future human verification. If you spot issues ahead of its initial review, please report them on GitHub!
Experimental

OSC 52 read queries the terminal for the contents of the system clipboard. The application sends a query with ? as the data parameter, and the terminal responds with the base64-encoded clipboard contents.

Syntax​

OSC 52 ; Pc ; ? ST            Query clipboard contents
OSC 52 ; Pc ; Pd ST Response with clipboard data
Formal syntax
(* Request *)
OSC52-query    = 0x1b, "]", "52", ";", selection, ";", "?", ( 0x07 | 0x1b, "\\" ) ;

(* Response *)
OSC52-response = 0x1b, "]", "52", ";", selection, ";", data, ( 0x07 | 0x1b, "\\" ) ;

selection      = sel-char, { sel-char } ;
sel-char       = "c" | "p" | "s" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ;
data           = base64-char, { base64-char } ;
base64-char    = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J"
             | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T"
             | "U" | "V" | "W" | "X" | "Y" | "Z"
             | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j"
             | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t"
             | "u" | "v" | "w" | "x" | "y" | "z"
             | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
             | "+" | "/" | "=" ;

Parameters​

ParameterDescription
PcClipboard selection target to query.
?Query indicator (sent in request).
PdBase64-encoded clipboard content (returned in response).

Selection targets:

ValueMeaning
cSystem clipboard
pPrimary selection (X11)
sSecondary selection (X11)
0-7Cut buffers 0 through 7 (legacy X11)

Response​

The terminal responds with OSC 52 ; Pc ; Pd ST where Pd is the base64-encoded contents of the requested clipboard. If the clipboard is empty or the operation is denied, the terminal may respond with an empty data field or not respond at all.

Description​

OSC 52 read allows a terminal application to retrieve clipboard contents from the host system. When the terminal receives a query (? as the data parameter), it reads the specified clipboard, base64-encodes the content, and sends it back as an OSC 52 response.

Security considerations

Many terminals disable OSC 52 read by default or require explicit opt-in from the user. Allowing arbitrary programs to read the clipboard is a significant security risk, as the clipboard may contain sensitive data such as passwords. A malicious program running in the terminal could silently exfiltrate clipboard contents.

Terminals that support OSC 52 read typically provide configuration options to control this behavior. XTerm requires the allowWindowOps resource or the selectToClipboard resource to be enabled.

Even among terminals that support OSC 52 write, clipboard read support is significantly less common. Some terminals respond with an empty payload to deny the request without revealing that the feature is unsupported.

Examples​

# Query the system clipboard
printf '\e]52;c;?\e\\'

# Query the primary selection
printf '\e]52;p;?\e\\'

# Read and decode the clipboard response (requires parsing terminal input)
# The response will be: ESC ] 52 ; c ; <base64-data> ST

Specifications​

SpecificationSection
XTerm ctlseqs—

Terminal support​

TerminalSupportVersionNotes
Terminal Emulators
Alacritty✓v0.4.0Disabled by default; requires terminal.osc52 config
Bobcat??PermitClipboardRead() option exists, but actual OSC 52 handling is in TerminalCtrl library
contour✗NoOSC 52 clipboard write is supported (v0.1.0), but reading/querying clipboard is explicitly not supported (comment in code: 'Only setting clipboard contents is supported, not reading')
foot✓1.5.0Requires security.osc52 config option set to enabled or paste-enabled
Ghostty✓v1.0.0Query with '?' is supported
iTerm2✓YesQuery support implemented - OSC 52 with ? parameter triggers terminalReportPasteboard callback
Kitty✓0.10.0Uses OSC 5522 for reading, standard OSC 52 for writing
Konsole✗NoOSC 52 write (copy to clipboard) is supported, but OSC 52 read (query clipboard) is not implemented
mintty✓YesOSC 52 read (?) is implemented at src/termout.c:4577-4594. Requires cfg.allow_paste_selection
mlterm✗NoOSC 52 only supports writing (set_selection), not reading clipboard content
PuTTY✗NoOSC 52 write (copy to clipboard) is supported, but OSC 52 read (query clipboard) is not implemented
Rio✓v0.0.28Triggered by OSC 52 with '?' parameter
rxvt-unicode✗NoAvailable via Perl extension (clipboard-osc), not built into core
st✗NoOnly writes to clipboard (OSC 52 set), does not respond with clipboard content for read operations
terminology✓v1.14.0Requires selection_escapes config option enabled
VT100✗No
VTE✗NoOSC 52 is recognized but falls through to default case (ignored)
WezTerm✗NoOSC 52 write (SetSelection) is supported, but QuerySelection is parsed but not handled (empty handler at performer.rs:788)
Windows Terminal✗NoOSC 52 write is supported, but query (read) is parsed and ignored
xterm✓xterm-268OSC 52 with '?' parameter for reading selection. Requires allowWindowOps resource
xterm.js✓6.0.0Requires @xterm/addon-clipboard addon
Multiplexers
cy✗NoWrite only; query returns 'not supported yet'
GNU Screen✗NoOSC 52 for clipboard operations is not implemented
tmux✓2.9Requires get-clipboard option enabled
tuios✗NoUses Bubbletea's tea.ReadClipboard API which sends OSC 52 queries, but the VT emulator itself doesn't implement OSC 52 read handling
Zellij✗NoOSC 52 write (copy to clipboard) is supported, but read (paste from clipboard with '?') is explicitly not implemented - see grid.rs:2784-2786

See also​