Blog

How to keep Claude Code running after you close your laptop

Claude Code runs as an interactive process in your terminal. When that terminal goes away, so does the session. Here is what actually ends it and what keeps it alive.

The RoamAI teamPublished September 9, 2026

What ends a session

Claude Code is a terminal program. It needs a live pseudo-terminal, and it keeps the conversation in memory while it runs. Three things end it: closing the terminal window (the shell sends a hangup signal and the process exits), the network dropping while you are connected to a remote machine over ssh (the ssh session ends and takes the shell with it), and the computer going to sleep (nothing runs on a sleeping CPU, and any network connection it had has timed out by the time it wakes).

What does not end it: losing the conversation. The transcript is written to disk as the session runs, under ~/.claude/projects/, one JSONL file per session. A session that died can usually be resumed. More on that below.

Keep the process alive with tmux

On a machine that stays awake, the standard fix is a terminal multiplexer. tmux keeps the shell and everything in it running after you disconnect, and lets you reattach later from the same or a different terminal.

tmux new -s claude
claude
# detach: press Ctrl-b, then d
# later, from any terminal on that machine:
tmux attach -t claude

This works on any Linux server, and on a Mac as long as the Mac does not sleep. It does not survive a reboot, and it does not tell you when Claude has stopped to ask a question. You have to reattach and look.

Why tmux does not help on a laptop

tmux protects the process from losing its terminal. It cannot protect it from the machine going to sleep, because nothing runs on a sleeping machine. On macOS you can keep a plugged-in laptop awake with the lid closed using caffeinate:

caffeinate -i tmux attach -t claude

That is fine for an evening. It is not a way to work. If a session has to keep going while you are away, it has to be on a machine that stays on.

Put the session on a server

The reliable version: install Claude Code on a Linux server, sign in there, start it inside tmux, and connect over ssh when you want to look. The session then depends on the server's uptime, not on your laptop. Using mosh instead of ssh keeps the connection through IP changes and short network drops, which matters from a phone or on a train.

The cost is that the files Claude edits are on the server, not on the machine in front of you. Running Claude Code on a remote server covers the setup and the file question in detail.

If it already died: resume it

Claude Code saves the transcript as it goes. Run claude --continue in the same directory to pick up the most recent session, or claude --resume to choose one from a list. The model gets the whole conversation back. What it does not get back is anything that only existed in the old process, such as a shell command that was still running.

Resuming a Claude Code session goes through what is and is not restored.

Or let a service hold the session

RoamAI does the server part for you. Sessions run on a hosted machine that stays on, or on a Linux server you connect with one command, and the desktop app shows which sessions are waiting for an answer and sends a push notification when one stops. Files are read and written on the computer running the app, so while that Mac is asleep the session pauses and continues when you open the lid. For work that must continue while you are away, run the session on a connected Linux server. How sessions work in RoamAI.

Sessions that stay up, without the server work

RoamAI runs Claude Code on a hosted machine or on a server you connect, and tells you when a session needs you. Signing up is free. Workspaces are $9 / month.

Get started

← All posts