aq.dev / guides / keep-claude-code-running-after-closing-laptop

How to Keep Claude Code Running After You Close Your Laptop

Claude Code keeps working after you close your laptop when the claude process runs on a machine that stays awake. Two setups do that: a tmux session on a remote host you reach over SSH, and a Claude Code cloud session on Anthropic's infrastructure. Remote Control alone does not move execution, because the session keeps running on the original machine, which has to stay on. Locking the screen, sleeping the laptop, losing an SSH connection, closing the terminal and restarting the host are five different events with different outcomes, covered below.

Short answer: locking your screen does not stop Claude Code by itself. Sleep, which closing the lid often triggers, pauses Claude Code running on the laptop, and shutting the laptop down ends it. An SSH disconnect can end Claude Code on a remote host unless it runs inside tmux. A cloud session runs on Anthropic's infrastructure, so closing the browser tab, the lid or the whole laptop leaves it running.

AQ is a multiplayer workspace where Claude Code and other coding agents run in persistent sessions on a team-controlled or AQ-managed always-on cloud machine, so work keeps running after you close your laptop and reopens from any browser or phone. Always-on cloud machines and team sharing are on the AQ Pro plan, while Free runs agents on your own Mac while it stays awake; see AQ pricing for the machine options.

What you doClaude Code in a laptop terminalOver SSH, without tmuxIn tmux on a remote hostCloud session at claude.ai/code
Lock the screenKeeps running, unless power settings then put the laptop to sleepKeeps running while the laptop stays awake and connectedKeeps runningKeeps running
Sleep or close the lidPauses until the laptop wakes, if closing the lid triggers sleepCan end once the server detects the dropped connectionKeeps runningKeeps running
Shut down the laptopEnds; resume the saved conversation laterCan end once the server detects the dropped connectionKeeps runningKeeps running
Close the terminal window or browser tabCan end with the terminalCan end with the connectionKeeps runningKeeps running
Lose the SSH connectionDoes not applyCan endKeeps runningDoes not apply

Sources: sleep pausing user processes, the systemd-sleep documentation (macOS and Windows manage sleep their own way); SSH disconnects, Anthropic's Remote Control documentation, which says to start claude inside tmux or screen to keep it running after you disconnect from SSH, and the Bash manual on SIGHUP; tmux, the tmux wiki; cloud sessions, Anthropic's cloud-session documentation. The tmux column assumes the remote host itself stays on; a host restart ends the session. A cloud session stops after a period of inactivity, covered in cloud sessions and Remote Control.

What happens when you lock, sleep or disconnect

  • Screen lock. Locking the screen changes what the display shows. It does not stop processes by itself. Your power settings decide whether the machine also sleeps after a timeout.
  • Sleep (suspend). Local work pauses during system suspend. On Linux systems running systemd, the sleep services freeze user.slice by default, preventing user-session processes from executing during sleep (systemd-sleep documentation). Sleep itself does not mean the process received SIGHUP or exited. macOS and Windows have their own power management. Whether closing the lid triggers sleep depends on the operating system, power source and settings; a laptop can stay awake with the lid closed.
  • SSH disconnect. When the server detects that an interactive SSH connection has ended, the remote terminal hangs up. The shell and foreground programs can exit as a result. tmux gives those programs a separate terminal on the host, allowing them to continue after the SSH client disconnects.
  • Terminal close. Closing a terminal window can end the shell and programs attached to it. Programs inside tmux can continue if the host stays awake and the tmux server remains running.
  • Host restart. A reboot or shutdown ends every process on the host, including the tmux server and anything inside it. tmux does not carry a running process across a restart.

Will Claude keep running if I close my laptop lid?

Usually not, when Claude Code runs on that laptop. Closing the lid normally puts the laptop to sleep, and sleep suspends the local claude process until the laptop wakes. Claude keeps working with the lid closed only when the laptop stays awake, as covered in keeping a laptop awake with the lid closed, or when the session runs on another machine, such as a remote host in tmux, a cloud session or an always-on AQ machine. The Claude desktop app's Keep computer awake setting does not cover the lid: Anthropic's scheduled tasks documentation says it prevents idle sleep and that closing the laptop lid still puts the computer to sleep.

