Claude Code in tmux: one window per agent, one worktree per window
Last updated
From a bare tmux to a window per agent, in six steps
1 / 6
Fix what tmux breaks
Out of the box, three things don't work inside it: Shift+Enter submits instead of adding a newline, desktop notifications never reach your terminal, and in fullscreen rendering the mouse wheel scrolls tmux instead of Claude Code.
2 / 6
Open one window per worktree
One worktree per agent, one tmux window per worktree. Two agents in the same directory overwrite each other's files, and a branch alone doesn't prevent it.
3 / 6
Answer the trust dialog
Claude Code saves workspace trust per directory, and each worktree is a new directory. The selected answer is "No, exit": anything a script sends with Enter at that moment exits the agent.
4 / 6
See which agent is waiting
Claude Code fires a notification event when it finishes or waits on a permission prompt and you seem to be away. Turn that into something tmux can see, or into something that reaches you outside tmux.
5 / 6
Detach, and come back over SSH
Detach with Ctrl-b d. The processes keep running. What tmux can't do is keep a laptop awake: if the agents run on the machine you close, they stop with it.
6 / 6
Clean up
git worktree remove refuses a worktree with uncommitted changes, which protects an agent's unmerged work. Merge or commit what you keep, then --force the rest and delete the agent-N branches.
tmux is the cheapest way to run several Claude Code agents: one detached session that survives a closed terminal or a dropped SSH connection, one window per agent, and nothing to install beyond tmux itself. Out of the box, though, three things don't work inside it: Shift+Enter submits instead of adding a newline, desktop notifications never reach your terminal, and in fullscreen rendering the mouse wheel scrolls tmux instead of Claude Code. This guide fixes those, then opens one window per git worktree with a script and shows how to see which agent is waiting on you.
If you are still choosing between tmux, containers and VMs, start with how to run Claude Code agents in parallel, which picks a setup by agent count. This page is the tmux detail; the same windows-per-worktree layout drives Codex CLI, as Codex parallel tasks shows.
Every command below was run on 31 October 2026 on macOS with tmux 3.8 and git 2.50.1, in a throwaway repository under /private/tmp. To avoid spending tokens, the script starts echo claude instead of claude (an AGENT_CMD variable, shown below); one real claude 2.1.314 was started, without a prompt, to capture the trust dialog. The shell prompt is shortened to $.
| You want to | Do this |
|---|---|
| Attach to the agents | tmux attach -t agents |
| Switch agent | Ctrl-b then the window number, or Ctrl-b w for a list |
| Leave everything running | Ctrl-b d (detach) |
| Send Ctrl+B to Claude Code | Press Ctrl+B twice |
| Scroll a Claude Code session | Mouse wheel with set -g mouse on, or PgUp / PgDn |
| See who is waiting | Window flags ! (bell) and ~ (silence) in the status bar |
How do you set up tmux for Claude Code?
Put this in ~/.tmux.conf, then run tmux source-file ~/.tmux.conf:
# Claude Code terminal docs: notifications, progress bar, Shift+Enter
set -g allow-passthrough on
set -g focus-events on
set -s extended-keys on
set -as terminal-features 'xterm*:extkeys'
# Claude Code fullscreen docs: mouse wheel scrolling
set -g mouse on
# Mark windows that ring the bell (used to spot waiting agents)
set -g monitor-bell on
set -g bell-action other
What each part fixes, according to Anthropic's documentation:
- Shift+Enter. Inside tmux, "Shift+Enter submits instead of inserting a newline" even when your outer terminal supports it. The two
extended-keyslines "let tmux distinguish Shift+Enter from plain Enter". If your terminal needs/terminal-setupfor Shift+Enter (VS Code, Cursor, Zed, Alacritty before 0.16), run it in the host terminal, not inside tmux, since it writes to the host terminal's configuration. - Notifications. Without
allow-passthrough, desktop notifications and the progress bar "never reach the outer terminal". - Scrolling. In fullscreen rendering, "without mouse mode, wheel events go to tmux instead of Claude Code".
PgUpandPgDnwork either way. The conversation lives in the alternate screen, so tmux copy mode doesn't see it: pressCtrl+o, then[, to write it into the native scrollback first. - Flicker. Anthropic says tmux releases "through the 3.6 series don't implement synchronized output", so you may see more flicker; the fix is a newer tmux. Don't use fullscreen rendering under iTerm2's
tmux -CCmode: the docs say the mouse wheel does nothing there and double-click can corrupt the terminal.
One conflict the config doesn't solve: Ctrl+B moves a running Bash command or agent to the background in Claude Code, and it is also tmux's prefix. "Tmux users must press Ctrl+B twice." If that gets old, move the tmux prefix (set -g prefix C-a, unbind C-b, bind C-a send-prefix).
On our tmux 3.8, the options took effect:
$ tmux show-options -g allow-passthrough
allow-passthrough on
$ tmux show-options -s extended-keys
extended-keys on
How do you run multiple Claude Code agents in tmux?
One worktree per agent, one tmux window per worktree. Two agents in the same directory overwrite each other's files, and a branch alone doesn't prevent it. This script does both, from the root of the repository:
#!/bin/sh
# Usage: agents.sh N "prompt" (run from the root of the repository)
# N worktrees next to the repo, one tmux window per worktree, one agent per window.
set -e
n=$1; prompt=$2
agent=${AGENT_CMD:-claude}
repo=$(basename "$PWD")
tmux new-session -d -s agents -n main -c "$PWD"
for i in $(seq 1 "$n"); do
dir="../$repo-agent-$i"
git worktree add -q -b "agent-$i" "$dir"
if [ -f .env ]; then cp .env "$dir/"; fi
tmux new-window -t agents -n "agent-$i" -c "$dir"
tmux send-keys -t "agents:agent-$i" "$agent '$prompt'" Enter
done
tmux list-windows -t agents -F "#{window_index} #{window_name} #{pane_current_path}"
It copies .env because a worktree is a fresh checkout without your ignored files. Keep single quotes out of the prompt, or write it to a file. The run:
$ AGENT_CMD="echo claude" ../agents.sh 4 "fix the flaky test in app.test.js"
0 main /private/tmp/tmux-b1/demo/myapp
1 agent-1 /private/tmp/tmux-b1/demo/myapp-agent-1
2 agent-2 /private/tmp/tmux-b1/demo/myapp-agent-2
3 agent-3 /private/tmp/tmux-b1/demo/myapp-agent-3
4 agent-4 /private/tmp/tmux-b1/demo/myapp-agent-4
$ git worktree list
/private/tmp/tmux-b1/demo/myapp 43944bb [main]
/private/tmp/tmux-b1/demo/myapp-agent-1 43944bb [agent-1]
/private/tmp/tmux-b1/demo/myapp-agent-2 43944bb [agent-2]
/private/tmp/tmux-b1/demo/myapp-agent-3 43944bb [agent-3]
/private/tmp/tmux-b1/demo/myapp-agent-4 43944bb [agent-4]
$ tmux capture-pane -p -t agents:agent-3 | grep -v "^$"
echo claude 'fix the flaky test in app.test.js'
$ echo claude 'fix the flaky test in app.test.js'
claude fix the flaky test in app.test.js
$
The trust dialog stops a scripted start
Claude Code saves workspace trust per directory, and each worktree is a new directory. When we started the real claude in a fresh worktree, it stopped here (border trimmed):
Accessing workspace:
/private/tmp/tmux-b1/demo/myapp-agent-1
Quick safety check: Is this a project you created or one you trust? (Like your own code, a
well-known open source project, or work from your team). If not, take a moment to review what's in
this folder first.
Claude Code'll be able to read, edit, and execute files here.
Security guide
❯ No, exit
Yes, I trust this folder
Enter to confirm · Esc to cancel
The selected answer is "No, exit". Anything a script sends with Enter at that moment exits the agent. Attach and answer each window once (Ctrl-b 1, Ctrl-b 2…), and reuse the same worktree paths between runs so the answer is already saved. claude -p skips the trust check, but it is non-interactive.
The fixed ports and the shared local database still collide across worktrees; the parallel agents guide shows both failures and the per-worktree .env that fixes them.
How do you watch several Claude Code sessions at once?
Claude Code fires a notification event when it finishes or waits on a permission prompt and you seem to be away. Turn that into something tmux can see, or into something that reaches you outside tmux:
| Signal | Setup | Where you see it |
|---|---|---|
| Bell flag | "preferredNotifChannel": "terminal_bell" in ~/.claude/settings.json, plus monitor-bell |
! next to the window in the tmux status bar |
| Silence flag | setw -t agents:agent-4 monitor-silence 30 |
~ next to a window that printed nothing for 30 s |
| Desktop notification | allow-passthrough on; iTerm2, Ghostty or Kitty |
Your OS notification center, over SSH too |
| Notification hook | A Notification hook running osascript or notify-send |
Anything you script: sound, popup, phone push |
To test the flags without an agent, we rang the bell in window 2 (printf '\a', which is what terminal_bell sends) and set a 5-second silence timer on window 4, then read the flags with a format string:
$ tmux set-window-option -t agents:agent-4 monitor-silence 5
$ tmux list-windows -t agents -F "#{window_index} #{window_name}#{?window_bell_flag, bell,}#{?window_silence_flag, silent,}"
0 main
1 agent-1
2 agent-2 bell
3 agent-3
4 agent-4 silent
That works with no client attached, so a cron job or a status-bar script can poll it. Two cautions. A working Claude Code session keeps redrawing its spinner, so silence usually means it stopped, but prefersReducedMotion changes those animations. And to check which windows still run an agent, #{pane_current_command} didn't print claude for the real session: it printed the version, 2.1.314. Match on that, or on bash / zsh for windows where the agent exited:
$ tmux list-panes -s -t agents -F "#{window_name} #{pane_current_command} #{pane_pid}"
main bash 74952
agent-1 sleep 74959
agent-2 bash 74966
agent-3 sleep 74973
agent-4 bash 74980
(Here sleep 600 stands in for a running agent in windows 1 and 3.)
How do you detach and resume Claude Code sessions over SSH?
Detach with Ctrl-b d, or from any shell with tmux detach-client -s agents. The processes keep running. We started a counter in window 1, attached a client, detached it, and read the pane twice:
$ tmux list-clients -F "#{client_tty} #{session_name}:#{window_name}"
/dev/ttys005 agents:agent-1
$ tmux detach-client -s agents
$ tmux list-clients | wc -l
0
$ tmux capture-pane -p -t agents:agent-1 | grep -v "^$" | tail -1
step 5
$ tmux capture-pane -p -t agents:agent-1 | grep -v "^$" | tail -1
step 7
From another machine, ssh -t you@host tmux new-session -A -s agents attaches if the session exists and creates it otherwise; tmux attach -d -t agents detaches the other client first. Anthropic gives the same advice for Remote Control: on a remote machine, start claude "inside tmux or screen to keep the session running after you disconnect from SSH". Desktop notifications also cross SSH: the docs say Ghostty and Kitty forward them without setup and iTerm2 after you enable its alerts.
What tmux can't do is keep a laptop awake. If the agents run on the machine you close, they stop with it. That is the case for a server: a VPS you SSH into, compared with a VM per agent in Claude Code on a VPS or a microVM.
Do agent teams work with tmux split panes?
Yes, once you turn them on: agent teams are experimental and off until you set CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1. They default to in-process mode; set "teammateMode": "auto" in ~/.claude/settings.json and, when you are already inside tmux, each teammate gets its own pane. Anthropic notes that tmux "traditionally works best on macOS" and suggests tmux -CC in iTerm2 as the entry point, which conflicts with fullscreen rendering (above). If a team's tmux session outlives Claude Code, the docs' fix is tmux ls then tmux kill-session -t <session-name>.
The difference with the script above: a team coordinates through its lead, and Anthropic warns that "two teammates editing the same file leads to overwrites", so you split the work by file. The script gives each agent its own worktree and no coordination at all, which suits independent tasks, or best-of-N runs where several agents try the same task and you keep one result.
The script's windows, or agent teams in split panes
| The script above | Agent teams | |
|---|---|---|
| To turn it on | Strength: Nothing to install beyond tmux itself | Partial: Off until you turn them on |
| In tmux | One window per agent | Each teammate gets its own pane |
| Files | Strength: Each agent has its own worktree | Gap: Two teammates editing the same file leads to overwrites |
| Coordination | Partial: None at all, which suits independent tasks | Strength: Through the team's lead |
| Suits | Independent tasks, or best-of-N runs | Work you split by file |
How do you clean up the sessions and worktrees?
git worktree remove refuses a worktree with uncommitted changes, which protects an agent's unmerged work:
$ tmux kill-session -t agents
$ for i in 1 2 3 4; do git worktree remove ../myapp-agent-$i; done
fatal: '../myapp-agent-3' contains modified or untracked files, use --force to delete it
$ git worktree list
/private/tmp/tmux-b1/demo/myapp 43944bb [main]
/private/tmp/tmux-b1/demo/myapp-agent-3 43944bb [agent-3]
Merge or commit what you keep, then --force the rest and delete the agent-N branches.
Where does tmux stop being enough?
tmux itself costs almost nothing. With five windows open, our tmux server used 3,936 KB of resident memory and each pane's shell between 1,472 and 2,352 KB (ps -o rss=). What fills the machine is the agents and what they run: installs, builds, test suites, dev servers. Past a handful of agents, the limits are elsewhere:
- Isolation. Worktrees separate files, not ports, databases or anything else your user account can reach. With
--dangerously-skip-permissions, every window can run any command you could; see how to use it safely. - Machine size and uptime. The agents share your RAM and CPU and stop when the lid closes.
- Attention. Flags tell you who is waiting; reviewing the diffs is still you.
If you would rather not script the windows yourself, Claude Squad, which runs on tmux, and other orchestrators are compared in parallel agent orchestrators.
When you hit those, the same tmux habits move to one VM per agent: SSH in, tmux new-session -A -s agent, detach. The docs' long-running sessions guide covers logs, headless runs and what survives a pause. flockvm runs Firecracker microVMs that boot to SSH in about a second and can pause and resume with memory, in France, on one host that holds at most 15 small VMs at once today, across all customers; Claude Code in a VM covers that setup, and coding agent swarms covers running 10 to 20 agents, which flockvm is building toward.
Run your agents in their own microVMs
flockvm gives each coding agent a Firecracker microVM that pauses with its memory and resumes, billed per second. France is live, and you can start with a 7-day free trial.
Start your 7-day free trialCard required. Nothing charged for 7 days.