Skip to main content

OSC 52 write

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 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
Formal syntax
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​

ParameterDescription
PcClipboard selection target. Multiple characters may be combined.
PdBase64-encoded data to place on the clipboard.

Selection targets:

ValueMeaning
cSystem clipboard (most commonly used)
pPrimary selection (X11)
sSecondary selection (X11)
0-7Cut 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.

note

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​

SpecificationSection
XTerm ctlseqs—

Terminal support​

TerminalSupportVersionNotes
Terminal Emulators
Alacritty~YesOnly 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.0Clipboard write/copy operations
foot✓YesClipboard write with security config, osc.c:27-107
Ghostty✓v1.0.0
iTerm2✓v20260216-nightly
Kitty✓YesClipboard write with extended OSC 5522 support
Konsole✓YesClipboard enum value 52 in src/Vt102Emulation.h:193, write (copy) in src/Vt102Emulation.cpp:1276-1283
mintty✓YesImplemented at termout.c:4556-4617, clipboard write via OSC 52 (requires AllowSetSelection config option)
mlterm✓rel-3_0_9Requires user permission via allow_osc52 option
PuTTY✗NoNot implemented in do_osc function
Rio✓v0.0.3
rxvt-unicode✗NoNot implemented; clipboard handled via X11 selections
st✓0.8Requires allowwindowops enabled
terminology✓v1.14.0Requires selection_escapes config enabled
VT100✗No
VTE✗NoOSC 52 listed as unsupported in vteseq.cc case statement
WezTerm✓YesOSC 52 ManipulateSelectionData for clipboard write - see wezterm-escape-parser/src/osc.rs:42,170-183,317,484
Windows Terminal✓YesSetClipboard case via _GetOscSetClipboard; write-only (query ignored)
xterm✓YesOSC 52 manipulates selection data (clipboard). Requires OPT_PASTE64 compile flag and allowWindowOps resource (OSC_SelectionData=52 in misc.c:3496)
xterm.js✓6.0.0Requires addon-clipboard
Multiplexers
cy✓v1.7.0Clipboard write functionality
GNU Screen✗No
tmux✓2.4Clipboard write support
tuios✗No
Zellij✓v0.31.2

See also​