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]52;c;BASE64\x07 (set clipboard 'c' to BASE64 decoded bytes)\033]52;c;BASE64\007\e]52;c;BASE64\aESC ] 52 ; SELECTION ; PAYLOAD BEL1b 5d 35 32 3b ... 07Description
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
printf '\033]52;c;%s\007' "$(printf 'hello' | base64)"import sys, base64\npayload = base64.b64encode(b'hello').decode()\nsys.stdout.write(f'\x1b]52;c;{payload}\x07')import "encoding/base64"\nfmt.Printf("\x1b]52;c;%s\x07", base64.StdEncoding.EncodeToString([]byte("hello")))process.stdout.write('\x1b]52;c;' + Buffer.from('hello').toString('base64') + '\x07')/* 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
| xterm | Linux console (fbcon) | macOS Terminal.app | iTerm2 | Windows Terminal | cmd.exe / ConPTY | kitty | alacritty | WezTerm | Ghostty | GNOME Terminal | Konsole | tmux | GNU screen |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| yes | no | no | yes | partial | no | yes | yes | yes | yes | partial | yes | no | no |