Does Claude Code stop when I disconnect from SSH?

It can. When the server notices the connection is gone, it hangs up the remote terminal, and the shell passes that hangup on to the programs it started, so claude exits. Start Claude Code inside tmux on the remote host before you disconnect and it keeps running; the steps are in running Claude Code in tmux on a remote host.

Can I close the browser tab while Claude is working?

For a Claude Code cloud session, yes. The session runs on an Anthropic-managed VM, and the tab is only a view of it, so you can reopen it at claude.ai/code or check on it from the Claude mobile app. For Remote Control, the browser is also a view, but the session still runs on your own machine, which has to stay on. The cloud sessions guide covers how long an idle session lasts.

Can I shut down my computer while Claude Code runs?

Only when Claude Code runs somewhere else. Shutting down ends every process on that computer, including a local claude session and any tmux server on it. A tmux session on a remote host or a cloud session keeps going while your computer is off. For agents that work around the clock, see always-on coding agents.

Related guides cover Codex, Cursor CLI, and Muse Code.

Keep a laptop awake with the lid closed

These settings keep a session on the laptop itself alive. They do nothing for a session that already runs elsewhere, and they come with costs: a closed laptop that keeps working runs warm, especially inside a bag, drains the battery fast when unplugged, can drop Wi-Fi when the network changes or the signal fades, and still restarts for operating system updates you have scheduled. Undo each change when you no longer need it.

macOS

  • Closed-display mode. Apple's supported way to use a closed MacBook is with an external display: Apple's external display guide says a Mac laptop with a closed lid needs to be connected to power and using an external keyboard and mouse.
  • caffeinate. The caffeinate man page (also man caffeinate on your Mac) lists -i to prevent idle sleep, -d to keep the display awake, and -s to prevent system sleep, which it says is valid only while the Mac runs on AC power. caffeinate -s claude holds that assertion for as long as Claude Code runs, and caffeinate -s -w <pid> holds it until the process with that ID exits. The man page does not say that any flag stops a closed lid from putting the Mac to sleep, so open the lid or use closed-display mode for a session that must keep running.
  • Check it. Run pmset -g assertions; the pmset man page describes it as a summary of the power assertions that may prevent system or display sleep.

Windows

  1. Open Control Panel > Hardware and Sound > Power Options > Choose what closing the lid does.
  2. Set When I close the lid to Do nothing under Plugged in. Leaving On battery at Sleep keeps an unplugged laptop from running hot in a bag.
  3. From an administrator terminal, the same setting is powercfg /setacvalueindex SCHEME_CURRENT SUB_BUTTONS LIDACTION 0 followed by powercfg /setactive SCHEME_CURRENT. Use /setdcvalueindex for battery power, and powercfg /aliases to confirm the alias names on your machine.

Microsoft's lid switch close action reference lists the LIDACTION values: 0 Do nothing, 1 Sleep, 2 Hibernate, 3 Shut down. The powercfg command-line reference covers /setacvalueindex, /setdcvalueindex and /setactive.

Linux with systemd

systemd-logind decides what the lid switch does. Per the logind.conf documentation, HandleLidSwitch= defaults to suspend, HandleLidSwitchExternalPower= applies while the laptop is on external power, and HandleLidSwitchDocked= applies when the laptop is docked or more than one display is connected. To stay awake with the lid closed while plugged in, add a drop-in file, which the documentation recommends over editing logind.conf itself:

# /etc/systemd/logind.conf.d/lid.conf
[Login]
HandleLidSwitchExternalPower=ignore

Reboot for the change to apply. Add HandleLidSwitch=ignore only if the laptop should also stay awake on battery. Desktop environments can take over lid handling with a handle-lid-switch inhibitor lock, in which case logind takes no action (systemd-inhibit documentation); if the laptop still sleeps, check your desktop's own power settings and run systemd-inhibit --list.

Where each setup executes

