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:
claude --continue(short-c) continues the most recent conversation in the current directory.claude --resume(short-r) opens a picker, or takes a session ID or name:claude --resume <session-id>.claude --name my-task(short-n) gives a session a display name, so you can find it in the picker later.
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:
- Use a narrow permission mode. Do not leave a session in a mode that skips all permission checks on a machine that also runs production. A prompt that waits for you in tmux is a feature, not a bug.
- Keep your deny rules and hooks active. They apply in tmux like anywhere else; see the guide on blocking dangerous commands with a hook.
- Run it as a dedicated non-root user with only the access the task needs.
- Know what it can spend. A long session can use a lot of tokens. Look at usage when you come back, and prefer a bounded non-interactive run (
claude -pwith a budget cap) for jobs you can describe fully up front. - Name your sessions. With several tmux sessions running,
tmux lswith clear names tells you in a second which one is doing what.
A short checklist
- Start Claude Code inside
tmux new -s <name>, never in a bare SSH shell for long tasks. - Detach with Ctrl-b d; reattach with
tmux attach -t <name>. - After a crash or reboot:
claude --continuein the same directory. - Narrow permission mode, deny rules and hook in place before you walk away.
- Never kill a tmux server without checking which sessions are inside it.