Fixing Codex CLI Clipboard Copy over Herdr
I’ve been using Herdr to manage local and remote agent sessions, connecting to my Mac Studio with:
herdr --remote mac-studio
OSC 52 clipboard copy worked perfectly in Herdr terminals and Cursor CLI, but not inside Codex CLI 0.157.1.
Getting Codex to use OSC 52
The remote session looked like:
COLORTERM=truecolor
TERM=xterm-256color
TERM_PROGRAM=ghostty
There was no SSH_CONNECTION. Herdr isn’t SSH, but this also meant Codex didn’t recognise the session as remote.
Testing with:
SSH_CONNECTION=herdr codex
immediately made Codex clipboard operations work over OSC 52.
Herdr conveniently exposes:
HERDR_ENV=1
So I added this to my shell config:
if [[ "${HERDR_ENV:-}" == "1" ]]; then
export SSH_CONNECTION="${SSH_CONNECTION:-herdr}"
fi
This leaves real SSH sessions alone while making Codex recognise Herdr as a remote terminal.
Getting copy-on-select working
There was one more piece.
Codex has its own fullscreen TUI and handles mouse selection itself, so Herdr’s:
[ui]
copy_on_select = true
doesn’t control selections inside Codex.
Adding this to ~/.codex/config.toml fixed it:
[tui]
copy_on_select = "always"
Codex 0.157.1 accepts auto, always or never. I had previously been using the default auto.
With both changes in place:
Codex selection
↓
copy_on_select
↓
OSC 52
↓
Herdr remote transport
↓
local macOS clipboard
Copy-on-select now works both in regular Herdr terminals and inside Codex.
The interesting part was that OSC 52 and Herdr were working correctly all along. Codex just needed to know it was effectively running remotely, plus its own copy-on-select setting enabled.