Keep Claude Code running after an SSH disconnect

Why the session dies, the minimal tmux workflow, how to resume, and what to check before you walk away.

You start Claude Code over SSH, give it a long task, close the laptop, and the session is gone: the SSH connection dropped, the shell got a hangup signal, and the process went with it. The fix is not a Claude Code setting. Run the session inside a terminal multiplexer on the server, so it keeps running when you are not connected. This guide shows the minimal tmux setup, how to get a conversation back after a disconnect or reboot, and the safety limit that matters more once the session runs unattended.

Why the session dies

An interactive claude process is a child of your SSH login shell. When the connection ends, the shell is closed and its children receive a hangup. A multiplexer such as tmux runs as its own server process on the machine, independent of your login, and your terminal is only a window onto it.

The minimal tmux workflow

tmux new -s claude-work        # start a named session
cd /srv/project && claude       # work as usual inside it
# detach: press Ctrl-b, then d
tmux ls                        # list sessions
tmux attach -t claude-work     # come back, from any SSH connection

Detaching leaves Claude Code running. If your connection drops, the session stays alive and tmux attach brings you back to exactly the screen you left, including a permission prompt that is waiting for an answer.

Get the conversation back when the process is gone

If the process did end (reboot, crash, a killed tmux server), the conversation is not lost. Claude Code stores transcripts per project directory and can continue them:

Resuming restores the conversation, not the running state: a build that was in progress or a shell variable you set is gone. Say what was happening and let Claude check the current state of the files.

Surviving a reboot

tmux itself does not survive a reboot. Two options: use a plugin that saves and restores tmux sessions (tmux-resurrect and tmux-continuum are the common ones), or accept that after a reboot you start a new tmux session and run claude --continue in the project directory. For a server that reboots rarely, the second one is enough and has no extra moving parts.

Newer option: background sessions

Current versions of the CLI have a --bg flag that starts a session in the background and prints an ID; claude attach, claude logs and claude stop take that ID, and claude agents lists them. Check claude --help on your version, since this area changes quickly. tmux still works everywhere and needs nothing from Claude Code.

The risk of a session you cannot see

A detached session works while you are not looking, which is the point and also the danger. Before you detach from a long task:

A short checklist

The handbook covers running Claude Code on a server long term: sessions, alerts, backups and rules for what the agent may never do: Pocket Server.