SetupWhere Claude Code executesAfter your laptop closes or disconnectsWhat the host must doRecovery
claude in a laptop terminalThe laptopPauses during sleep; may exit on terminal closeStay awake with the terminal openCheck the process after wake; use claude --continue if it ended
Remote ControlThe original machineWork continues while the original machine and process remain runningStay awake and onlineReconnect automatically when online; use /remote-control if needed
Remote tmux over SSHThe remote hostWork can continue with no SSH client attachedKeep the host, tmux and Claude runningtmux attach; after restart, create a session and resume saved history
Anthropic-hosted cloud sessionAnthropic-managed VMContinues after laptop closureEnvironment must remain active; usage limits applyReopen at claude.ai/code; expiry recovery uses a fresh VM
AQ FreeYour own Mac, with the AQ Mac appRuns while your Mac is awake; it pauses when the Mac sleepsYou manage your Mac's sleep settingsReopen the work item; resume saved history if the process ended
AQ ProYour cloud VM or a dedicated always-on AQ-managed VMTerminal sessions run on that VMKeep the host and processes running; restarts end processesReopen the work item; after restart, resume saved history

Run Claude Code in tmux on a remote host

You need a Linux host you can SSH into with tmux installed and Claude Code signed in. Running Claude Code on a cloud VM covers building that host.

ssh dev-box
tmux new -s auth-fix
claude

# Detach with Ctrl-b then d. Close the laptop.
# Later, from any machine:
ssh dev-box
tmux attach -t auth-fix

The tmux wiki describes how programs inside tmux can keep running in the background after detachment and be reattached to a different terminal. The host must stay awake.

A check you can run first

Run this on your remote host before starting Claude. It starts a harmless counter in a disposable tmux server, using a unique socket name, an empty tmux configuration and a scratch directory. It needs no credentials.

D=$(mktemp -d /tmp/keepcheck.XXXXXXXX) || exit 1
S="keepcheck-$(basename "$D")"
cat > "$D/counter.sh" <<'EOF'
#!/bin/sh
n=0
while true; do n=$((n+1)); echo "$n $(date -u +%H:%M:%S)" >> "$1/counter.log"; sleep 1; done
EOF
chmod +x "$D/counter.sh"
tmux -L "$S" -f /dev/null new-session -d -s check "$D/counter.sh $D"
sleep 3; tail -1 "$D/counter.log"
tmux -L "$S" list-clients    # prints nothing: no client is attached
sleep 4; tail -1 "$D/counter.log"
tmux -L "$S" kill-server     # stop only this disposable server
rm -rf "$D"

Expected output looks like 3 03:12:56 followed by 7 03:13:00: the second count is higher and its timestamp is later. Exact counts depend on timing. list-clients prints nothing, confirming that the counter advanced with no attached client.

Our check on 1 November 2026 used tmux 3.4 on a Linux 7.0 cloud VM. We observed those counts with an empty client list; stopping the disposable server ended the counter and the log stopped advancing. This verifies detached execution on that test host only. It was not a laptop-sleep experiment or an AQ or Claude Code run. Our attempted interactive reattachment exited immediately, so we did not verify that step.

Reattach a living process, or resume a saved conversation

After reconnecting over SSH, run tmux ls and attach to the named session if it still exists. tmux attach -t auth-fix reconnects to that session's terminal, scrollback and any process still running there. If Claude has exited, run claude --continue from the same project directory for the latest conversation, or claude --resume to choose one from that machine's saved history. Check files, test results and any background processes before rerunning commands. Loading history does not recreate process memory or restart a test suite or dev server.

The tmux-resurrect plugin saves session, window and pane layout and working directories for restoration after a restart. It relaunches programs on its configured list, which defaults to selected editors, viewers and terminal tools such as vim and htop. It cannot restore an in-flight Claude process's memory. Its program-restoration documentation warns that the :all: setting can replay commands against the wrong target; leave it off. After a host restart, create a session and resume saved conversation history.

Connect through mosh or a tunnel

mosh supports interactive terminal connections across IP changes and temporary connection loss; it requires a network that allows its UDP traffic. A tunnel provides a route to a host. With either connection method, the execution host must stay awake, and tmux lets you return to the terminal session later.

Cloud sessions and Remote Control

