blog / , updated
Run a Coding Agent While Your Laptop Sleeps
The question behind "how do I stop my Mac sleeping" is which machine the agent runs on. You can keep that machine awake, or you can run a coding agent while your laptop sleeps by starting it on a machine that never closes its lid. A process on the laptop is on the laptop's side of the lid. A process on a server is not, so the agent keeps working and you read the result when you come back. This tutorial compares the options, then does the server version with qoop: add the server, start the agent there, detach, close the lid, reattach, and read the answer on your phone.
Before you start
- Ssh access to a server (
ssh me@devboxlogs you in), with Claude Code or Codex installed and signed in there. - qoop on your computer (macOS or Linux, Windows only under WSL). It is in early access, so sign up at qoop.si first. Install qoop and start your first agent covers the rest.
- On a Linux server, run
sudo loginctl enable-linger meonce, with your server user instead ofme, so that what runs there outlives your ssh login.
Step 1: Why local agents stop
An agent is a process, and the processes on a sleeping Mac are paused. Anthropic's docs for Claude Code background sessions say this from the other side: sessions are preserved when the machine sleeps, their processes resume on wake, and a session that was mid-response can come back unresponsive until the supervisor restarts it. That is general sleep behavior plus Claude Code's documentation, not a qoop statement.
Remote Control, Anthropic's way to continue a session from a phone, does not change where the process runs. Its docs say Claude keeps running locally and that, if your laptop sleeps, Claude Code reconnects when your machine comes back online.
Detaching is a different thing. ctrl-q leaves the qoop interface while the agents keep working, which protects you from closing a terminal window. It does not protect you from the Mac sleeping, because a local space lives on the Mac. In a remote space the agents keep working through sleep, because they run on the server.
Without qoop: three ways to run a coding agent while your laptop sleeps
Each works. Pick by what you will pay.
- Keep the Mac awake.
caffeinate -i claudeholds an idle-sleep assertion for as long asclauderuns. Apple's manual page lists-ifor idle sleep and-sfor system sleep on AC power only, and says nothing about the lid. Apple's external display troubleshooting page says that with a closed lid and an external display connected, the Mac must be on power with an external keyboard and mouse. That is about driving a display, not a promise of staying awake. The cost: the laptop is still the machine doing the work, so it has to stay on, powered and online. - A cloud session.
claude --cloud "your task"starts a Claude Code session on Anthropic-managed infrastructure, and the docs say cloud sessions persist even if you close your laptop. The cloud machine clones your GitHub remote at your current branch, not your local checkout, so push first. The cost: Claude Code only, and the work runs in an environment you configure there, not on your own machine. - A server and tmux. tmux sessions survive an ssh disconnection or a detach (
C-b d), andtmux attachreattaches. This suits any agent. A plain ssh session without it ends when the connection drops, as keep Claude Code running after an SSH disconnect explains, and the tmux setup for Claude Code goes through the details. The cost is visibility: you learn the state by logging in and looking.
The rest of this post is option 3, minus the visibility problem.
Step 2: Move the work to a remote space
On your computer, add the server once:
qoop remote add devbox me@devbox
qoop calls the ssh already on your computer and reads your ~/.ssh/config, so any server that ssh me@devbox reaches is one qoop reaches. If the server has no qoop, you are asked qoop is not installed on <target>. install qoop <version> there, in ~/.local/bin? [y/N]. Say y.
Once added, the server's spaces appear next to your local ones, named like devbox:api. If the server has no spaces yet, you still see its default space: pick it and open a tab there, which becomes its first tab. Click the + of a devbox: space for a new agent, or press ctrl-a c for a new tab (it asks for a name, and empty keeps the program's own) and type cd into your project and claude or codex at the server's prompt. Whatever you start in a remote space, be it a tab, a split or a new space, runs on the server. Work already running on the laptop stays on the laptop. Start it again here.
Step 3: Detach with ctrl-q
Give the agent a task that takes a few minutes. Then press ctrl-q (ctrl-a d does the same). One of the closing lines of qoop --help on qoop 0.13.2 says what happens:
detach with ctrl-q. the shell keeps running.
You are back in your own shell, and the agent keeps working on the server. Close the lid.
Step 4: Reattach
Open the lid and run qoop. It brings you back to the same space, tab and pane.
If you closed the lid without detaching, the agents on the server keep working. Without a connection, the remote spaces are marked offline after roughly fifteen seconds, and they come back by themselves, tabs intact, within ten seconds of the network returning.
Step 5: Read the result on your phone
Sign the computer in with qoop login. It prints Open <url>, sign in, and enter this code: and a code. Sign in at that page, type the code, confirm the computer's name, and approve at the computer. Then open qoop.si/app on your phone and sign in with the same account. The server shows beside your computers. Agents opens on Priority: needs you, finished, working, idle. Tap one and switch between Chat (the parsed conversation) and Terminal (the live screen).
That route goes through your computer's qoop, so it is not enough while the laptop sleeps. qoop's docs say to pair the server itself to reach it with the Mac off, and a sleeping laptop is best treated as the Mac being off. Pair the server directly:
ssh -t devbox '~/.local/bin/qoop pair'
A qoop session must be running on the server first. Scan the QR code with the qoop app (Android today) and type the six digits it shows into the ssh session; run Claude Code on a remote server has the full steps, and the server setup. Pairing by code and push both need the qoop app, which is Android today. An iPhone uses the browser, which can do neither. The app gets a push when an agent blocks, finishes or fails.
Check it worked
This is the checklist, from the lid's point of view:
| After you close the lid | Local space | Remote space |
|---|---|---|
ctrl-q, Mac stays awake | Agents keep working | Agents keep working |
| Mac sleeps | Paused with the Mac, as any process on a sleeping Mac is | Keeps working on the server |
| You wake the Mac | Resumes if it resumes: Claude Code's docs say a mid-response session can need a restart | If you stayed attached: offline for a moment, then back on its own |
ctrl-a x on a tab | Ends the agent in it | Ends the agent in it |
The last row is the one to watch. ctrl-a x closes a tab. If an agent in it is busy, qoop asks first and only Y goes ahead. Closing a terminal ends what it started.
To test your own setup:
- Run
qoop remote ls. Your server should be listed. - Start an agent in a
devbox:space on a task that takes a few minutes, such as running your test suite and summarizing the failures. - Press
ctrl-qand close the lid for about as long as the task takes. - Open the lid and run
qoop. The tab is where you left it, and a full square on the agent's mark means it finished.ctrl-a Mopens its last answer as a page.
For contrast, run the same task in a local space and close the lid. It should not have moved on when you wake the Mac.
When it does not work
| Symptom | Cause | What to do |
|---|---|---|
| The agent stopped on the server after you detached | Linux server without linger | Run sudo loginctl enable-linger me once, then start the agent again |
| Spaces stay offline | The network is down, or plain ssh me@devbox fails | Get plain ssh working first, since qoop rides on it. Once the link is back the spaces return on their own |
| A local agent made no progress while the lid was shut | It lives on the Mac | Start it in a remote space instead |
| The agent vanished after you closed its tab | ctrl-a x ends the terminal and what it started | Detach with ctrl-q to leave things running |
qoop sleep refuses and names a pane | A tab will not sleep while a command or an agent is working in it | Leave it. This is qoop's own sleep, which ends a tab and keeps it until qoop wake. It is not your laptop's sleep |
| The phone cannot pair from a browser | Pairing by code needs the qoop app (Android today) | Pair from the Android app |
To keep a server's agents running while the lid is shut and read their answers from your phone, sign up at qoop.si.