Keep the agent running after you put your phone away

tmux is a terminal multiplexer: it keeps a terminal session running on the machine you connect to, rather than inside the connection you came through. For an AI coding agent, that is the difference between surviving and dying. SSH connections drop when a phone locks or a signal goes, and a dropped SSH normally kills the agent's shell.

You put your phone away, the SSH tunnel drops, and the agent dies with it. That is mechanics, not bad luck.

When the connection goes, the kernel closes the pseudo-terminal your login was using. It sends SIGHUP (hangup) to every process attached to it: your shell, and the agent inside it. A process that does not catch that signal on purpose terminates by default, and the kernel throws away whatever was half-finished. SSH was only the path the connection came along. It was never what kept the agent alive.

tmux lets the session live somewhere else

tmux opens a session on the server, and your agent runs inside that session rather than inside the SSH connection that keeps dropping.

The mechanism is a process. The first time you type tmux, it starts a background program called the tmux server, which stays alive under your user account. Sessions belong to that process, and each one gets its pseudo-terminal from it instead of from sshd.

When the connection goes, sshd closes its own pseudo-terminal, and only your tmux client is attached to it. The client exits. The session keeps running.

What is a session, a window, a pane?

People use three nouns for three different things, and only the first one keeps your agent alive.

WordWhat it isWhat it means for an agent
session A named place to work on that machine, holding its own processes The thing that survives. Name it once
window A tab inside a session; most people give each agent one Switch away and it keeps running
pane A split inside a window: agent left, tests right Two things visible on a phone screen

A fourth word: a client is the terminal looking at a session. A session with zero clients is normal. It is detached, still running, and nobody is watching it.

Names matter. The session you made with tmux new -s work is still findable a week later, while an unnamed session is just a number you have to look up.

Is detaching like turning off a television?

Switch a TV off and the picture in your living room is gone. The broadcast never stopped. Turn it back on and you are on the same channel, wherever it has got to by now.

tmux calls those two actions detach and attach: close the window, open it again. Neither one touches what is running on the machine.

The analogy hides one thing, and it works in your favour. A television learns nothing while it sits switched off, but a tmux session keeps its output. Attach an hour later and you can read the hour you missed by scrolling back through it.

Which commands do I type?

Start with four:

tmux new -s work          # make a session named work
claude                    # start the agent inside it
tmux ls                   # list sessions: work: 1 windows
tmux attach -t work       # look at it again, from anywhere

Detach is a key press, not a command. Press Ctrl-b, let go, then press d. That first key is the prefix: tmux takes it, and the next key says what to do. Two more are worth learning:

  • Ctrl-b d detaches. The terminal becomes an ordinary shell again, and the session keeps running.
  • Ctrl-b c makes a new window; Ctrl-b % splits a window into panes.

If the machine answers tmux: command not found, the fix is on the troubleshooting page.

A dropped connection does not interrupt the agent

You lose signal on the train, again in a lift, again when you switch Wi-Fi. Attach to the same tmux session every time and you can drop ten times without interrupting the agent once. It never notices, because it was never living inside your connection.

The three cases people worry about on a phone are one event described three ways:

  • The phone locks. The system suspends the app, the connection comes apart, and nothing reaches the agent. It keeps working.
  • No signal for twenty minutes. The connection dies quietly and the tmux client dies with it. The session stays detached and untouched.
  • You kill the app or swipe it away. A process on the phone is gone, and the session was never inside it. Close a laptop's terminal window and tmux behaves the same way.

Detach does not pause anything. While you are gone the agent keeps reading files, editing them, and spending your quota. That is the point of it, and it is why you answer a prompt that is waiting before you walk off.

Can two devices watch the same session?

Yes, and there is no trick to it. Several clients can attach to one session at the same time. Start the job from your phone in a queue, attach from your laptop at work, and you are looking at the same screen mid-sentence rather than a copy of it.

Keys from either device go to the same program, so only one person types at a time. Attaching moves nothing: the session stays on the machine that made it, which is why your phone and your laptop agree. A session you started by hand in a laptop terminal is there for the app too.

How the app handles these sessions

Agentmux is built on the same split. A disconnect on the phone's side is a detach and nothing more: reconnect and you are back at that session, further along. Type the commands above in its terminal and it is still the same session.

The app takes two chores off your hands. If the machine has no tmux, the app installs it, working out whether your machine uses apt, yum, dnf, pacman, apk, or brew. If an agent sits where the shell can't see it, the app probes that PATH problem. Persistent sessions are in the free single-server tier, so nothing here is paid. The setup page turns it into a checklist.

What tmux does not do

tmux answers one question, whether a process outlives your connection, and leaves the rest alone.

  • A reboot of the server ends every session. They live in the tmux server's memory, so a power cut or an unattended upgrade ends the agent with them. What survives is what reached the disk: files changed, commits made, the branch you were left on. Git is the save file, not tmux.
  • It does not undo a command the agent already ran. tmux keeps the output of that command, but it does not roll the files back.
  • tmux kill-session -t work really does kill it. So does quitting the last window, or the agent crashing. tmux kill-server takes every session with it, and tmux does not ask first.
  • It does not keep the machine awake. A Mac mini that stays on is a different case from a laptop that sleeps when you shut the lid, and a machine that powers off loses the session.

Checking this takes two minutes. SSH in, run tmux new -s work, start an agent, press Ctrl-b then d, close the connection, and run tmux attach -t work. The same screen comes back, further along, with one question waiting for you.

So the agent survives you putting the phone away. One problem left: getting in from outside without opening a port to the whole internet. Tailscale answers that.