According to Anthropic's cloud-session documentation, a cloud session keeps running after you close your laptop. Start one at claude.ai/code, from the Code tab in the Claude mobile app, or from a terminal with claude --cloud "task". Your account needs cloud-session access, and usage limits still apply. The cloud sessions guide covers setup and limits.

Three caveats matter for keeping work running:

  • Cloud sessions stop after a period of inactivity and the VM is reclaimed. Reopening the session restores the conversation history on a fresh VM. Shell commands, subagents and scheduled tasks that were still running are not restored.
  • A session waiting for you to approve an MCP connector tool call counts as inactive and can expire during the wait.
  • Handoff from the CLI goes one way. claude --teleport pulls a cloud session into your terminal, and you cannot push an existing terminal session to the cloud from the CLI.

A usage limit is not necessarily a final stop. Anthropic's errors and usage-limit documentation says an open interactive session signed in with a claude.ai subscription can wait and continue the interrupted task shortly after the reset. Disable automatic continuation on each surface you use before leaving work unattended; the controls are listed below.

Remote Control connects claude.ai/code or the Claude mobile app to a session on the original machine. That machine must stay on with the claude process running. If that machine sleeps, work pauses, and Remote Control reconnects automatically once the machine is online again. You can use Remote Control to steer a session on an awake desktop or remote host from your phone. See running Claude Code from your phone for phone setups and managing Claude Code sessions across a team for shared hosts.

Does quitting or restarting the Claude desktop app stop a Claude Code session?

It depends on where the session runs. A cloud session keeps going: the Claude Code Desktop documentation says cloud sessions continue even if you close the app or shut down your computer. An SSH session in Desktop can keep running on the remote machine after you quit, on recent versions of Desktop, though the same page warns that its sign-in can expire while Desktop is closed, and that you can lose the running task when the session reopens unless Desktop can rejoin its process. For a local session, the Desktop documentation does not say what happens when you quit or restart the app. The Remote Control documentation says quitting the Desktop app that runs a session takes that session offline. The safe check: start a short task, quit and reopen Desktop, and see whether it finished. Before a long local task, leave the app open and the computer awake.

Does Remote Control work when my laptop is closed?

Only while the laptop stays awake. Anthropic's Remote Control documentation says your computer has to stay on and the claude process has to keep running, because the web and mobile apps are a window into that local session. If the laptop sleeps when the lid closes, work pauses, and Claude Code reconnects when the machine comes back online. To keep a session reachable from your phone with the laptop shut, run it on an awake remote host or in a cloud session, or keep the laptop awake as described in keeping a laptop awake with the lid closed.

Guardrails for unattended work

An unattended agent can read repository content and run commands with the permissions and credentials available on its host. tmux provides no permission, network or secret boundary. Git worktrees separate files into directories but provide no sandbox against code execution. Even on an awake host, work can stop for an approval prompt, a usage limit, a network failure, an expired login or environment, or a restart. An awake host also does not guarantee that work stays stopped at a usage limit.

Turn off automatic continuation on every surface you use

These controls are independent. Disabling one surface's setting does not disable the others.

  1. Terminal CLI. Open /config and turn off Continue automatically at usage limit.
  2. Desktop app. In the Code tab, clear Auto-continue when limits reset on the session-limit card. The weekly-limit card does not have this checkbox.
  3. Claude Code Projects. Turn off Project settings > General > Auto-continue when usage limits reset. Anthropic's Projects documentation says this setting is on by default and applies to the whole project, including its threads and project conversation, not only the thread you are viewing. With it off, send the thread or conversation a message after the reset to continue. Our Claude Code Projects guide covers this project-level default.
  • Start with a task you can verify afterward, on a branch, with non-sensitive test data.
  • Keep approval prompts on for actions you would not want repeated unattended. See permission modes explained.
  • Give each person their own sign-in. Do not share one account's credentials across a team, and do not grant tokens broader than the repository needs.
  • Read the safe agents guide before leaving a run overnight, and overnight coding agent runs for scoping the task.

Where AQ fits

