Tmux and Claude Code, What Survives the Detach
How to use tmux with Claude Code: the tmux.conf it needs, what survives a detach, sleep or reboot, and a hook that flags the agent waiting on you.
To use tmux with Claude Code, run each agent in its own tmux window, add four lines to ~/.tmux.conf so Shift+Enter and notifications work, and detach with Ctrl-b d. The agent keeps running on that machine. What tmux cannot do alone is tell you which agent is waiting on you. Claude Code's hooks fix that.
Updated November 13, 2026 · by the AITerm team
of tmux.conf that Anthropic's docs require before Shift+Enter and desktop notifications work inside tmux
from tmux's silence monitor on a pane that only redraws its title, in our test on tmux 3.4. The truly silent pane got flagged
between our screen-reading status detector passing 150 frames of Claude Code 2.1.226 and a CLI update that muted one of its signals
Key takeaways
- tmux is the right tool when agents run on a remote box: the process outlives your SSH connection and your laptop lid.
- Inside tmux, Claude Code loses Shift+Enter, background notifications and the OSC 7501 status until you configure it, and the status never comes back.
- tmux sees bytes, not agents. Its silence alert misses a waiting agent that keeps redrawing its title.
- Five Claude Code hooks and one shell script put a real "needs you" flag in tmux's window list.
- On a local Mac, background sessions (
claude --bg) or a status-aware workspace replace most reasons to run tmux.
How do you use tmux with Claude Code?
Using tmux with Claude Code means starting each Claude Code session inside a tmux window, so the agent keeps running when you detach or your SSH connection drops. At AITerm, where we build a native macOS workspace for coding agents, the setup we recommend is one window per agent, one git worktree per window, the four tmux.conf lines from Anthropic's docs, and hooks that write each agent's state into tmux's status bar.
Here's the whole thing on the machine that runs the agents, a dev box over SSH or your own Mac:
# one session, one window per agent
tmux new-session -d -s agents -n api -c ~/code/shop
tmux new-window -t agents -n web -c ~/code/shop
# one worktree per agent, so they never edit the same files
tmux send-keys -t agents:api 'claude --worktree api' Enter
tmux send-keys -t agents:web 'claude --worktree web' Enter
tmux attach -t agents
# Ctrl-b d detaches. tmux attach -t agents brings you back.
Claude Code can also build this for you. claude -w feature-auth --tmux creates the worktree and a tmux session for it in one go, per the CLI reference. On iTerm2 it uses native panes instead, unless you pass --tmux=classic. The flag only works with --worktree.
What tmux does better than anything we ship
Honestly, one thing matters more than the rest. A tmux server keeps the process alive. Close the window, lose Wi-Fi on a train, let the SSH session time out: the agent in the pane does not notice and keeps editing files.
AITerm does not do that, and we should say so plainly. When you quit the app, the agents stop. At the next launch every pane reopens with claude --resume and the session's ID, so the conversation comes back, but nothing ran while the app was closed. If your agents live on a Linux box in a closet or a cloud VM, use tmux. Full stop.
The rest is real too. tmux runs on every server you will ever SSH into, it costs nothing, and every pane is scriptable, which no GUI matches. Brian P. Hogan's tip from 2025 still holds: one pane for Claude Code with a big scrollback buffer, one pane for git and the shell next to it.
The tmux.conf Claude Code actually needs
Inside tmux, Shift+Enter submits your prompt instead of adding a newline, and desktop notifications never reach your real terminal. Anthropic's terminal docs list four lines to fix both. We add three of our own: a long history, the mouse, and a window list that shows each agent's state (the hook that feeds it comes later).
# ~/.tmux.conf
# Required by Claude Code: notifications, focus, Shift+Enter
set -g allow-passthrough on
set -g focus-events on
set -s extended-keys on
set -as terminal-features 'xterm*:extkeys'
# Agents print a lot. Applies to new windows only.
set -g history-limit 50000
set -g mouse on
# Show the state the Claude Code hooks write (see below)
set -g window-status-format '#I:#W#{?#{==:#{@claude_state},wait}, #[fg=black#,bg=yellow] needs you #[default],}#{?#{==:#{@claude_state},done}, #[fg=green]done#[default],}'
set -g window-status-current-format '#[bold]#I:#W#{?#{==:#{@claude_state},wait}, #[fg=black#,bg=yellow] needs you #[default],}'
Run tmux source-file ~/.tmux.conf, then restart Claude Code in each pane. For notifications over SSH, also set "preferredNotifChannel" to "iterm2", "kitty" or "ghostty" in ~/.claude/settings.json on the remote machine. In iTerm2, Anthropic suggests entering tmux through tmux -CC, which maps tmux windows to native tabs.
The two gaps config can't close. With this setup, only a pane in the window you are looking at forwards its notification. The others send nothing. And the OSC 7501 status (working, waiting, done) that iTerm2 and kitty now display per tab disappears inside tmux, because Claude Code asks tmux whether it supports the protocol, not your terminal. allow-passthrough does not change that.
What survives the detach?
The short version: the agent survives as long as the machine running it stays awake. Everything else is a detail of where that machine is.
| Setup | Window closed or SSH drops | Your laptop sleeps | The agent's machine reboots |
|---|---|---|---|
| Plain terminal tab | Agent stops | Paused until wake | Stops, claude --continue reopens the chat |
| tmux on a remote box | Keeps working | Keeps working | Stops, tmux-resurrect restores the layout, not Claude Code |
| tmux on your Mac | Keeps working | Paused with the Mac | Stops |
claude --bg on your Mac | Keeps working (supervisor process) | Paused, resumes on wake | Stops, conversation kept on disk |
| AITerm | Quitting the app stops agents | Paused with the Mac | Each pane reopens with claude --resume |
Sources: Claude Code docs (agent view, worktrees), tmux-resurrect README, AITerm source. Read November 13, 2026.
Look at the middle column. On a Mac, tmux and background sessions both pause when the lid closes. Only a machine that stays awake keeps an agent working while you sleep. Anthropic's background sessions are the cheaper answer on a Mac: claude --bg "fix the flaky test" runs under a supervisor process with no terminal at all, and claude agents lists every session with its state.
Where tmux stops: it can't see the agent
tmux multiplexes terminals. It knows a pane printed bytes. It has no idea whether those bytes mean "thinking", "waiting for your yes" or "done an hour ago". It was never built to know. At six agents, though, that is the one question you keep asking.
The obvious trick is monitor-silence: flag a window after N quiet seconds. So we tested it on tmux 3.4, with a silence interval of 4 seconds, one pane printing nothing and one pane writing only a terminal title once per second:
S="tmux -L silencetest -f /dev/null"
$S new-session -d -s t -n quiet 'sleep 60'
$S new-window -d -t t -n title 'while true; do printf "\033]0;spin\007"; sleep 1; done'
$S set-option -g monitor-silence 4
sleep 9; $S list-windows -t t -F '#{window_name} silence=#{window_silence_flag}'
quiet silence=1
title silence=0
A title update counts as activity. Turns out that matters, because in September we caught Claude Code still animating its title spinner while a question dialog sat open, waiting for an answer. To tmux, that agent looks busy. Plugins such as claude-tmux go further and read the pane text, looking for "ctrl+c to interrupt" or a [y/n] prompt. It works until the CLI changes a string.
We learned this the hard way. On August 10 our own status detector read Claude Code's screen, and we checked it on 150 captured frames of version 2.1.226 with no false positive. Three days later, Claude Code 2.1.231 switched its spinner to new glyphs and our "working" signal went silent. We deserved it. Anything that parses an agent's screen is a bet on the next release.
How do you make tmux show which agent needs you?
The reliable way to see which Claude Code session needs you in tmux is to let Claude Code report its state through hooks instead of reading the screen. AITerm, our macOS workspace for coding agents, has worked this way since August 18, 2026: hooks fire on prompt submit, tool use, notification and stop, and write each session's state. In tmux, the same hooks can set a window option that the status bar displays.
Save the script
Six lines in ~/.claude/tmux-state.sh, then chmod +x. Outside tmux it exits quietly.
Wire five hooks
Waiting, working and done, in ~/.claude/settings.json. Hooks inherit $TMUX_PANE from Claude Code.
Reload and test
Source the tmux.conf above, restart the agents, ask one for a command that needs approval and switch windows.
#!/bin/sh
# ~/.claude/tmux-state.sh usage: tmux-state.sh working|wait|done
[ -n "$TMUX_PANE" ] || exit 0
cat >/dev/null # drain the hook's JSON input
tmux set-option -w -t "$TMUX_PANE" @claude_state "$1"
// ~/.claude/settings.json
{
"hooks": {
"PermissionRequest": [{ "hooks": [{ "type": "command", "command": "$HOME/.claude/tmux-state.sh wait" }] }],
"PreToolUse": [{ "matcher": "AskUserQuestion|ExitPlanMode",
"hooks": [{ "type": "command", "command": "$HOME/.claude/tmux-state.sh wait" }] }],
"UserPromptSubmit": [{ "hooks": [{ "type": "command", "command": "$HOME/.claude/tmux-state.sh working" }] }],
"PostToolUse": [{ "hooks": [{ "type": "command", "command": "$HOME/.claude/tmux-state.sh working" }] }],
"Stop": [{ "hooks": [{ "type": "command", "command": "$HOME/.claude/tmux-state.sh done" }] }]
}
}
Why PermissionRequest and not the Notification hook? Claude Code fires Notification for a permission prompt only after about six seconds without a keystroke, and only when you seem away. PermissionRequest fires the moment the prompt appears. We ran the tmux half on tmux 3.4: the window flips to "needs you", then to "done". You see the idea. And yes, this is the same five-event pattern our sidebar runs on, minus the sidebar.
Two more commands earn a place in your muscle memory. tmux capture-pane -p -t agents:api -S -40 prints an agent's screen plus 40 lines of history without attaching. tmux send-keys -t agents:api 'run the tests' Enter types into it from a script. Together, they let a cron job or another agent drive a session.
When to keep tmux, and when to leave it
You're probably thinking a company selling a Mac app would tell you to drop tmux. Fair. Here is the split we would give a friend, our product included.
Agents on a remote box
Keep tmux, add the config and hooks above. Nothing else keeps a process alive through a dropped connection this simply.
One to four sessions on a Mac
Skip tmux. iTerm2 3.7.5 or later shows each session's status per tab, which tmux hides. Our terminal comparison covers the rest.
Long runs you walk away from
claude --bg plus claude agents. No terminal to keep open, states built in.
Many agents, mixed CLIs
Claude Code next to Codex or Gemini CLI, one worktree each: that is what AITerm's sidebar is for. Free for 7 days, no card.
Our take. Running tmux on a local Mac just to split the screen is a habit, not a requirement. It costs you Shift+Enter until you configure it, background notifications and the status protocol for good. Agent teams don't need it either: the default in-process mode works in any terminal, and split panes also run in iTerm2.
Panes solve looking, worktrees solve colliding, and neither tells you who is stuck. That third part is the one to fix first, with hooks in tmux or with anything else that asks the agent instead of guessing. The full parallel setup is in our guide to running multiple AI coding agents, and split-pane teammates are covered in the Claude Code agent teams guide. If you try this config and something breaks, tell us: hello@aiterm.app.
Going further
Sources
- Configure your terminal for Claude Code, Claude Code docs, read November 13, 2026: the four tmux.conf lines, notifications from visible panes only,
preferredNotifChannelover SSH, OSC 7501 status lost inside tmux. - CLI reference, Claude Code docs:
--tmux(requires--worktree, iTerm2 native panes,--tmux=classic),--bg,--teammate-mode. - Hooks reference, Claude Code docs: hook processes inherit the parent environment, PermissionRequest, PreToolUse matchers on AskUserQuestion and ExitPlanMode, Notification timing (about six seconds for permission prompts).
- Manage multiple agents with agent view, Claude Code docs: background sessions, supervisor process, behavior on sleep and reboot.
- Orchestrate teams of Claude Code sessions, Claude Code docs: in-process and split-pane modes,
teammateMode,tmux -CCin iTerm2. - tmux(1) manual page:
monitor-silence,history-limit, user options prefixed with @. - tmux-resurrect, README: restores sessions, panes, layouts and working directories after a restart, and a conservative default list of programs.
- Working with Claude Code, Brian P. Hogan, June 19, 2025: a Claude Code pane with a big scrollback buffer next to a git pane.
- claude-tmux, lib.rs, version 0.4.0 (April 17, 2026): status detection by reading pane content.
- tmux wiki: installation and getting started.
Frequently asked questions
How do I use tmux with Claude Code?
Start a tmux session, open one window per agent and run claude in each, ideally with claude --worktree <name> so every agent gets its own checkout. Add four lines to ~/.tmux.conf (allow-passthrough, focus-events, extended-keys and the extkeys terminal feature) so Shift+Enter and notifications work. Detach with Ctrl-b d and reattach with tmux attach.
Does Claude Code keep running when I detach from tmux?
Yes. Detaching only disconnects your terminal from the tmux server, and Claude Code keeps working in its pane. It stops if the machine running tmux goes to sleep or reboots. On a remote dev box that stays awake, an agent keeps working after your laptop closes or your SSH connection drops.
Why does Shift+Enter submit my prompt in Claude Code inside tmux?
By default tmux does not tell Claude Code that Shift was held, so Shift+Enter arrives as a plain Enter. Add set -s extended-keys on and set -as terminal-features 'xterm*:extkeys' to ~/.tmux.conf, run tmux source-file ~/.tmux.conf, then restart Claude Code. Ctrl+J also inserts a newline in every terminal with no setup.
How do I get Claude Code notifications inside tmux?
Turn on set -g allow-passthrough on in tmux and set preferredNotifChannel to iterm2, kitty or ghostty in ~/.claude/settings.json. Only a pane in the window you are viewing forwards the notification. For background windows, use Claude Code hooks that set a tmux window option and show it in the status bar.
Do Claude Code agent teams need tmux?
No. The default in-process mode runs every teammate inside one terminal. tmux, or iTerm2 with the it2 CLI, is only required for split-pane mode, where each teammate gets its own pane. Set teammateMode to auto to use split panes when you are already inside tmux.
How do I see which Claude Code session needs input in tmux?
tmux cannot tell on its own, because it only sees bytes. Let Claude Code report its state through hooks: PermissionRequest and a PreToolUse matcher on AskUserQuestion mark the window as waiting, UserPromptSubmit and PostToolUse mark it as working, Stop marks it as done. A tmux window-status-format then shows the flag in the window list.
Does a tmux session survive a reboot?
No. A reboot kills the tmux server and every agent in it. The tmux-resurrect plugin restores sessions, windows, panes and working directories, but by default it only restarts a short list of programs such as vim and less, not Claude Code. Reopen each conversation with claude --continue or claude --resume.