Home / Blog / How to keep Claude Code running 24/7 (even when your laptop closes)
Your session should not die because your lid closed.

How to keep Claude Code running 24/7 (even when your laptop closes)

You kick off a long Claude Code task, close the laptop, and come back to a dead session. The fix is not a flag or a setting. The process has to live on a machine that never sleeps. Here is every way to do that, from tmux to a $5 VPS to fully managed.

Hivra team15 July 20269 min read

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.

bash
# Start a named session and launch Claude Code inside it tmux new -s claude claude # Detach without killing anything: press Ctrl+b, then d # Later, from any connection: tmux attach -t claude # See what is running tmux ls

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:

bash
screen -S claude # start # Detach: Ctrl+a, then d screen -r claude # reattach

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:

bash
nohup claude -p "run the test suite, fix any failures, and commit" > run.log 2>&1 & # Check on it later tail -f run.log

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:

bash
# 1. SSH into the fresh box ssh root@your-vps-ip # 2. Install Node.js (Claude Code needs it), then the CLI curl -fsSL https://deb.nodesource.com/setup_22.x | bash - apt-get install -y nodejs npm install -g @anthropic-ai/claude-code # 3. Authenticate (run claude once and follow the login flow) claude # 4. Run it inside tmux so it survives your disconnects tmux new -s claude claude

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 + tmuxHivra managed
Cash cost$5-10/mo$0 free tier, $9.99/mo Pro for always-on
Setup time1-2 hours~5 minutes
Survives laptop sleepYesYes
InterfaceSSH terminal onlyBrowser: chat, terminal, files, skills
Agent browser automationYou install and maintain itIncluded on the Claude Code box
Updates and patchingYouHandled
Server securityYouHandled
Control over the boxTotal (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 -p on 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.
Common questions

Does tmux keep Claude Code running when I close my laptop?

No. tmux protects the session from disconnects and closed terminal windows, but when your laptop sleeps, every process on it is suspended, tmux included. tmux only helps on a machine that stays awake: a desktop, home server, or VPS.

Can I run Claude Code on a VPS?

Yes. Install Node.js, install the CLI with npm install -g @anthropic-ai/claude-code, authenticate, and run it inside tmux so it survives SSH drops. A small $5-10/month VPS is enough for the CLI itself.

How much does it cost to run Claude Code 24/7?

DIY: $5-10/month for a small VPS, plus your setup and maintenance time. Managed on Hivra: Claude Code launches on the free tier, and the Pro plan at $9.99/month keeps it always-on with browser automation. Your Claude usage bills through your own Anthropic account either way.

Do I need an API key to run Claude Code in the cloud?

On Hivra, no separate key setup is required for Claude Code: you sign in with your own Anthropic account inside the box after launch, the same login flow as on your laptop. Hivra never sees or stores those credentials.

Does Hivra modify Claude Code?

No. It is the official Claude Code CLI from Anthropic, running unmodified on a private VM. The chat, terminal, files, skills, and browser tabs are a convenience layer around the standard CLI.

What happens to a running task if my SSH connection drops?

If Claude Code is running inside tmux or screen on the remote machine, nothing. The session keeps working and you reattach with tmux attach -t claude. If it is running bare in the SSH shell, the disconnect sends SIGHUP and the task dies.

Deploy in 5 minutes.

7-day money-back guarantee. BYO AI key. From $9.99/mo.

Start Now
Related reading
How to run Codex 24/7 in the cloudBest VPS for Hermes Agent in 2026How much does it cost to run an AI agent?Hermes Agent scheduled tasksFeature: Browser automation