Here is a thing that surprises people: Claude Code does almost none of its thinking on your machine. The model runs in Anthropic's data centre. Your laptop holds the orchestration loop, your files, and a terminal.

So why does closing the lid kill it?

The short answer is SIGHUP

When you run a command in a terminal, that process is a child of your shell, and your shell is attached to a terminal device. When the terminal goes away โ€” you close the tab, the SSH connection drops, the laptop suspends โ€” the kernel sends SIGHUP ("hang up") to the process group. The default action for SIGHUP is to terminate.

The name is literal. It dates from when terminals were physical teletypes on the end of a phone line, and "hang up" meant someone put the receiver down. Half a century later, your AI coding agent dies for the same reason.

Why the usual escapes are not enough

You have probably reached for one of these:

  • nohup command & โ€” ignores SIGHUP, so the process survives. But you have also thrown away the terminal. You cannot see the output, and you certainly cannot type a reply when the agent asks a question.
  • A persistent session on a server โ€” the actual answer, covered below.
  • Caffeinate / "prevent sleep" โ€” treats the symptom. Your laptop still has to stay open, awake and on the same network.

The distinction that matters for an interactive agent is that you need the process to survive and stay reachable. nohup gives you the first and destroys the second.

What a persistent session actually does

A persistent session puts a long-lived process on the machine and makes your shell a child of that, rather than a child of your SSH connection or your terminal emulator. What you are looking at is a viewer onto it.

Pull the network cable and the viewer dies. The session does not notice or care. Your agent keeps running, keeps writing files, keeps working through the task. Reconnect, and a new viewer attaches to the same session and redraws the screen.

This is why the fix feels almost too simple. You are not making the process resilient. You are moving its parent.

The one thing it does not survive

A reboot. A live session lives in memory; if the machine restarts, it is gone. Layouts can be saved and restored, but a running process cannot be resurrected.

In practice this matters less than it sounds, because the durable artefact is your filesystem. Agents work by editing files. If the machine reboots you lose the in-flight conversation, not the work.

So what is the actual fix?

Two options, and they differ in effort rather than in kind:

  1. Run the agent on a server you keep. A small VPS, SSH in, start a persistent session, run your agent, detach. This works, costs a few euros a month, and takes an evening to set up properly.
  2. Use something that does it for you. Which is, transparently, what we sell. The mechanism underneath is the same โ€” there is no secret sauce, just a session that outlives you and a machine that stays on.

If you want to do it yourself, we wrote the full guide: running Claude Code on a VPS.

The mental model worth keeping

Your laptop is a viewer, not a host. Once you internalise that, the whole category of "my session died" problems collapses into one question: is the process a child of something that survives me?