TUI: option to always copy via the terminal (OSC 52), regardless of SSH/tmux detection
What variant of Codex are you using?
CLI
What feature would you like to see?
An option that makes the TUI copy through the terminal (OSC 52) every time, whatever environment it detects.
Problem
Sometimes Codex runs on a remote machine and you reach it through a terminal that isn't an ssh session, such as a remote terminal server or a web-based dev environment. In that case, selection copy, /copy, Ctrl+O and the Ctrl+C copy shortcut all put the text on the remote machine's clipboard. The user's own clipboard doesn't change.
This happens because clipboard_copy.rs decides whether to send OSC 52 by looking at environment variables only:
https://github.com/openai/codex/blob/rust-v0.162.1/codex-rs/tui/src/clipboard_copy.rs#L231-L239
pub(crate) fn is_ssh_session() -> bool {
std::env::var_os("SSH_TTY").is_some() || std::env::var_os("SSH_CONNECTION").is_some()
}
fn is_tmux_session() -> bool {
std::env::var_os("TMUX").is_some() || std::env::var_os("TMUX_PANE").is_some()
}
If none of these are set, Codex copies with the native clipboard and only uses OSC 52 when the native write fails. On a remote macOS or Windows host the native write nearly always works, so the terminal never gets the copy, even when it accepts OSC 52.
Proposal
Add a setting that skips the detection, for example:
[tui]
clipboard = "osc52" # "auto" (today's behaviour) | "native" | "osc52"
or an environment variable such as CODEX_CLIPBOARD=osc52. With osc52, Codex would always send OSC 52 to the terminal (and could still write natively as well, the way the ssh path does now).
Why
The current workaround is to set SSH_CONNECTION yourself before starting Codex. That variable is then inherited by every command Codex runs, and it changes other behaviour too (paste, right-click paste, startup terminal probing). An explicit option would let terminal servers and remote dev tools turn on terminal copy cleanly, without pretending to be an ssh session.
Additional information
#34160 is a related case: a dev container where the native clipboard "works" but is the wrong clipboard. An explicit setting would cover that case as well.
Another case for this option: SpaceTerm, a terminal multiplexer whose server runs shells on one machine while a desktop client on another machine presents them. The client relays OSC 52 to its own clipboard. Codex running under a SpaceTerm server on a remote Mac writes that Mac's pasteboard and never sends OSC 52. None of SSH_TTY, SSH_CONNECTION, TMUX, HERDR_ENV or the Rex markers apply there. A client on another computer can attach to a shell that is already running, so the server can't set something per client.
We tried setting HERDR_ENV=1, which Codex already treats this way (#52557). Herdr then refuses to start in those shells ("nested herdr is disabled by default"), so we reverted it.
Either of these would solve it:
- the opt-in proposed here (
[tui] clipboard = "osc52"orCODEX_CLIPBOARD=osc52), which SpaceTerm would set in every shell; or - treating
SPACETERM=1, which every SpaceTerm shell already sets, the way Codex treatsHERDR_ENV=1.
pi added an equivalent generic opt-in, PI_CLIPBOARD_OSC52=1, for the same reason.