Skip to content

Run Claude Code 24/7 at Home and SSH In with Localtonet

Keep Claude Code running on a home machine with tmux and systemd, then reattach over SSH through a Localtonet TCP tunnel with no port forwarding or public IP.

Summary in your language
In this article 16 sections
Home mini PC running a terminal session in tmux next to a router, with a laptop and phone resting nearby
A home machine keeps the Claude Code session running while you are away.
AI Agents · Claude Code 24/7 · Localtonet · 2026

Keep a coding agent working while your laptop sleeps, using hardware you already own

A Claude Code session normally lives only as long as the terminal that started it. Close the laptop lid or drop the SSH connection and the long refactor you left running stops. This guide turns a spare desktop, mini PC, or home server into an always-on agent host. We cover detachable tmux sessions, a systemd user service with login lingering, and power settings that keep the box awake. We then harden SSH and expose only that one local port through a Localtonet TCP tunnel. You can reattach from a laptop or phone with no router port forwarding, no public IP, and no VPN.

🔒 Key-only SSH, dedicated low-privilege agent user 🌐 One TCP tunnel to local port 22, outbound connection only ⚡ Detach, disconnect, reattach: the agent keeps working

Why a Claude Code session stops when you walk away

Claude Code is a terminal program. When you type claude in a shell, the process becomes a child of that shell, and the shell is attached to a terminal: a local terminal window, or a pseudo-terminal created by an SSH connection. When that terminal goes away, the operating system sends a hangup signal to the processes attached to it. Close the terminal window, let your laptop suspend, or lose Wi-Fi long enough for the SSH connection to drop, and the agent receives that hangup and exits. Whatever it was doing, such as running a test suite and fixing failures one by one, ends with it.

Running an agent "24/7" therefore requires three separate things to be true at the same time:

  • The machine stays powered, awake, and online. A suspended computer runs no code. This rules out a laptop that sleeps when you close it, unless you change its power behavior.
  • The agent process survives your disconnection. The agent must run inside something that does not depend on your terminal, such as a tmux or screen session. Ideally that session is started by a supervisor like systemd, so it comes back after a reboot.
  • You can get back in from anywhere. At home, the machine sits behind your router's NAT, often behind carrier-grade NAT as well. Nothing on the internet can reach it directly without port forwarding or a public IP. This is the part most people get stuck on.

The first two are solved with standard Linux tooling that has been stable for many years. The third is where our platform comes in. The Localtonet client on the home machine opens an outbound connection to one of our relay servers. A TCP tunnel then gives you a public host and port that forwards to the machine's local SSH port. No inbound router rules, firewall changes, or public IP address are needed. The tunnel is available only while the client on that device is connected and the tunnel is running, which also gives you a simple off switch.

What this guide is, and is not

We expose a single SSH port through a TCP tunnel. This is not a VPN: the remote device does not join your home network and cannot reach other LAN devices through this tunnel. If you want a private mesh network across your devices, our separate VPN Manager feature covers that use case. For an agent host, one hardened SSH port is usually all you need, and it keeps the attack surface small.

How the pieces fit together

Diagram of a laptop and phone connecting over SSH to a Localtonet endpoint, which tunnels TCP to sshd, tmux, and Claude Code on a home computer
SSH traffic reaches the home machine through an outbound Localtonet TCP tunnel. Claude Code runs inside tmux under systemd.

Before running commands, it helps to see the full chain from your phone to the agent. Each layer has one job, and each can be tested on its own, which makes troubleshooting much easier later.

🖥️ Always-on host A spare desktop, mini PC, or home server running Linux, configured never to suspend. It holds your repositories and runs the agent.
👤 Dedicated agent user A normal account without sudo that owns only the repositories the agent should touch. If the agent runs a bad command, the damage stays inside this account.
🪟 tmux session A terminal multiplexer that owns the agent's terminal. You attach and detach from it; the agent never sees your SSH connection come and go.
♻️ systemd user service plus lingering Starts the tmux session at boot, before anyone logs in, and keeps it running after you log out.
🔑 Hardened OpenSSH server Public-key authentication only, no passwords, no root login, and access limited to the users you name.
🌐 Localtonet TCP tunnel Our client connects outbound to a relay server and forwards a public host and port to 127.0.0.1:22 on the host. Start it when needed; stop or delete it when not.

