Skip to main content

Overview

tmux supports bidirectional clipboard integration with the host system using the OSC 52 escape sequence. This allows copying from tmux to the system clipboard and pasting from the system clipboard into tmux.

Clipboard Architecture

OSC 52 Protocol

From tty-features.c:86-94, clipboard support uses the OSC 52 escape sequence:
The sequence format:
or with ST terminator:

Clipboard Targets

OSC 52 supports multiple clipboard targets:
  • c: Clipboard (standard system clipboard)
  • p: Primary selection (X11 middle-click paste)
  • s: Secondary selection
  • 0-7: Cut buffers (rarely used)
tmux typically uses c for the main clipboard.

Configuration

Enable Clipboard Support

~/.tmux.conf
From options-table.c:505-510, the option accepts:
Full clipboard integration:
  • Copies from copy mode set system clipboard
  • Applications can set clipboard via OSC 52
  • Bidirectional sync enabled
Default for most modern terminals.

Terminal Feature Detection

From tty-features.c:475-477, modern terminals include clipboard by default:

Copy to Clipboard

From Copy Mode

When text is selected in copy mode:
The selection is automatically sent to the system clipboard using OSC 52.

Using copy-pipe

From window-copy.c:5034-5080, the copy-pipe command copies selection and pipes to external command:
Default bindings from key-bindings.c:456-459:

Copy Commands

From window-copy.c:2776-2819, copy-pipe commands:
  • copy-pipe-end-of-line
  • copy-pipe-end-of-line-and-cancel
  • copy-pipe-line
  • copy-pipe-line-and-cancel
  • copy-pipe-no-clear
  • copy-pipe
  • copy-pipe-and-cancel

Paste from Clipboard

Get Clipboard Option

From options-table.c:411-420, control how tmux responds to clipboard requests:
Configuration

OSC 52 Clipboard Request

From input.c:3099-3109, when an application requests the clipboard:

Manual Paste

Clipboard Query

From tty.c:3021-3028, tmux can query the terminal clipboard:
The query sends:
Terminal responds with clipboard contents.

Clipboard Query Callback

From tty.c:3013-3019:
Timeout if terminal doesn’t respond within TTY_QUERY_TIMEOUT.

Clipboard Response Handling

From tty-keys.c:1305-1402, parsing OSC 52 responses:
1

Receive Response

Terminal sends back:
2

Base64 Decode

tmux decodes the base64 data to get the actual clipboard content.
3

Store in Buffer

Content is stored in tmux paste buffer and can be used.

Clipboard Hook

From options-table.c:1609:
Example uses:
~/.tmux.conf

External Clipboard Tools

Platform-Specific Integration

~/.tmux.conf

Clipboard Manager Integration

Troubleshooting

Verify terminal supports OSC 52:
From tty-keys.c:752, tmux logs clipboard events:
OSC 52 has size limits depending on terminal:
  • Most terminals: 100KB - 1MB
  • Some terminals: Unlimited
  • SSH: May have lower limits
For large data, use external clipboard tools instead.
Applications must explicitly request clipboard:
From tty-keys.c:1402, query timeout:
If queries time out:

Security Considerations

Clipboard integration has security implications:

OSC 52 Risks

  1. Application access: Any application in tmux can read/write clipboard
  2. Remote access: SSH sessions can access local clipboard
  3. Data leakage: Clipboard content may be logged

Mitigation Strategies

Audit Clipboard Usage

Advanced Techniques

Bidirectional Sync Script

~/bin/tmux-clipboard-sync

Clipboard History Manager