Running AI coding agents in tmux
tmux quietly became the standard harness for terminal AI agents: it's how you run five coding agents in parallel, keep them alive after you close your laptop, and script interactions with them. The 50-year-old Unix answer to a 2026 problem.
Why tmux fits agents so well
An agent session is a long-running interactive terminal process — exactly what tmux manages. Sessions give each agent a persistent home that survives disconnects; panes give you a mission-control view of several at once; send-keys and capture-pane give scripts (or an orchestrating agent) hands and eyes on any of them.
The parallel-agents layout
One window per task, or a tiled window of agent panes you can watch at once:
tmux new -d -s agents -n fix-auth
tmux send-keys -t agents:fix-auth "claude" Enter
tmux new-window -t agents -n add-tests
tmux send-keys -t agents:add-tests "claude" Enter
tmux new-window -t agents -n refactor
tmux send-keys -t agents:refactor "claude" Enter
tmux attach -t agents # prefix w shows all three, with previewsPair with git worktrees
Parallel agents in one repo trample each other's changes. The standard pattern is one git worktree per agent — same repo, isolated working directories — with each tmux window cd'd into its own worktree. Window name = branch name and the mapping stays legible.
Scripting the loop
send-keys types into an agent; capture-pane -p reads what it said — enough to build watchdogs, auto-approvers, or a supervisor that round-robins between agents:
# check on an agent
tmux capture-pane -t agents:fix-auth -p | tail -20
# nudge it
tmux send-keys -t agents:fix-auth "continue, and run the tests" EnterQuality-of-life for agent-watching
setw -g monitor-activity on + set -g visual-activity on flags windows where an agent produced output while you were elsewhere. prefix z zooms one agent full-screen. A popup (display-popup -E) gives you a scratch terminal over the top without disturbing the grid. And because it's all detached-safe, closing your laptop mid-run costs nothing.
Verified against tmux 3.6 · updated July 2026 · more guides · cheat sheet