The connection path is: your SSH client connects to the public host and port assigned by Localtonet. Our relay carries the traffic over the client's outbound connection to the home machine. The Localtonet client hands it to the local SSH server. SSH authenticates you with your key, and you run tmux attach to land back in the agent's session. SSH encrypts your session end to end between your SSH client and the SSH server, independently of the tunnel.

Prerequisites

This guide assumes a Linux host, because tmux, systemd, and OpenSSH behave consistently there. Commands use Debian/Ubuntu package names; on other distributions, substitute your package manager and note where service names differ (we flag those spots). macOS hosts work for the tmux and SSH parts, but systemd does not exist on macOS, so the boot-persistence section does not apply as written.

Requirement Details Why it matters
Host hardware At least 4 GB of RAM, the minimum Anthropic lists for Claude Code; more if you run builds or test suites Memory limits usually bite before CPU when an agent runs tests and tooling
Operating system A Linux distribution with systemd (Debian, Ubuntu, Fedora and similar) Needed for the user service and login lingering steps
Packages tmux (or screen), openssh-server, git, curl Session persistence, remote login, repository access, and the Claude Code installer
Claude access A Claude subscription login or an Anthropic Console API key Claude Code needs to authenticate; usage is billed by Anthropic separately from your hardware
Localtonet account An account, the Localtonet client for your OS, and the device's auth token from the dashboard Creates the TCP tunnel that makes SSH reachable without port forwarding
Client device Any laptop or phone with an SSH client that supports key authentication This is where you reattach from
Local console access A keyboard and monitor, or LAN SSH access, during setup You will change SSH settings, and you need a way back in if something goes wrong
About costs

We do not quote prices in this guide because Claude plans, API rates, VPS pricing, and electricity costs change and vary by region. Check current pricing from Anthropic and any hosting provider you compare against. Our own plan details are on the Localtonet website; not every option is included in every plan.

Prepare the host and a dedicated agent user

Do this part at the machine itself, or over SSH from another computer on the same LAN. We deliberately set everything up locally first and expose it to the internet last.

Install the base packages

sudo apt update
sudo apt install -y tmux openssh-server git curl

On Debian and Ubuntu, installing openssh-server usually starts and enables the SSH service automatically. Confirm it is listening locally:

sudo systemctl status ssh
sudo ss -tlnp | grep ':22'

The service is called ssh on Debian and Ubuntu and sshd on Fedora, RHEL, and Arch. If status ssh reports that the unit does not exist, try sshd.

Create a low-privilege user for the agent

Claude Code can run shell commands on your behalf. Even with careful permission prompts, you should assume that a command you did not intend will run eventually. Running the agent as your personal admin account means that command runs with access to your browser profile, your SSH keys, your password manager files, and sudo. A dedicated account limits the blast radius.

sudo adduser agent

Do not add this user to the sudo or wheel group. If the agent needs extra system packages, install them yourself from your admin account. Check the result:

id agent

The output should list only the user's own group (plus any groups you added intentionally). Switch to the new user for the remaining agent-side steps:

sudo -iu agent

Give the agent scoped repository access

Clone only the repositories the agent should work on into the agent user's home directory, for example ~/code/storefront. For pushing and pulling, avoid copying your personal SSH key or a broad personal access token onto this account. Most Git hosts offer narrower credentials, such as a per-repository deploy key or a fine-grained token restricted to specific repositories and permissions. Create one for this machine, so you can revoke it independently if the machine is lost or compromised.

mkdir -p ~/code
cd ~/code
git clone git@your-git-host:your-org/storefront.git

Replace the remote with your own. A practical pattern is to let the agent work on a branch and push it, then review and merge from your own account. The agent account never needs rights to your protected branches.

Install and sign in to Claude Code

Still as the agent user, install Claude Code with Anthropic's installer script:

curl -fsSL https://claude.ai/install.sh | bash

Open a new shell (or reload your shell profile) so the claude command is on your PATH, then confirm the installation:

claude --version

