OSC 52 read
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
(* 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
| Parameter | Description |
|---|---|
Pc | Clipboard selection target to query. |
? | Query indicator (sent in request). |
Pd | Base64-encoded clipboard content (returned in response). |
Selection targets:
| Value | Meaning |
|---|---|
c | System clipboard |
p | Primary selection (X11) |
s | Secondary selection (X11) |
0-7 | Cut 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.
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
| Specification | Section |
|---|---|
| XTerm ctlseqs | — |
Terminal support
| Terminal | Support | Version | Notes |
|---|---|---|---|
| Terminal Emulators | |||
| Alacritty | ✓ | v0.4.0 | Disabled by default; requires terminal.osc52 config |
| Bobcat | ? | ? | PermitClipboardRead() option exists, but actual OSC 52 handling is in TerminalCtrl library |
| contour | ✗ | No | OSC 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.0 | Requires security.osc52 config option set to enabled or paste-enabled |
| Ghostty | ✓ | v1.0.0 | Query with '?' is supported |
| iTerm2 | ✓ | Yes | Query support implemented - OSC 52 with ? parameter triggers terminalReportPasteboard callback |
| Kitty | ✓ | 0.10.0 | Uses OSC 5522 for reading, standard OSC 52 for writing |
| Konsole | ✗ | No | OSC 52 write (copy to clipboard) is supported, but OSC 52 read (query clipboard) is not implemented |
| mintty | ✓ | Yes | OSC 52 read (?) is implemented at src/termout.c:4577-4594. Requires cfg.allow_paste_selection |
| mlterm | ✗ | No | OSC 52 only supports writing (set_selection), not reading clipboard content |
| PuTTY | ✗ | No | OSC 52 write (copy to clipboard) is supported, but OSC 52 read (query clipboard) is not implemented |
| Rio | ✓ | v0.0.28 | Triggered by OSC 52 with '?' parameter |
| rxvt-unicode | ✗ | No | Available via Perl extension (clipboard-osc), not built into core |
| st | ✗ | No | Only writes to clipboard (OSC 52 set), does not respond with clipboard content for read operations |
| terminology | ✓ | v1.14.0 | Requires selection_escapes config option enabled |
| VT100 | ✗ | No | |
| VTE | ✗ | No | OSC 52 is recognized but falls through to default case (ignored) |
| WezTerm | ✗ | No | OSC 52 write (SetSelection) is supported, but QuerySelection is parsed but not handled (empty handler at performer.rs:788) |
| Windows Terminal | ✗ | No | OSC 52 write is supported, but query (read) is parsed and ignored |
| xterm | ✓ | xterm-268 | OSC 52 with '?' parameter for reading selection. Requires allowWindowOps resource |
| xterm.js | ✓ | 6.0.0 | Requires @xterm/addon-clipboard addon |
| Multiplexers | |||
| cy | ✗ | No | Write only; query returns 'not supported yet' |
| GNU Screen | ✗ | No | OSC 52 for clipboard operations is not implemented |
| tmux | ✓ | 2.9 | Requires get-clipboard option enabled |
| tuios | ✗ | No | Uses Bubbletea's tea.ReadClipboard API which sends OSC 52 queries, but the VT emulator itself doesn't implement OSC 52 read handling |
| Zellij | ✗ | No | OSC 52 write (copy to clipboard) is supported, but read (paste from clipboard with '?') is explicitly not implemented - see grid.rs:2784-2786 |
See also
- OSC 52 write — Clipboard Write — Set clipboard contents via OSC 52