Skip to main content
ansicode

OSC 52 — System clipboard read/write

Set (or query) the host system clipboard via the terminal — works over SSH without X11 forwarding.

Byte forms

Every common string-literal form so you can paste-and-search either direction.

\\x1b[\x1b]52;c;BASE64\x07 (set clipboard 'c' to BASE64 decoded bytes)
\\033[\033]52;c;BASE64\007
\\e[\e]52;c;BASE64\a
ESC [ESC ] 52 ; SELECTION ; PAYLOAD BEL
hex1b 5d 35 32 3b ... 07

Description

Set the system clipboard from terminal output. The first parameter is the selection: `c` = CLIPBOARD, `p` = PRIMARY, `s` = secondary, `q` = `0..9` cut-buffers. The second parameter is base64-encoded bytes; a literal `?` instead queries the current contents (and the terminal replies with `\x1b]52;c;BASE64\x07`). This is how `tmux set -g set-clipboard on`, `vim` (via `clipboard=unnamedplus,osc52`), `neovim` (`vim.g.clipboard`), and `yazi --copy` make yank work across SSH. Disabled by default in most terminals (security: a malicious log line can replace the user's clipboard); enable explicitly per terminal.

Spec citation: xterm-ctlseqs (OSC 52)

Examples

bash
printf '\033]52;c;%s\007' "$(printf 'hello' | base64)"
python
import sys, base64\npayload = base64.b64encode(b'hello').decode()\nsys.stdout.write(f'\x1b]52;c;{payload}\x07')
go
import "encoding/base64"\nfmt.Printf("\x1b]52;c;%s\x07", base64.StdEncoding.EncodeToString([]byte("hello")))
javascript
process.stdout.write('\x1b]52;c;' + Buffer.from('hello').toString('base64') + '\x07')
c
/* assumes base64_encode() helper */\nprintf("\x1b]52;c;%s\x07", base64_encode("hello", 5));

Terminal support

xterm
yes
Linux console (fbcon)
no
macOS Terminal.app
no
iTerm2
yes
Windows Terminal
partial
cmd.exe / ConPTY
no
kitty
yes
alacritty
yes
WezTerm
yes
Ghostty
yes
GNOME Terminal
partial
Konsole
yes
tmux
no
GNU screen
no

Related sequences