Keep Claude Code running when your laptop sleeps or SSH drops
The short answer: these are two different problems. A closed terminal or a
dropped SSH connection only ends a session that lives in that terminal, and every
agent amux runs is already independent of it, with nothing to set up. tmux and
claude --bg do that too. A sleeping computer is harder, because nothing runs on it
at all, so keep it awake or run your agents on another computer. amux keeps a
plugged-in Mac awake for you.
Where it goes wrong
You’re working on Tally, a small accounting app. You set an agent going on a long database migration, then close your laptop and head to a meeting. An hour later you open it again, and the agent has done two minutes of work.
Or you’re connected to a server over SSH when the Wi-Fi blinks. The connection drops, and the session goes with it.
Why it happens
There are two separate causes.
The terminal. A session you start by running claude belongs to its terminal,
and ends when it closes. An SSH
connection is a terminal too, so dropping it does the same. What you need is a
session that doesn’t depend on a window.
Sleep. A sleeping computer stops every program on it. The session isn’t gone, and it carries on when the computer wakes, but no work happens in between. What you need is a computer that stays awake.
Fixing the first does nothing for the second, which is why tmux on a laptop still stops when you close the lid.
Without amux
Surviving a closed terminal or dropped SSH
tmux keeps a session running on the computer it started on, whatever happens to your connection:
ssh you@servertmux new -s tallyRun claude inside it. After a drop, connect again and run tmux attach -t tally.
Background sessions need no tmux. Start one with
claude --bg "write the invoices migration", or run /bg in a session you already
have open. A background service runs
it, so it keeps going after your terminal closes, and claude agents shows it again.
These are a research preview.
If a session has already ended, claude --resume picks the conversation back up.
Staying awake
On a Mac, caffeinate keeps the computer awake for as long as a command runs:
caffeinate -i claudeOn Linux, systemd-inhibit does the same job:
systemd-inhibit --what=idle:sleep claudeNeither helps once a laptop’s lid closes, or its battery runs out.
With amux
Each agent amux runs is a process of its own, separate from your terminal and from amux itself. So both halves of the first problem are already solved. Close the terminal, lose your SSH connection or press q to leave the app, and every agent carries on. Even amux updating itself leaves them running.
Run amux again and they’re all there, along with anything you’d typed and not
sent.
For sleep, amux keeps a Mac awake while it’s plugged in and its lid is open, with no command to wrap and nothing to remember. You can turn that off:
amux config set keep_awake falseOn Linux, amux leaves power settings to you, so make sure the computer doesn’t suspend by itself.
That covers a laptop on your desk. A laptop in your bag is asleep whatever you do, so if your agents need to work while you travel, they need another computer. amux makes that a small step, because you work with a paired computer’s agents just as you do with your laptop’s. Run them on a server, or on a desktop at home, and your laptop can go anywhere.
To go further, Running amux on a server covers sleep and starting at login, and How amux works explains why agents outlast amux itself.
Last reviewed on 6 November 2026.
Next: Your laptop is the wrong place for agents to run Run Claude Code on a remote server