Codeman logocodeman GitHub →

Keep Claude Code running when your laptop sleeps or closes

Updated 2026-09-25

On this pageWhat actually stops a sessionOption 1: keep the laptop awakeOption 2: run it on an always-on machine, inside tmuxHow Codeman handles it

A sleeping laptop suspends every process, so Claude Code stops mid-task and stays stopped until the lid opens again. You can keep the laptop awake while it works, but the durable fix is to run Claude Code inside tmux on a machine that does not sleep (a desktop, a home server or a cloud VM) and reattach to it from the laptop or your phone.

What actually stops a session

Event What happens to claude started in a terminal on your laptop
Laptop sleeps Every process is suspended. Nothing runs until it wakes.
You close the terminal window The process usually ends with the terminal.
An SSH connection drops A claude started directly in that SSH shell usually ends with it.
The machine reboots Everything ends, tmux included.

Claude Code's own features follow the same physics. Its agent view preserves background sessions while the machine sleeps and resumes them on wake, which means no work happens in between. Its automatic continue after a usage limit waits for you to press Enter if the computer slept for more than about 30 minutes across the reset.

Option 1: keep the laptop awake

If the laptop stays open on your desk, preventing idle sleep while Claude works is enough.

On macOS, caffeinate holds a sleep assertion for as long as the command it runs:

caffeinate -i claude      # -i: prevent idle sleep while claude runs
caffeinate -s claude      # -s: prevent system sleep, only while on AC power

On a Linux desktop with systemd:

systemd-inhibit --what=idle:sleep --why="claude is working" claude

These cover idle sleep, not a closed lid in a bag. Closing the lid is handled separately by the operating system; on a Mac, running with the lid closed needs power, an external display and an external keyboard and mouse. And the session still dies with the terminal window or the SSH connection it was started from.

Option 2: run it on an always-on machine, inside tmux

tmux keeps a program running on the machine where it started, independent of any terminal or SSH connection. Put Claude Code on a machine that stays on and run it inside tmux:

ssh you@server
tmux new -s work          # start a named tmux session
cd ~/src/myapp && claude  # run Claude Code inside it
# press Ctrl-b then d to detach; claude keeps running

Close the laptop. The session keeps working on the server. When you are back, from the laptop or a phone SSH client:

ssh you@server -t tmux attach -t work

A few practical points:

If the work is a scheduled job rather than an interactive session, Anthropic also offers cloud routines that run with your computer off.

How Codeman handles it

Codeman is built around option 2. You install it on the always-on machine, and it runs each agent CLI (Claude Code, Codex, Gemini CLI and others) in its own tmux session, streaming the terminals to a browser. Closing the browser tab, losing the network, closing the laptop and even restarting the Codeman server leave the sessions running.

curl -fsSL https://getcodeman.com/install | bash
codeman service install     # systemd user unit on Linux, LaunchAgent on macOS
loginctl enable-linger $USER   # Linux: keep the service running while you are logged out

On macOS a LaunchAgent starts at login, not at boot, so a headless Mac needs a system LaunchDaemon instead; Running As A Service covers both.

Reaching it from the laptop or phone is covered in Remote Access; Tailscale is the recommended route, and codeman tui gives an SSH-friendly dashboard of the same sessions.

What Codeman adds after a reboot: tmux is gone, but a banner offers to rebuild the sessions the reboot destroyed, and their conversations come back (the terminal scrollback does not). Past Claude conversations are also listed under Resume Conversation on the home screen.

If Codeman runs on the laptop itself, it can still keep work going with remote SSH cases: point a case at another host and the agent runs in a tmux server on that host, fronted by a local SSH pane. The laptop can sleep or change networks, the remote session continues, and Codeman reattaches when the connection comes back. See Remote SSH Sessions.

For unattended nights, combine this with auto-resume after a usage limit and push notifications; Keeping Agents Running walks through that setup.