Why your Claude Code session dies
Claude Code is an interactive terminal program. It lives inside your shell session. Anything that kills the shell kills the agent mid-task. The three usual killers:
- Laptop sleep. Close the lid and macOS or Windows suspends every process. Claude Code included. Nothing runs until you wake it up.
- SSH disconnect. Running Claude Code on a remote box over SSH? When the connection drops, the shell gets SIGHUP and the CLI dies with it. Flaky wifi is enough.
- Terminal close. Quit the terminal app, or the window crashes, and the child process goes down too.
One thing to get straight before any fix: tmux on your laptop does not survive sleep. tmux protects a session from disconnects and closed windows. It cannot keep a suspended machine working. If the hardware sleeps, everything sleeps. So the real question is where the process runs, not which multiplexer you use. To score a specific setup against these failure modes, run it through the agent survival check.
Fix 1: tmux (or screen) on a machine that stays awake
If you have any always-on machine (a desktop, a home server, a VPS), tmux is the classic answer. It keeps your terminal session alive on that machine even after you disconnect.
Your SSH connection can drop a hundred times. The session keeps working on the server. You reattach and pick up exactly where the agent left off.
Prefer screen? Same idea, older tool:
tmux is the better default in 2026. Panes, better scripting, active development. But screen ships preinstalled on more distros, and for this one job either works.
Fix 2: nohup for one-shot headless runs
You do not always need the interactive session. Claude Code has a headless mode (claude -p) that takes a prompt, runs it, and exits. For fire-and-forget jobs, nohup keeps that run alive after you log out:
nohup detaches the process from your terminal so the logout SIGHUP never reaches it. Good for single tasks. Wrong tool for an ongoing interactive session, because you cannot reattach and steer. For that, use tmux.
Fix 3: the DIY VPS route
No always-on machine at home? Rent one. A small VPS runs $5-10/month and is enough for the CLI itself. The setup:
Detach, close your laptop, go to sleep. The agent keeps working. Reattach from your phone over SSH if you want to check in.
What the DIY route actually costs you beyond the $5-10:
- Setup time. An hour or two if the steps go clean. More if they do not.
- Auth friction. The OAuth login flow on a headless box means copying URLs and tokens between machines.
- Maintenance. OS updates, Node updates, CLI updates, disk filling up with logs. Small jobs, but they land on you at bad times.
- Security. The box is on the public internet with your logged-in agent on it. SSH keys only, firewall on, fail2ban is a good idea. That is your job now.
- No interface. You get a terminal over SSH. No browser view of what the agent is doing, no file browser, nothing on mobile beyond a raw shell.
Fix 4: the managed route
Hivra runs the official Claude Code CLI from Anthropic on a private virtual machine provisioned for you. Nothing forked, nothing rebranded. It is the standard CLI, running unmodified, on a box that never sleeps.
What you get, per the actual product:
- Your own Anthropic login. After launch, you sign in with your own Anthropic account inside the box. Hivra never sees or stores your credentials.
- Browser access to the session. Chat, terminal, files, skills, and browser tabs wrap the standard CLI. Check on a running task from your phone.
- A live self-hosted browser. The Claude Code box ships browser automation, so the agent can drive a real Chrome instance on its own VM.
- No server admin. Provisioning, updates, and the always-on part are handled.
Launch takes about 5 minutes from the Claude Code agent page.
Honest plan note: Claude Code launches on the free tier, but free-tier agents sleep after 4 idle days and the free tier has no browser automation. For true 24/7 always-on, the Pro plan at $9.99/month is the fit. Full details on the pricing page. One more cost question worth settling before you commit: whether your current Claude subscription covers round-the-clock usage. The Claude Code plan calculator does that math.
DIY vs managed: the honest tradeoffs
| DIY VPS + tmux | Hivra managed | |
|---|---|---|
| Cash cost | $5-10/mo | $0 free tier, $9.99/mo Pro for always-on |
| Setup time | 1-2 hours | ~5 minutes |
| Survives laptop sleep | Yes | Yes |
| Interface | SSH terminal only | Browser: chat, terminal, files, skills |
| Agent browser automation | You install and maintain it | Included on the Claude Code box |
| Updates and patching | You | Handled |
| Server security | You | Handled |
| Control over the box | Total (root on your VPS) | Managed VM, resize CPU/RAM in the dashboard |
If you enjoy running servers and want total control, the DIY route is legitimate and cheap. If you want the agent working tonight without owning another Linux box, managed wins on time.
Which fix should you pick?
- You already have an always-on machine: tmux. Done. Costs nothing.
- You need one long task to finish overnight:
nohup claude -pon any machine that stays awake. - You want a permanent 24/7 setup and like sysadmin work: small VPS plus tmux, $5-10/month.
- You want a permanent 24/7 setup without the sysadmin work: run Claude Code on Hivra. Sign in with your own Anthropic account and the box stays up.