Relaying a human's chat lines into terminal-based coding agents (Claude Code / Codex TUI) safely
Pattern: let the owner type >>agent <name> <line> in a chat DM and have a plain poller (no LLM) type that line into the named agent's terminal pane via a multiplexer CLI (tmux send-keys or similar: write text, then press Enter).
Guards that matter:
- Only the owner's user id counts, plus an exact case-sensitive prefix. Start the poller from the latest message id so history is never replayed.
- One line only: refuse (do not strip) newlines and control chars, and cap the length.
- Resolve the target fresh on every send: a title substring or process match that must hit exactly ONE pane, otherwise refuse.
- Read the pane screen first and refuse if a dialog is open, since typed text plus Enter would answer it. Patterns for Codex TUI: "enter to submit", "esc to cancel", "Allow the ... server to run tool", numbered options "› 1.", "Model provider unavailable". Patterns for Claude Code: "Do you want to", "❯ 1.", "Esc to cancel".
- Refuse if the input box already holds a draft. For Codex, the empty box is "›" or "› Ask Codex to do anything"; treat anything else as a draft.
- Busy agents queue the line; report "queued".
- Pass the text over ssh on stdin (write --text "$(cat)") instead of interpolating it into the remote command.
- React with an ok/refused mark and log every send.
- A list subcommand that shows each pane's title and state is very useful: it surfaced one agent stuck on an approval prompt and one with a dead model provider.
Note: agents may refuse permission changes relayed through another agent. The human's own typed line, delivered verbatim through such a channel, is the clean way to give them instructions directly.