Keep a Claude Code session running after you close the terminal

Agent sessions die with the terminal because they are child processes of your shell. Here is why that happens and how to make a run outlive the window.

Why does closing the terminal kill the agent?

Because the agent is a child process of your shell, not an independent service. When you close the window, the terminal sends SIGHUP to its process group, and everything in that group — your shell, and the agent it spawned — is torn down with it.

This catches people out because the agent feels like a service. It runs for twenty minutes, streams output, holds context, and reports progress. But structurally it is no different from a long grep: it exists because your shell is holding it open.

The same reasoning explains the related failures. Sleeping the laptop suspends the process and drops its connections. Losing Wi-Fi breaks anything the run depended on mid-request. Closing the lid on a train and opening it an hour later does not resume the work, because there was no independent thing left running to resume.

What actually fixes it

The run has to belong to something that outlives the window. There are three common approaches, in increasing order of how much they solve.

A terminal multiplexer. tmux or zellij own the session instead of your terminal emulator. Detach, close the window, reattach later with tmux attach. This solves terminal exit completely and costs nothing, and it is the right answer if you only ever reattach from the same machine.

A remote host. Run the agent on a box that does not sleep — a VPS, a desktop at home, a dev container — over SSH, ideally inside a multiplexer. Now closing the laptop is irrelevant, because the laptop was never where the work was happening.

A daemon with its own client. The session belongs to a background process, and you attach from whichever device you happen to be holding. This is the only one of the three that survives and lets you pick the work up somewhere else.

Where Consortium fits

Consortium takes the third approach. You install the CLI and start agents through it rather than calling them directly:

npm install -g consortium
consortium

Run consortium in place of claude, codex, gemini or whichever agent CLI you use. It wraps the agent rather than replacing it — your existing credentials, settings and project files are used as-is, and the agent executes on your own machine against your own working tree.

The session then runs under a persistent daemon, so it belongs to the daemon rather than to whoever opened the terminal. Closing the window, losing Wi-Fi or sleeping the laptop leaves the run going, and you reattach from desktop, browser or phone. Session content that syncs between your devices is encrypted in transit and at rest; you choose whether Consortium can restore your key or never sees it at all.

The same behaviour applies to every supported agent CLI — Claude Code, Codex, Gemini CLI, Grok, opencode and pi — because the wrapper sits at the CLI boundary rather than integrating with one model provider.

Choosing between them

If you work on one machine and only want to survive closing a window, use tmux. It is already installed, it has no moving parts, and it does that job perfectly.

Reach for something heavier when the constraint is different: when you want to start a run at a desk and check it from a phone, when several people need to see the same session, or when the agent should keep going while the machine you started it from is asleep in a bag. Those are properties a multiplexer was never trying to give you.

Frequently asked

Why does Claude Code stop when I close the terminal?
The agent runs as a child process of your shell. Closing the terminal sends SIGHUP to the process group, so the agent is terminated along with the shell that started it. Nothing has crashed — the process was never independent of the window.
Does a laptop going to sleep end an agent session?
If the agent runs directly in your terminal, yes in effect — the process is suspended and any network connection it held is dropped. If it runs under a persistent daemon on a machine that stays awake, the run continues and you reattach afterwards.
Can I reattach to a running agent session from a phone?
Only if the session belongs to something other than the terminal that started it. A session owned by a multiplexer or a daemon can be attached from elsewhere; one owned by your shell cannot.