AQ is where teams run Claude Code and other coding agents on an always-on cloud machine (on the AQ Pro plan), so the work keeps going after you close your laptop, lock your screen or lose your connection, and you can reopen the same work item later from a browser or phone. Its terminal sessions run on a machine that belongs to you or your team and stream to the browser, so closing the browser leaves execution on that machine. Work items use separate git worktrees. Workspace sharing controls who can open an item, and driving another person's session requires their permission; see security and isolation for the access boundaries.

On Free, agents run on your own Mac with the AQ Mac app, so they stop when the Mac sleeps; do not plan overnight runs with the lid closed. Pro lets you connect VMs from your own cloud or use a dedicated always-on AQ-managed VM. A host restart still ends running processes; resuming a saved conversation does not restore a command that was still running. If you need team access while your laptop is unavailable, compare the machine options on the pricing page, then run the short tmux check above on your chosen host before leaving a task unattended.

Frequently asked questions

Does Claude Code keep running if I close my laptop?

Claude Code pauses if it runs on the laptop and the laptop sleeps. Remote tmux and cloud sessions can keep working while their execution host stays awake and the session remains valid. A closed lid does not always trigger sleep: check your operating system and power settings. On AQ Pro, Claude Code runs on an always-on cloud machine, so it keeps working with your laptop closed and you reopen the work item from a browser or phone.

How do I stop Claude Code from automatically continuing after a usage limit resets?

Turn off each independent setting you use. In the CLI, open /config and disable Continue automatically at usage limit. In Desktop's Code tab, clear Auto-continue when limits reset on the session-limit card; the weekly-limit card has no such checkbox. In a project, turn off Project settings > General > Auto-continue when usage limits reset, which is on by default for the whole project. Disabling one setting does not disable the others. With the Project setting off, send the thread or conversation a message after the reset to continue.

Why does Claude Code stop when I disconnect from SSH?

A detected SSH disconnect hangs up the remote terminal, which can end Claude and other programs attached to it. Start claude inside tmux on the remote host before disconnecting, then use tmux attach to return. The host and tmux server must remain running. A host restart ends the processes.

Does Claude keep running if I lock my computer?

Locking the screen alone does not stop running processes. Your power settings may put the computer to sleep later, which pauses local work. For execution while the laptop is unavailable, choose an awake remote host with tmux or a cloud session.

If I close my laptop, will Remote Control keep Claude Code working?

Remote Control requires the original host to stay awake with the claude process running. If that host is your laptop and it sleeps, work pauses until it wakes. Reconnecting afterward does not imply that work continued during sleep. For execution away from the laptop, start a cloud session or run Claude Code in tmux on a remote host.

How do I get a Claude Code session back after a restart?

Start a new tmux session on the same host and open the project directory. Use claude --continue for the latest saved conversation or claude --resume to select one. Check files and command results before deciding what to rerun: an interrupted command may have made changes before the restart. This requires the host's saved history to remain available. tmux-resurrect can restore layout and relaunch configured programs, but cannot recover a running Claude process's memory.

Can I check on a running Claude Code session from my phone?

Yes, in three ways. Cloud sessions appear in the Claude mobile app. Remote Control shows a session running on your own machine, which must stay on. An SSH client on the phone can attach to tmux on a remote host. The running Claude Code from your phone guide compares them.

If I close my laptop, will Claude still run?

Not if Claude Code runs on that laptop and closing the lid puts it to sleep, which is the default on most laptops. The session pauses and continues when the laptop wakes. To keep it working with the lid closed, run it in tmux on a remote host, in a cloud session, or on an always-on machine, or change the laptop's lid setting so it stays awake while plugged in.

Can the Claude app keep my computer awake?

The Claude desktop app has a Keep computer awake setting in Settings > Desktop app or Settings > This computer > System. Anthropic's documentation says it prevents idle sleep, and that closing the laptop lid still puts the computer to sleep.

If I run a Claude Code session in the Claude app and restart, will everything stop?

A cloud session keeps running when you close or restart the app. An SSH session can keep running on the remote machine, but you can lose the running task when the session reopens unless Desktop can rejoin its process. Anthropic does not document what happens to a local session when the app restarts, so test with a short task first. A restart of the computer itself ends every local process; resume the saved conversation afterward and check what finished.