If the command is not found, read the installer's final output; it prints where the binary was placed and whether you need to adjust PATH. We are not reproducing a fixed path here because it can change between installer versions.

Authenticate without leaking credentials

There are two ways to pay for Claude Code usage: a Claude subscription login or an Anthropic Console API key. For a headless home machine, the subscription login flow is convenient. Run:

claude auth login

It prints a link that you open in a browser on any computer, and gives you a code to paste back into the terminal. The credential is then stored by Claude Code for that user, and no secret passes through your shell history.

If you use an API key instead, follow Anthropic's current documentation for how Claude Code reads it. Whatever the mechanism, apply these rules:

  • Never type the key as part of a command line, such as an inline export with the literal value. It lands in ~/.bash_history and is visible in the process list while the command runs.
  • If you must keep the key in a file, make it readable only by the agent user (chmod 600) and keep it outside any Git repository.
  • Use a key dedicated to this machine so you can revoke it without affecting other projects.

To stop an individual command from being saved in bash history, many setups honor a leading space if HISTCONTROL includes ignorespace. Ubuntu's default .bashrc sets ignoreboth, which includes it. Check with echo $HISTCONTROL rather than assuming.

Background sessions built into Claude Code

Recent Claude Code releases include their own background session mode (a --bg flag, with claude agents to list running sessions). Flags and behavior evolve quickly, so check claude --help on your installed version before relying on them. We use tmux in this guide because it is independent of Claude Code's version. It also works for any other terminal tool you run next to the agent, such as a dev server or a log tail. The two approaches are not mutually exclusive.

Keep sessions alive with tmux and systemd

tmux in two minutes

tmux runs a server process that owns one or more terminal sessions. Your terminal is only a client looking at a session. When you detach, or your SSH connection dies, only the client goes away. The session and everything running in it, including Claude Code, keeps running. As the agent user:

tmux new -A -s agent

The -A flag attaches to a session called agent if it already exists and creates it if not. That makes this one command safe to run every time you log in. Inside the session:

cd ~/code/storefront
claude

Give Claude Code its task. To leave it running, detach with Ctrl+b and then d. You are back in your plain shell, and the agent continues. Useful commands:

