Skip to main content

How I Run Claude Code 24/7 on an Always-On Home Box With tmux

Persistent Claude Code sessions that survive closed laptops and dropped SSH: a one-file tmux script, moving sessions to a new always-on box without losing history, and phone follow-up.

For most of September my Claude Code sessions lived on my NAS. It’s always on, it’s where the files are, and SSH-ing in from anywhere was easy. It was also the weakest machine I own: very little RAM, spinning disks, and a CPU that sat pinned whenever the agent ran a build or a big search.

๐ŸŽฏ Not sure if this will run on your hardware?Use our free Local LLM Hardware Checker โ€” pick your GPU and RAM, see which models will run with real tokens/sec estimates.
Check my hardware โ†’

This week I moved everything to a small, quiet always-on box at home with more RAM and an SSD that draws a few watts at idle, so it’s just as “always on” as the NAS. The move took about ten minutes, and the setup is simple enough that I think it’s the best way to run a coding agent at home. Here’s exactly how it works.

The goal: sessions that never die

Run claude in a normal terminal and the session dies when you close the lid, lose Wi-Fi, or your SSH connection drops. What I wanted instead:

  • One long-running session per project, living on a box that never sleeps.
  • Attach from any machine — laptop, desktop, or phone — and pick up exactly where I left off.
  • Start a session in the background with one command, without opening a terminal window for it.

The answer is old and boring: tmux. tmux keeps a terminal session running on the server whether or not anyone is attached to it.

Advertisement

The whole thing is one shell script

I keep this in ~/.local/bin/cc on the always-on box (make sure that folder is on your PATH). Install tmux first with your package manager, for example sudo apt install tmux or brew install tmux.

#!/bin/sh
# cc [-d] [project] - persistent Claude Code session in tmux.
#   cc            list sessions and projects
#   cc myapp      attach to (or create and attach) the session for myapp
#   cc -d myapp   create it detached in the background

DETACH=0
if [ "${1:-}" = "-d" ]; then DETACH=1; shift; fi

PROJ="${1:-}"
ROOT="${CC_PROJECTS:-$HOME/projects}"

if [ -z "$PROJ" ]; then
  echo "Running sessions:"; tmux ls 2>/dev/null || echo "  (none)"
  echo; echo "Projects in $ROOT:"; ls -1 "$ROOT"
  exit 0
fi

DIR="$ROOT/$PROJ"
mkdir -p "$DIR"
SESS="cc-$PROJ"

if tmux has-session -t "$SESS" 2>/dev/null; then
  [ "$DETACH" = 1 ] && echo "$SESS already running" || exec tmux attach -t "$SESS"
else
  if [ "$DETACH" = 1 ]; then
    tmux new-session -d -s "$SESS" -c "$DIR" "claude; exec $SHELL"
    echo "started $SESS in background"
  else
    exec tmux new-session -s "$SESS" -c "$DIR" "claude; exec $SHELL"
  fi
fi

Day to day that turns into three commands:

cc                      # what's running, what projects exist
cc -d homelab-ops       # start a session in the background
cc homelab-ops          # attach to it (Ctrl+b then d to detach)

The exec $SHELL at the end matters. If Claude Code exits or crashes, the tmux window drops you into a shell in the project folder instead of vanishing, so you can see what happened and restart it.

Moving sessions to a new machine without losing history

The migration was mostly about not losing anything:

  1. Put the project on the new box. My maintenance scripts were already in a git repo, so this was a clone.
  2. Check the old session is idle, then stop it cleanly. I confirmed its last turn had finished and sent a normal kill -TERM rather than -9, so it could exit cleanly.
  3. Copy the history. Claude Code stores each project’s conversations as .jsonl files under ~/.claude/projects/, in a folder named after the project path. I copied them into the matching folder on the new box and compared checksums before deleting anything.
  4. Back up the old config, minus the login token. The whole ~/.claude folder went into a dated archive on the new box. I excluded the credentials file: there’s no reason to copy a live token around.
  5. Uninstall from the old machine. Remove the binary, ~/.local/share/claude, ~/.claude and ~/.claude.json. Deleting the local token doesn’t revoke it on the server, so sign the old device out from your account settings too.

The NAS still does what it’s good at — storage and backups — and the agent reaches it over SSH when it needs to.

Following sessions from your phone

Inside any running session, the /remote-control command connects it to the Claude app, so I can watch progress and answer questions from my phone. Because the session lives in tmux on the always-on box, it keeps running whether or not the phone is connected. I’ll start a long job at my desk, walk away, and approve the next step from wherever I am.

A warning about permission modes

Claude Code can be launched with --dangerously-skip-permissions, so tool calls run without asking. On a box that holds SSH keys to other machines, that’s a real decision, not a default to copy blindly. The flag is named that way for a reason. If you use it:

  • Only on machines you own, running projects you trust.
  • Keep backups of anything the agent can touch. More on that in my guide to letting an AI agent maintain your homelab safely.
  • Give the agent SSH keys for the specific accounts it needs, not root.

If you’re unsure, leave the flag out. The approval prompts are slower, but tmux keeps the session alive while it waits for you.

Why a small always-on box

You can do all of this on any always-on Linux box, mini PC, or small desktop. What matters is that it’s quiet, sips power, and has enough RAM and fast storage that the agent is never the bottleneck. Builds, searches and test runs that crawled on the NAS now finish before I’ve switched windows. If your coding agent lives on your weakest machine, it’s worth moving.

For the guardrails I give an agent that runs around the clock, see 7 Rules for Letting an AI Agent Maintain Your Homelab. If you want to run models locally as well, my local LLM homelab stack covers what stays on.

Written by MustafaEngineer running a 24/7 homelab since 2022. Every guide here is built and tested on my own hardware. No paid placements.

Keep reading