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
Fromtty-features.c:86-94, clipboard support uses the OSC 52 escape sequence:
Clipboard Targets
OSC 52 supports multiple clipboard targets:c: Clipboard (standard system clipboard)p: Primary selection (X11 middle-click paste)s: Secondary selection0-7: Cut buffers (rarely used)
c for the main clipboard.
Configuration
Enable Clipboard Support
~/.tmux.conf
options-table.c:505-510, the option accepts:
- on
- external
- off
Full clipboard integration:
- Copies from copy mode set system clipboard
- Applications can set clipboard via OSC 52
- Bidirectional sync enabled
Terminal Feature Detection
tty-features.c:475-477, modern terminals include clipboard by default:
Copy to Clipboard
From Copy Mode
When text is selected in copy mode:Using copy-pipe
Fromwindow-copy.c:5034-5080, the copy-pipe command copies selection and pipes to external command:
key-bindings.c:456-459:
Copy Commands
window-copy.c:2776-2819, copy-pipe commands:
copy-pipe-end-of-linecopy-pipe-end-of-line-and-cancelcopy-pipe-linecopy-pipe-line-and-cancelcopy-pipe-no-clearcopy-pipecopy-pipe-and-cancel
Paste from Clipboard
Get Clipboard Option
Fromoptions-table.c:411-420, control how tmux responds to clipboard requests:
Configuration
OSC 52 Clipboard Request
Frominput.c:3099-3109, when an application requests the clipboard:
Manual Paste
Clipboard Query
Fromtty.c:3021-3028, tmux can query the terminal clipboard:
Clipboard Query Callback
Fromtty.c:3013-3019:
TTY_QUERY_TIMEOUT.
Clipboard Response Handling
Fromtty-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
Fromoptions-table.c:1609:
~/.tmux.conf
External Clipboard Tools
Platform-Specific Integration
- Linux (X11)
- Linux (Wayland)
- macOS
- Windows (WSL)
~/.tmux.conf
Clipboard Manager Integration
Troubleshooting
Clipboard not working in terminal
Clipboard not working in terminal
Verify terminal supports OSC 52:From
tty-keys.c:752, tmux logs clipboard events:Clipboard data truncated
Clipboard data truncated
OSC 52 has size limits depending on terminal:
- Most terminals: 100KB - 1MB
- Some terminals: Unlimited
- SSH: May have lower limits
Clipboard not accessible to applications
Clipboard not accessible to applications
Applications must explicitly request clipboard:
Timer issues with clipboard query
Timer issues with clipboard query
From If queries time out:
tty-keys.c:1402, query timeout:Security Considerations
OSC 52 Risks
- Application access: Any application in tmux can read/write clipboard
- Remote access: SSH sessions can access local clipboard
- Data leakage: Clipboard content may be logged
Mitigation Strategies
Audit Clipboard Usage
Advanced Techniques
Bidirectional Sync Script
~/bin/tmux-clipboard-sync
Clipboard History Manager
Related Options
set-clipboard- Enable clipboard integrationget-clipboard- Control clipboard requeststerminal-features- Clipboard capability
Related Commands
set-buffer- Set tmux paste buffersave-buffer- Save buffer to fileload-buffer- Load buffer from filepaste-buffer- Insert buffer contentschoose-buffer- Interactively select buffer