Action tmux GNU screen equivalent
Create or attach a named session tmux new -A -s agent screen -DR agent
Detach and leave it running Ctrl+b, then d Ctrl+a, then d
List sessions tmux ls screen -ls
Reattach later tmux attach -t agent screen -r agent
New window in the same session Ctrl+b, then c Ctrl+a, then c
Scroll back through output Ctrl+b, then [ (q to exit) Ctrl+a, then Esc (Esc to exit)

Separate tmux windows are a good fit for a long agent run: window 0 for Claude Code, window 1 for running tests yourself, window 2 for watching logs. All of them survive disconnection together.

Start the tmux session at boot with a systemd user service

tmux alone survives disconnections, but not reboots. After a power cut or a kernel update, the session is gone. A systemd user service, owned by the agent account rather than root, can recreate it automatically.

First, as your admin user, enable lingering for the agent account. Without lingering, a user's systemd instance (and its services) starts only when that user logs in and stops when the last login session ends. With lingering, it starts at boot and keeps running:

sudo loginctl enable-linger agent
loginctl show-user agent --property=Linger

The second command should print Linger=yes. Next, as the agent user, find the tmux binary path, because systemd unit files need absolute paths:

command -v tmux

On Debian and Ubuntu this is typically /usr/bin/tmux. Create the unit file at ~/.config/systemd/user/agent-tmux.service, replacing the tmux path if yours differs:

[Unit]
Description=Persistent tmux session for Claude Code

[Service]
Type=forking
WorkingDirectory=%h/code
ExecStart=/usr/bin/tmux new-session -d -s agent
ExecStop=/usr/bin/tmux kill-session -t agent
Restart=on-failure

[Install]
WantedBy=default.target

%h expands to the user's home directory. new-session -d creates the session detached, so it does not need a terminal. Enable and start it:

mkdir -p ~/.config/systemd/user
systemctl --user daemon-reload
systemctl --user enable --now agent-tmux.service
systemctl --user status agent-tmux.service
tmux ls

If systemctl --user complains that it cannot connect to the bus, you probably switched users with su or sudo -iu in a way that did not create a full login session. Log in as agent directly over SSH (from the LAN at this point) and run the commands there.

Should systemd also start Claude Code automatically?

You could add a line that sends claude into the new session with tmux send-keys. We recommend against auto-starting the agent after a reboot. An unattended restart would launch Claude Code with no task context, and you generally want to decide what it works on next. Let systemd guarantee that the session exists, then attach and start the agent yourself.

Stop the machine from sleeping

The most common reason a "24/7" agent quietly stopped overnight is not a crash; the machine went to sleep. Desktop Linux installs often suspend after a period of inactivity, and remote SSH activity does not always count as activity for the desktop's idle timer.

Linux with systemd

On a dedicated agent host, the simplest reliable option is to disable sleep targets entirely:

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

This prevents the system from entering those states no matter which component requests it. To undo it later, run the same command with unmask. If you use a desktop environment, also set its power settings to never suspend, so it does not keep trying.

If the host is an old laptop, closing the lid triggers suspend through systemd-logind. Edit /etc/systemd/logind.conf and set:

HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore

Then restart logind with sudo systemctl restart systemd-logind. Be aware that this can end an active graphical session, so do it before you start anything important.

macOS hosts

If you run the agent on a Mac, caffeinate -s prevents system sleep while the Mac is on AC power, for as long as the command runs. You can run it in its own tmux window. For a permanent setting on a Mac used as a server, the Energy settings or sudo pmset -c sleep 0 (no system sleep on charger) are alternatives. The systemd section of this guide does not apply to macOS.

BIOS and power-loss behavior

Many desktop and mini PC firmware menus have an option to power on automatically after a power failure, often labeled as an AC power recovery setting. Turning it on, combined with the systemd service and lingering above, means a brief outage leads to an automatic return of the tmux session and the Localtonet client. You will still need to restart the agent's task yourself.

Harden SSH before exposing it

Once the tunnel is running, your SSH port is reachable from the internet. Automated scanners find open SSH ports constantly and try common usernames and passwords. Key-only authentication makes those attempts useless. Do every step in this section on the LAN, and keep a second session open while you change settings so you cannot lock yourself out.

Create and install a key on your laptop

On the laptop (not the home machine), generate a key if you do not already have one, and protect it with a passphrase:

ssh-keygen -t ed25519 -C "laptop-to-agent-host"

Copy the public key to the agent account while password login is still enabled, using the machine's LAN address:

ssh-copy-id agent@192.168.1.50

Replace the address with your host's LAN IP. Test that key login works before going further:

ssh agent@192.168.1.50

If you also want to connect from a phone, generate a key inside the phone's SSH app and append its public key as a new line in /home/agent/.ssh/authorized_keys. One key per device means you can revoke a lost phone by deleting a single line. Our article on the Elio SSH client walks through a mobile SSH workflow if you need one.

Lock down the SSH server

On Debian 12 and recent Ubuntu releases, the main /etc/ssh/sshd_config includes files from /etc/ssh/sshd_config.d/. Check that your config contains an Include /etc/ssh/sshd_config.d/*.conf line; if it does not, put the settings directly in the main file instead. Create /etc/ssh/sshd_config.d/10-hardening.conf:

PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
PermitRootLogin no
AllowUsers agent youradmin
MaxAuthTries 3
LoginGraceTime 30

Replace youradmin with your own admin username, or remove it if you only ever log in as agent. Keep in mind that the agent account has no sudo, so you need some way to do administration. OpenSSH uses the first value it finds for most settings, so if another drop-in file sets PasswordAuthentication yes earlier in alphabetical order, it wins. Check for conflicts with grep -ri passwordauthentication /etc/ssh/.

Validate the syntax, then reload:

sudo sshd -t
sudo systemctl reload ssh

Use sshd instead of ssh as the service name on Fedora, RHEL, or Arch. From the laptop, confirm that password login is now refused:

ssh -o PubkeyAuthentication=no agent@192.168.1.50

You should see Permission denied (publickey) without being offered a password prompt.

Optional: bind SSH to localhost only

Because the Localtonet client runs on the same machine and forwards to 127.0.0.1:22, you can make sshd listen only on the loopback interface by adding ListenAddress 127.0.0.1. SSH is then unreachable from your LAN entirely and only reachable through the tunnel. This is a meaningful reduction in exposure on a shared home network. The trade-off is that you lose direct LAN SSH, and if the tunnel is down you need physical console access. Only do this once everything else works.

Per-IP blocking tools and tunneled traffic

With a forwarding client on the host, incoming SSH connections typically reach sshd from the local client's address rather than from the remote attacker's IP. Host tools that ban by source IP, such as fail2ban, may therefore see every attempt as coming from 127.0.0.1. Banning that address would cut off the tunnel for everyone, including you. Rely on key-only authentication as your primary defense, and check the tunnel settings in your dashboard for any access controls your plan offers.

Verify the host key on first connection

The first time you connect through the tunnel, your SSH client shows the server's key fingerprint and asks you to confirm it. Compare it against the real fingerprint, read on the host itself:

ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub

If the fingerprints match, accept. This confirms you are talking to your own machine and not something in between.

Expose SSH through a Localtonet TCP tunnel

Localtonet console showing a connected TCP tunnel forwarding to 127.0.0.1 port 22 with status OK
The Localtonet console shows the TCP tunnel to local SSH on port 22 as connected.

SSH is a raw TCP protocol, not HTTP, so it needs a TCP tunnel rather than an HTTP tunnel. A TCP tunnel points to a local IP address and port on, or reachable from, the device running our client. For this setup, the target is the SSH server on the same machine: 127.0.0.1, port 22. If you changed sshd's port, use that port instead.

The sequence below follows our standard tunnel workflow. Exact field labels and screens can change between dashboard and client versions, so keep the Localtonet documentation open for the current TCP tunnel page while you work.

1

Install and run the Localtonet client on the home machine

Install our client for your operating system on the agent host itself, the device that can reach 127.0.0.1:22. The client creates the outbound connection to our relay, so it must be running for the tunnel to work.

2

Authenticate the device with its auth token

Copy the device's auth token from your dashboard and use it to sign the client in, as described in our documentation for your OS. Tokens are device-specific; treat yours like a password and never paste it into chat, screenshots, or a repository.

3

Create a TCP tunnel and select the token and relay server

In the dashboard, open the TCP tunnel page, choose the auth token of your home machine, and select an available relay server. Pick from the servers your dashboard currently lists; a nearby region usually feels more responsive for interactive terminal work.

4

Point the tunnel at the local SSH port

Set the local IP to 127.0.0.1 and the local port to 22 (or your custom sshd port). Do not point this tunnel at any other service; one tunnel, one purpose.

5

Start the tunnel and note the public host and port

Creating a tunnel does not start it. Press Start, then copy the public host and port shown for the tunnel. That address is what your laptop and phone connect to.

Keeping the client running after reboots

For the tunnel to come back after a power cut, the Localtonet client has to start again too. Our documentation describes the supported way to run the client for each operating system; follow that rather than an improvised unit file, since the client's command-line options are version-specific. As a stopgap, you can run the client in its own tmux window under your admin account. Note that tmux alone does not survive a reboot unless systemd recreates the session.

Turning the tunnel off

The tunnel lifecycle is a useful security control. While a tunnel is stopped, nothing is listening on its public address. If you only reattach during the workday, stop the tunnel in the dashboard in the evening and start it again when you need it. The agent keeps running in tmux either way; stopping the tunnel only removes your remote path to it. When you retire the setup, delete the tunnel rather than leaving it dormant, and remove the device's token if the machine is no longer used.

Connect and reattach from a laptop or phone

Phone and laptop SSH terminals connected through a Localtonet endpoint and reattached to the same tmux session on a home computer
Any SSH client can reattach to the same running tmux session through the tunnel endpoint.

With the tunnel running, connect from anywhere using the public host and port from the dashboard. The placeholders below stand for those values:

ssh -p PUBLIC_PORT agent@PUBLIC_HOST

Typing that every time gets old, so add an entry to ~/.ssh/config on the laptop:

Host agent-home
    HostName PUBLIC_HOST
    Port PUBLIC_PORT
    User agent
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes
    ServerAliveInterval 30
    ServerAliveCountMax 4

ServerAliveInterval makes the SSH client send small keepalive messages, which helps idle connections survive aggressive NAT timeouts on mobile networks and public Wi-Fi. Now the whole reattach flow is one command:

ssh -t agent-home tmux new -A -s agent

The -t flag forces a terminal allocation, which tmux needs when started directly as the remote command. You land inside the same session where Claude Code is working, with its scrollback intact.

Working well from a phone

  • Use the phone SSH app's key authentication, not a password; the server will refuse passwords anyway.
  • Configure the same keepalive interval if the app supports it.
  • Small screens make tmux's scrollback mode (Ctrl+b, then [) essential for reading what the agent did while you were away.
  • If two devices attach at once, tmux sizes the window to the smaller one. Detach the laptop first, or run tmux attach -d -t agent to detach other clients when you connect.

Verify the whole setup end to end

Test each guarantee explicitly. It takes about fifteen minutes and saves you from discovering a gap at 3 a.m. when the agent should have been working.

1

Detach and reattach locally

Start a long-running command in the tmux session, such as a test suite or a simple counter loop. Detach with Ctrl+b then d, wait a minute, run tmux attach -t agent, and confirm the output continued while you were detached.

2

Kill the SSH client mid-task

Connect through the tunnel, give Claude Code a multi-step task, then close the terminal window or switch the laptop to airplane mode without detaching. Reconnect through the tunnel and reattach. The agent should have kept going, because the hangup only reached your SSH session, not the tmux-owned process.

3

Test from a different network

Connect from a phone on mobile data or a hotspot, not your home Wi-Fi. This proves the path really goes through the public tunnel address rather than your LAN.

4

Reboot and check persistence

Reboot the host without logging in afterwards. Then, from outside, connect through the tunnel and run tmux ls. You should see the agent session recreated by systemd. If the tunnel is unreachable, the Localtonet client did not start at boot; if the session is missing, check lingering and the user service.

5

Confirm tunnel state in the dashboard

Check that the device shows as connected and the tunnel as running. Stop the tunnel and confirm your SSH connection attempt now fails, then start it again and confirm it works. This proves the off switch does what you expect.

6

Confirm password login is refused through the tunnel

Run ssh -o PubkeyAuthentication=no -p PUBLIC_PORT agent@PUBLIC_HOST. You should get Permission denied (publickey) without a password prompt. Also try root@ to confirm root login is rejected.

A few commands are handy for spot checks on the host at any time:

systemctl --user status agent-tmux.service
loginctl show-user agent --property=Linger
tmux ls
systemctl status sleep.target

The last one should report the target as masked if you disabled sleep in the power section.

Optional: get alerted when the host goes offline

An always-on machine at home will eventually go offline: a power cut, a router reboot, an ISP outage, or a kernel panic. You would rather find out from a notification than from a failed SSH attempt while traveling. Our platform-wide Token/Tunnel webhooks cover exactly this.

These webhooks fire when a token or tunnel in a selected Token Group changes state to Connected or Disconnected. Localtonet sends an HTTP POST with a JSON body containing four fields: Id (the tunnel id or authtoken), ActionDate, Type ("Token" or "Tunnel"), and Status ("Connected" or "Disconnected"). A disconnect notification for the tunnel has this shape (values shown as placeholders):

{
  "Id": "YOUR_TUNNEL_ID",
  "ActionDate": "TIMESTAMP",
  "Type": "Tunnel",
  "Status": "Disconnected"
}

A Type of "Token" with Status "Disconnected" tells you the client on the home machine lost its connection entirely, which usually means power, network, or the client process. A tunnel-level event can also follow a deliberate stop. Configuration steps are on the Localtonet webhook documentation page.

Do not host the webhook receiver on the machine you are monitoring

If the home machine loses power or internet, a receiver running on it cannot receive the Disconnected event. Point the webhook at an endpoint that lives somewhere else, such as a small serverless function, an automation service, or a chat tool's incoming webhook. Also treat the payload's Id as sensitive, since it can be an authtoken, and avoid forwarding it verbatim into public channels.

Note that these platform webhooks are separate from the file-event webhooks in our File Server feature. For this setup, you want the Token/Tunnel kind.

Security checklist for an always-on agent

An unattended coding agent with network access deserves a deliberate security posture. The tunnel does not bypass any of the controls below, and it does not replace them; it simply carries SSH traffic. Review this list before you leave the agent running overnight for the first time.

🔑 Key-only SSH Passwords and keyboard-interactive auth disabled, root login off, AllowUsers limited to the accounts you actually use. One key per device so revocation is precise.
👤 Least-privilege agent account No sudo, no access to your personal home directory, and no personal credentials stored in its home.
📦 Scoped repository credentials Per-repository deploy keys or fine-grained tokens, branch protection on main, and human review before merging the agent's work.
🤫 Secrets out of history Prefer the interactive login flow; if you use an API key, keep it out of command lines and Git, in a file readable only by the agent user.
⏹️ Tunnel only when needed Stop the tunnel when you will not reattach for a while, and delete it when the project ends. A stopped tunnel exposes nothing.
🔄 Keep the host patched Install OS and OpenSSH updates regularly, ideally with your distribution's unattended security updates, and update Claude Code through its normal mechanism.

Also think about what the agent can reach on your home network. Running Claude Code on a machine that sits next to your NAS, smart home hub, and printers means its shell commands can reach them too. If that concerns you, put the agent host on a separate network segment or guest network if your router supports it, and review Claude Code's own permission settings so that command execution requires your approval where it matters.

Troubleshooting

"Connection refused" or the connection closes immediately

Work from the inside out. On the host, run ssh agent@127.0.0.1. If that fails, sshd is not running or not listening on the port you think; check sudo systemctl status ssh and sudo ss -tlnp | grep ssh. If local SSH works, check the dashboard: is the device connected, and is the tunnel actually started? Remember that creating a tunnel does not start it. Finally, confirm the tunnel's local target matches sshd's real address and port, especially if you changed the port or set ListenAddress.

"Permission denied (publickey)"

  • Check you are connecting as the right user (agent@, not your laptop username).
  • Make sure your public key is in /home/agent/.ssh/authorized_keys on one line.
  • OpenSSH rejects keys if permissions are too open: chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys as the agent user, and the home directory must not be group-writable.
  • Confirm the user is listed in AllowUsers.
  • Run ssh -v agent-home to see which keys the client offers, and read sudo journalctl -u ssh on the host for the server's reason.

The tmux session is gone after a reboot

Check loginctl show-user agent --property=Linger; if it says no, the user service only starts on login. Then check systemctl --user status agent-tmux.service and journalctl --user -u agent-tmux.service for errors such as a wrong tmux path. Ensure you ran enable, not just start.

"no server running" when attaching

tmux sessions belong to a user. If you created the session as agent but logged in as your admin account, tmux ls shows nothing. Log in as the user who owns the session.

The agent stopped overnight

First, check whether the machine slept: journalctl -b | grep -i suspend and look for suspend entries. If the machine stayed up, attach to the session and read the scrollback. Claude Code may have stopped to ask for permission, hit a usage limit on your Claude plan, or finished the task. An agent waiting at a prompt looks idle from the outside.

Host key warning after reconnecting

SSH remembers host keys per host and port. If your tunnel's public address changes, for example because you recreated the tunnel, your client may treat it as a new host, which is expected. A changed key warning for an address you have used before deserves attention: verify the fingerprint on the host with ssh-keygen -lf before removing the old entry with ssh-keygen -R.

Sessions drop on mobile networks

Add ServerAliveInterval as shown earlier. Dropped connections are harmless with tmux, since you just reattach, but keepalives reduce how often it happens.

Home machine vs VPS vs laptop: the trade-offs

A home machine is not automatically the best place for an always-on agent. It is the right choice when you already own suitable hardware and value keeping code and data on your own disk. Here is how the main options compare qualitatively. Check current provider pricing yourself, as we deliberately quote no figures.

Factor Home machine + Localtonet TCP tunnel Rented VPS Your everyday laptop
Uptime depends on Home power, home internet, the machine itself, and the Localtonet client staying connected The provider's infrastructure Whether the lid is open, the battery charged, and you are online
Power and network reliability Residential grade; outages and router reboots happen, so webhook alerts help Data center grade in general Lowest; moves between networks and sleeps constantly
Remote reachability Via the tunnel; no public IP or port forwarding required Usually a public IP out of the box Rarely practical as a target while traveling with it
Data locality Code and files stay on hardware you own Code lives on the provider's servers Stays on your device
Hardware cost Already owned in many cases; you pay electricity Recurring rental; must meet the 4 GB RAM minimum Already owned
Maintenance OS updates, SSH hardening, physical upkeep, power settings OS updates, SSH hardening, firewall rules, disk housekeeping Minimal, but no true always-on capability
Best for Developers with spare hardware who want agents near local files and services Teams needing reliability and a provider-managed environment Short tasks you supervise in real time

Anthropic also offers cloud-hosted Claude Code sessions. According to Anthropic's documentation at the time of writing, those environments pause after a period of inactivity and are best suited to tasks that finish, rather than processes that must stay up. Their behavior and plan requirements may change, so check Anthropic's current documentation if you are considering them.

Whichever host you choose, Claude usage is billed by Anthropic separately from the machine. A long overnight run can reach your plan's usage limits well before it stresses the hardware, so size your expectations around your Claude plan, not just your CPU.

Frequently asked questions

Does Claude Code keep running when I close my SSH connection?

Not if you started it directly in the SSH shell; the hangup signal ends it. If you start it inside a tmux or screen session, it keeps running because tmux owns the terminal, not your SSH connection. Recent Claude Code versions also have a built-in background mode; check claude --help on your version.

Why use a TCP tunnel instead of an HTTP tunnel for SSH?

SSH is its own TCP protocol, not HTTP. A Localtonet TCP tunnel forwards raw TCP from a public host and port to a local IP and port, which is exactly what an SSH client needs. HTTP tunnels are meant for web applications served over HTTP.

Do I need to open ports on my router or have a public IP?

No. Our client on the home machine opens an outbound connection to a Localtonet relay server, and the tunnel's public address forwards over that connection. No inbound port forwarding, firewall changes, or public IP are required, which also means it typically works behind carrier-grade NAT.

Is exposing SSH through a tunnel safe?

The port becomes reachable from the internet, so it is as safe as your SSH configuration. With key-only authentication, password and root login disabled, a restricted user list, and current updates, password-guessing attacks have nothing to work with. Stop the tunnel when you do not need remote access to shrink the exposure window further.

What happens to the agent if I stop the Localtonet tunnel?

Nothing. The agent runs in tmux on the home machine and does not depend on the tunnel. Stopping the tunnel only removes your remote path into the machine; start it again and you can reattach to the same session.

How do I know if my home machine went offline while I am away?

Configure our Token/Tunnel webhooks. They send a POST with Id, ActionDate, Type, and Status when a token or tunnel in your selected Token Group becomes Connected or Disconnected. Send them to a receiver hosted somewhere other than the machine being monitored.

Can I use screen instead of tmux?

Yes. GNU screen provides the same detach and reattach behavior: screen -DR agent to create or attach, Ctrl+a then d to detach, and screen -r agent to reattach. Adjust the systemd unit accordingly, for example by starting a detached session with screen -dmS agent.

Will this work on Windows or macOS hosts?

The concepts carry over, but this guide's commands target Linux with systemd. On macOS, tmux and OpenSSH work, but boot persistence uses different mechanisms, and caffeinate or power settings handle sleep. We have not documented a Windows host workflow here, so check Anthropic's and our documentation for platform-specific details before adapting it.

Give your agent a home with Localtonet

Create a free account, install our client on your always-on machine, and point a TCP tunnel at port 22. You can reattach to your Claude Code session from anywhere, and stop the tunnel the moment you are done.

Get Started Free →

Localtonet is a secure multi-protocol tunneling and proxy platform designed to expose localhost, devices, private services, and AI agents to the public internet supporting HTTP/HTTPS tunnels, TCP/UDP forwarding, mobile proxy infrastructure, file server publishing, latency-optimized game connectivity, and developer-ready AI agent endpoint exposure from a single unified control plane.

Support