OSC 52 write
OSC 52 write copies data to the system clipboard through the terminal. The application sends base64-encoded content along with a selection target, and the terminal places the decoded data onto the specified clipboard.
Syntax
OSC 52 ; Pc ; Pd ST Set clipboard contents
OSC52-write = 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. Multiple characters may be combined. |
Pd | Base64-encoded data to place on the clipboard. |
Selection targets:
| Value | Meaning |
|---|---|
c | System clipboard (most commonly used) |
p | Primary selection (X11) |
s | Secondary selection (X11) |
0-7 | Cut buffers 0 through 7 (legacy X11) |
Description
OSC 52 was introduced by XTerm to allow terminal applications to write to the system clipboard without requiring direct access to the display server. This is particularly valuable when working over SSH, inside tmux, or in other situations where the application does not have direct clipboard access.
The data payload Pd must be base64-encoded. The terminal decodes the base64 content and places the resulting text on the clipboard specified by Pc. Most modern terminals only support the c (clipboard) and sometimes p (primary) selections; the cut buffer targets (0-7) and secondary selection (s) are rarely implemented.
When multiple selection characters are given in Pc, the terminal should set the content on all specified clipboards. In practice, most terminals treat any value of Pc as the system clipboard.
Some terminals impose a size limit on OSC 52 payloads. XTerm limits the decoded content to 100,000 bytes by default (configurable via the maxStringParse resource). Other terminals may have different limits or no limit at all.
Examples
# Copy "Hello, world!" to the system clipboard
printf '\e]52;c;%s\e\\' "$(echo -n 'Hello, world!' | base64)"
# Copy text to both clipboard and primary selection
printf '\e]52;cp;%s\e\\' "$(echo -n 'Hello' | base64)"
# Using BEL as the string terminator
printf '\e]52;c;%s\a' "$(echo -n 'Hello' | base64)"
Specifications
| Specification | Section |
|---|---|
| XTerm ctlseqs | — |
Terminal support
| Terminal | Support | Version | Notes |
|---|---|---|---|
| Terminal Emulators | |||
| Alacritty | ~ | Yes | Only clipboard and primary selection per escape_support.md:104 |
| Bobcat | ? | ? | PermitClipboardWrite() option exists, but actual OSC 52 handling is in TerminalCtrl library |
| contour | ✓ | v0.1.0 | Clipboard write/copy operations |
| foot | ✓ | Yes | Clipboard write with security config, osc.c:27-107 |
| Ghostty | ✓ | v1.0.0 | |
| iTerm2 | ✓ | v20260216-nightly | |
| Kitty | ✓ | Yes | Clipboard write with extended OSC 5522 support |
| Konsole | ✓ | Yes | Clipboard enum value 52 in src/Vt102Emulation.h:193, write (copy) in src/Vt102Emulation.cpp:1276-1283 |
| mintty | ✓ | Yes | Implemented at termout.c:4556-4617, clipboard write via OSC 52 (requires AllowSetSelection config option) |
| mlterm | ✓ | rel-3_0_9 | Requires user permission via allow_osc52 option |
| PuTTY | ✗ | No | Not implemented in do_osc function |
| Rio | ✓ | v0.0.3 | |
| rxvt-unicode | ✗ | No | Not implemented; clipboard handled via X11 selections |
| st | ✓ | 0.8 | Requires allowwindowops enabled |
| terminology | ✓ | v1.14.0 | Requires selection_escapes config enabled |
| VT100 | ✗ | No | |
| VTE | ✗ | No | OSC 52 listed as unsupported in vteseq.cc case statement |
| WezTerm | ✓ | Yes | OSC 52 ManipulateSelectionData for clipboard write - see wezterm-escape-parser/src/osc.rs:42,170-183,317,484 |
| Windows Terminal | ✓ | Yes | SetClipboard case via _GetOscSetClipboard; write-only (query ignored) |
| xterm | ✓ | Yes | OSC 52 manipulates selection data (clipboard). Requires OPT_PASTE64 compile flag and allowWindowOps resource (OSC_SelectionData=52 in misc.c:3496) |
| xterm.js | ✓ | 6.0.0 | Requires addon-clipboard |
| Multiplexers | |||
| cy | ✓ | v1.7.0 | Clipboard write functionality |
| GNU Screen | ✗ | No | |
| tmux | ✓ | 2.4 | Clipboard write support |
| tuios | ✗ | No | |
| Zellij | ✓ | v0.31.2 | |
See also
- OSC 52 read — Clipboard Read — Query clipboard contents via OSC 52