Keep coding agents running after you close your laptop
Why Claude Code and Codex pause when your laptop sleeps, when keeping it awake is enough, and how to run agents on a machine that stays on.
The short answer
Claude Code and Codex run on the computer where you start them. If that's your laptop, they pause when it goes to sleep. You can keep a laptop awake, even with the lid closed, but only while it sits on your desk. To keep agents working after you pack up, run them on a machine that stays on. A VM you manage, with the agent in tmux over SSH, can be a cheap solution for people who want full control and are ok maintaining a server. Claude Code and Codex can also run in Anthropic's and OpenAI's clouds, which suit tasks that need only your repository. Boxes.dev runs both agents on full copies of a cloud machine where your app already runs.
Why agents stop when your laptop sleeps
Claude Code and Codex run as programs on the computer where you start them, whether you use the CLI, a desktop app, or an IDE extension. If that computer is your laptop, closing the lid usually puts it to sleep, and the agent pauses with everything else on it. The agent's turn, the tests it started, and your dev server all stop until the laptop wakes.
That's true even of features that seem to run in the background. Remote Control lets you steer a Claude Code session from your phone, but the session runs on your computer, so the work waits until the computer comes back online. Claude Code's background sessions in agent view survive sleep but make no progress while the laptop is asleep. For a Codex scheduled task that uses local files, OpenAI's docs say to keep the computer on and the ChatGPT desktop app running.
So you have two ways to keep an agent working. You can keep the laptop awake, which works while it sits on your desk, or run the agent on a machine that stays on, so it keeps going after you pack up and leave.
Keep your laptop awake
On a Mac, caffeinate keeps the computer from sleeping while a command runs.
For example, to keep the Mac awake until Claude Code exits, start Claude Code
with it:
caffeinate -i claude
The -i flag prevents idle sleep. The -s flag prevents system sleep too,
but only while the Mac is plugged in. In the ChatGPT desktop app, you can turn
on Prevent sleep while running under Settings → General so that local
Codex chats continue while you step away.
Closing the lid still puts a Mac notebook to sleep unless it's in closed-display mode, which Apple supports when the Mac is plugged in and connected to an external display, keyboard, and mouse. To keep a Mac awake with the lid closed and nothing connected, you can use a free app such as Amphetamine from the Mac App Store. Windows and most Linux desktops let you choose what closing the lid does in their power settings.
Don't put a laptop that's kept awake in a backpack or a closed bag. It keeps running your builds and tests with almost no airflow, so the air around it heats up quickly. Apple warns that air temperatures above 95° F (35° C) can permanently damage a battery's capacity, and a laptop that overheats can shut down or, in the worst case, fail.
Keeping a laptop awake works while it sits on your desk, open or closed. When you need to pack it up and leave, run the agent on a machine that stays on. Agents on your laptop also share its CPU, memory, and battery with everything else you're doing.
Run the agent on a machine that stays on
A VM you manage
You can install Claude Code or Codex on a Linux server and run it inside tmux, so it keeps working after you disconnect. An always-on computer at home, such as a desktop you reach over SSH, works the same way. To set up a server:
-
Create an Ubuntu server with your cloud provider, add your SSH key, and allow only SSH through its firewall.
-
Connect over SSH and install the agent. For Claude Code, run the installer:
curl -fsSL https://claude.ai/install.sh | bashFor Codex, install it with npm:
npm install -g @openai/codex -
Clone your repository, then install your app's dependencies, databases, and services.
-
Start a tmux session and run the agent in it:
tmux new -s agent claudeRun
codexinstead ofclaudefor Codex. To sign in to Codex on a server without a browser, first turn on device code login in your ChatGPT security settings. Then runcodex login --device-auth, open the link it shows on another device, and enter the code. -
Detach with Ctrl+B and then D. To return later, connect over SSH and run
tmux attach -t agent.
Running one server can be inexpensive. As of September 2026, a DigitalOcean Basic Droplet with 4 vCPUs and 8 GB of memory costs $48 a month. On AWS, an EC2 c7i.xlarge instance of the same size costs about $130 a month on demand in US East, before storage. Either one costs the same whether or not an agent is working. The agent's usage counts toward your Claude or ChatGPT plan.
The server is yours to maintain, including operating system updates, SSH access, backups, and the credentials you put on it. Agents on one server share its files, credentials, CPU, memory, ports, and databases. A VM fits if you want a server that stays up at the lowest cost, if your agents can share one machine, or if you like running your own server, for example for a personal project. The Claude Code guide covers this setup in more detail.
The agent vendors' clouds
Anthropic and OpenAI can run the agent on their own machines, so a task keeps going after you close your laptop:
- Claude Code cloud sessions run each task in a fresh VM with your GitHub
repository. Start one at claude.ai/code, in the Claude app, or from your
terminal with
claude --cloud "<task>", and check on it from your phone. Routines run Claude Code in the cloud on a schedule, even when your computer is off. - Codex cloud tasks each run in their own workspace, created from a reusable environment that Codex helps you prepare and publish. Local files, running processes, browser sign-ins, and VPN access on your computer don't carry over to a cloud task.
Both suit tasks that need only your repository and the tools the environment installs. See the Claude Code guide for how cloud sessions work, including what happens when one sits idle.
Boxes.dev
Boxes.dev runs Claude Code and Codex on cloud machines that start as copies of your working development environment, so closing your laptop doesn't affect them.
You'll start by setting up your app on a cloud machine called the Template box, with the tools, databases, services, and data it needs. Boxes.dev saves the Template box as a snapshot. Each task then runs on its own devbox: a full, isolated copy of that machine. The agent can start your app, test its changes in a browser, and reproduce bugs against your real services and data, the way an engineer would before shipping. After your message reaches boxes.dev, you can close the desktop app and the laptop, and the agent will keep working.
An agent that's still working keeps its devbox awake. A devbox goes to sleep after about five minutes when no agent is working and nobody is using it. Sleep keeps its files and memory, so dev servers, databases, and terminal sessions pick up where they left off when it wakes. A sleeping devbox doesn't use box-hours.
You'll get a notification on your laptop or phone when an agent replies, fails,
or needs your input, and you can answer from the boxes.dev iOS and Android
apps. For a long Codex task, enter /goal followed by the outcome you want.
Codex will keep working across responses until it reaches the goal or something
stops it, such as a usage limit. You can also start work from Slack, Linear, or
scheduled automations.
As of September 2026, the free trial includes 10 box-hours. Starter costs $19 per user each month, with 40 box-hours and up to four devboxes awake at once. Pro costs $99, with 250 box-hours and up to ten awake. Extra time costs $0.75 per box-hour on Starter and $0.60 on Pro. A box-hour is one default devbox, with 4 vCPUs and 8 GiB of memory, awake for an hour. See Plans, seats, and box-hours.
To try it, connect Claude or Codex, then set up a project from a folder on your laptop or a GitHub repository.
Usage limits still apply
Wherever the agent runs, a long task can stop when you reach your Claude or ChatGPT plan's usage limit, and running several agents at once gets you there faster. Anthropic notes that ten background sessions use your quota roughly ten times as fast as one. Check your remaining usage before you leave a long task running overnight.
How to choose
- The task is short and the laptop is staying on your desk: keep it awake
with
caffeinate, Codex's Prevent sleep while running, or, to close the lid, an app such as Amphetamine. - You want a server that stays up at the lowest cost, or you like running your own server: a VM you manage, with the agent in tmux.
- The task needs only your repository: Claude Code cloud sessions or Codex cloud tasks.
- You want the agent to run and test your full app, and to pick up where it left off when its devbox wakes: Boxes.dev.
Frequently asked questions
Does Claude Code keep running when I close my laptop?
Not by default. Closing the lid usually puts the laptop to sleep, and a local session pauses until it wakes. An app such as Amphetamine can keep a Mac awake with the lid closed, but don't pack the laptop in a bag while it runs. Claude Code keeps working with the lid closed when it runs somewhere else, such as in tmux on a VM, in an Anthropic cloud session, or on a boxes.dev devbox.
How do I run Codex overnight?
Run it somewhere that stays on: a Codex cloud task, a server with Codex in tmux, or a boxes.dev devbox. On boxes.dev, a Codex goal keeps the agent working across responses, and you'll get a notification when it finishes or needs you.
Will my dev server still be running when I come back?
On a server, it will if it runs inside tmux or as a service. A Claude Code cloud session starts a fresh VM when you reopen it after it sits idle, so Claude has to start your services again. A boxes.dev devbox keeps its memory while it sleeps, so your dev server and database pick up where they left off when it wakes.
Sources
- Anthropic: Remote Control, agent view, Use Claude Code in the cloud, common workflows, and setup.
- OpenAI: Codex environments, scheduled tasks, settings, authentication, and the Codex CLI.
- Apple: Use your Mac notebook computer in closed-display mode,
Batteries: maximizing performance,
and the
caffeinatemanual page (man caffeinate). - Amphetamine: Mac App Store listing.
- DigitalOcean: Droplet pricing.
- AWS: EC2 On-Demand pricing.
- Boxes.dev: Sleep, wake, and recover a devbox, Notifications, Keep Codex working toward a goal, Use boxes.dev on your phone, Create an automation, and Plans, seats, and box-hours.
Related
Product names are trademarks of their respective owners.
