Back to blog

How I Close My Laptop Without Losing My Coding Agent Mid-Run

Thang Doan
Thang Doan

You spawn a coding agent to do a forty-minute task. You close the laptop to grab coffee. You come back, open the lid, and the agent is gone. Not paused. Gone.

Why laptop sleep kills agent runs

Most local agent runs are tied to the terminal process that started them. When the laptop sleeps, the terminal process suspends. When the laptop wakes, sometimes the process resumes. Sometimes it does not. There is no announcement either way.

The agent that was forty minutes into a sixty-minute task is not waiting for you. It is dead, with a half-finished branch, an uncommitted diff, and no decisions log explaining where it stopped.

The cost is not the lost work. The cost is reconstructing the agent state. You read its last commits. You guess at its next step. You spend thirty minutes figuring out what it would have done in five.

The pattern that decouples the agent from the laptop

The agent runs inside a persistent session on a machine that does not sleep when your laptop sleeps. Two ways to set this up.

Option one: the session lives on a desktop or server that is always on. You attach from the laptop. When the laptop sleeps, the session keeps running. When the laptop wakes, you reattach.

Option two: the session lives on the laptop, but in a detached state. You close the lid without killing the session. The OS may still suspend the process on sleep, depending on settings.

Option one is more reliable. Option two is more portable.

The Herdr commands that make this real

Herdr exposes the session as a named object you can attach to and detach from. The session has its own lifetime, separate from any terminal that connects to it.

herdr                     # launch or attach to the persistent session
herdr session list        # see named sessions
herdr session attach X    # reattach to a specific session
herdr --remote host       # attach through SSH to a remote server

The --remote flag is the one that fully decouples. The session lives on the remote machine. The laptop is a thin client. Sleep the laptop, wake the laptop, the session is unchanged.

What this does not solve

A persistent session does not mean the agent cannot fail. It can still hit a quota, still drift, still produce a PR you reject. Persistence gives you the chance to catch those failures. It does not prevent them.

It also does not solve network. SSH from a flaky connection drops the attach. The session keeps running on the remote, but you cannot see it until the connection recovers. For mobile networks, this matters.

Try this

Spawn your next long agent run inside a named session, then close the laptop for ten minutes. If the agent is gone when you come back, your session is tied to the laptop, not to the session layer. That is the bug to fix before your next forty-minute task.

Recommended for you

Enjoyed this article?

Subscribe for new articles. No spam. Unsubscribe anytime.

By subscribing you agree to receive the newsletter. See the Privacy page.