Copy remote command output to your local Mac clipboard — over SSH, no extra tools required.
The problem: When you're SSH'd into a remote machine and working inside a multiplexer like tmux or Zellij, copying output between panes — and then sharing it with an AI agent or another tool — means endless manual select → copy → paste cycles. There's no pbcopy on Linux, and xclip/xsel don't work over SSH.
The solution: A tiny shell script that wraps output in an OSC 52 terminal escape sequence. Your local terminal (iTerm2) sees the sequence and writes the content directly to your Mac clipboard — transparently, over the existing SSH connection.
remote command output
→ base64 encoded
→ wrapped in \033]52;c;<data>\a
→ sent through SSH to your terminal
→ iTerm2 writes it to macOS clipboard
No sockets, no ports, no daemons. Just a terminal escape sequence.
On your Mac (one-time):
iTerm2 → Settings → General → Selection → enable "Applications in terminal may access clipboard"
Multiplexer passthrough:
- Zellij: works out of the box
- tmux: add
set -s set-clipboard onto~/.tmux.conf
Run this on your remote Linux machine:
bash <(curl -fsSL https://raw.githubusercontent.com/Meteors27/remote-pbcopy/main/install.sh)Then reload your shell:
source ~/.bashrc # or source ~/.zshrc# 1. Install pbcopy
sudo tee /usr/local/bin/pbcopy << 'EOF'
#!/bin/bash
printf "\033]52;c;$(cat | base64 | tr -d '\n')\a"
EOF
sudo chmod +x /usr/local/bin/pbcopy
# 2. Add cpy alias (shows output AND copies)
echo "alias cpy='tee >(pbcopy)'" >> ~/.bashrc
source ~/.bashrc# Copy to clipboard (silent)
echo "hello" | pbcopy
cat file.txt | pbcopy
git log --oneline | head -20 | pbcopy
# Show output AND copy simultaneously
ls -la | cpy
grep -r "TODO" . | cpybash <(curl -fsSL https://raw.githubusercontent.com/Meteors27/remote-pbcopy/main/install.sh) --verify- Requires iTerm2 on the Mac side (or another terminal with OSC 52 support, e.g. WezTerm, Kitty)
- Large payloads (>100 KB) may be truncated by some terminals
- Multi-hop SSH (jump hosts): OSC 52 only propagates through the terminal you're directly connected to
MIT