Get started free
Guides

How do you keep a coding agent running after you close your laptop?

The short answer

Run the agent somewhere that does not sleep. A terminal multiplexer such as tmux keeps it alive when your SSH connection drops, but not when the machine itself suspends. To survive closing a laptop the agent has to be on a machine that stays awake: a desktop, a home server, a VPS, or a hosted service. Everything else is a workaround.

What is true regardless of what you pick

  • Closing a laptop lid suspends the CPU by default on macOS, Windows and most Linux desktops, which stops the agent process wherever it is running locally.
  • tmux and screen survive a lost SSH connection or a closed terminal window, because the session is owned by a daemon rather than by your terminal. Neither survives the host suspending or rebooting.
  • Preventing sleep (caffeinate on macOS, a power plan change on Windows) keeps a lid-closed laptop awake, at the cost of heat and battery, and only while it has power.
  • An agent that is still running is not the same as an agent you can still see. Reattaching to a session requires being back at a terminal with access to that host.
  • Agents that run unattended need a spend limit and a permission boundary set before they start, because nobody is watching to stop them.

Your options, and where each one stops

ApproachGood forBreaks when
Stop the machine sleepingKeep the laptop awake with the lid shut, using the operating system's own power settings.A run you expect to finish in an hour, on a machine that is plugged in and somewhere ventilated.You need to travel, the battery runs out, or the machine reboots for an update. It also cooks a laptop in a bag.
tmux or screen on the same machineThe agent runs inside a session owned by a background daemon rather than your terminal window.Surviving a dropped SSH connection, a closed terminal, or an accidental window close. This is the right answer to that problem.The host suspends or restarts. The session dies with the machine, so this does not solve the closed laptop at all, which is the most common misunderstanding here.
A second machine you ownA desktop, a spare laptop, a home server or a VPS that stays on, reached over SSH or a tunnel.Long runs, unattended automation, and anything where the code and credentials have to stay on hardware you control.You have no such machine, or you are not willing to operate one. There is real setup and real maintenance.
A hosted agent serviceThe vendor runs the agent on their infrastructure; you start it from a browser and come back later.Getting persistence with nothing to run or maintain, and for checking on work from a phone.The repository or its credentials cannot leave your infrastructure, or the work needs tools and services the host does not offer.

What to actually do

If the problem is a dropped connection, use tmux. If the problem is a closed lid, no session manager will help and the agent has to move to a machine that stays on.

The cheapest version of that is a desktop you already own, reached over SSH. The most convenient version is something that also gives you a way back in from a browser, so checking on the run does not require a terminal.

intentic is built for the second case: the sandbox runs on your own desktop, server or VPS as a Docker container, keeps working while nothing is connected to it, and is reachable again from any device through a private tunnel that dials outward, so no ports are opened. It is free and MIT licensed.

What actually stops the agent

Three different things get confused here, and they have three different fixes. Losing the terminal window kills a foreground process. Losing the SSH connection kills everything attached to that session. Suspending the machine stops all of it regardless.

tmux fixes the first two and does nothing for the third. This is worth being precise about, because the advice to just use tmux is given constantly to people whose actual problem is that they want to close a laptop.

Running unattended safely

An agent working while nobody watches needs its limits set in advance. That means a spending cap, an explicit list of what it may touch, and work that lands somewhere reviewable rather than on the main branch.

The pattern that holds up is that unattended work produces a proposal rather than a result. The agent commits to its own branch and stops, and a person reads the diff before anything merges. Nothing then depends on the agent having been right while unobserved.

  • Set a spend limit before the run, not after.
  • Give the agent its own branch and no push access to the default branch.
  • Keep credentials scoped to the job, so an unattended mistake has a small blast radius.
  • Make sure the run leaves a log you can read afterwards to see what it did.

Getting back to a run in progress

Persistence is only half of it. An agent that kept working but can only be reached from one terminal on one network is still a run you cannot check on from a train.

The useful shape is a process that stays on a machine you own, plus a way in that works from any device without exposing that machine to the internet. Outbound tunnels do this: the machine dials out and holds the connection open, so nothing inbound is ever opened and no port forwarding is involved.

Related questions

Does tmux keep an agent running when I close my laptop?

No. tmux keeps a session alive when your terminal closes or your SSH connection drops, because the session belongs to a background daemon. If the machine itself suspends, the daemon stops with everything else. Closing a laptop lid suspends by default, so the agent stops.

Can I run a coding agent on a VPS?

Yes, and it is the usual answer for work that has to keep going. The agent runs on a machine that never sleeps, and you reach it over SSH or a tunnel. The trade is that credentials and code now live on that server, so it needs the same care as any machine holding your keys.

Can I check on a running agent from my phone?

Only if the agent is somewhere reachable over the network and has an interface that is not a terminal. A tmux session on a desktop technically qualifies if you SSH in from the phone, but in practice this means running the agent behind a web interface on a machine that stays on.

Is it safe to leave an agent working overnight?

It is safe when the limits are set beforehand: a spending cap, credentials scoped to the job, and work that lands on its own branch for review rather than merging itself. Without those, an unattended agent can spend a lot and change a lot before anyone looks.

Read next

Written against the state of the field in 2026-08. This area moves fast. Spot something out of date or wrong? Open an issue and it is fixed in the next build.