Writing/AI·15 min read

Running Claude Code on a €6 Hetzner server

Why my scheduled AI agents moved from my laptop to a small EU server, what they get done every weekday, and how I set it up and locked it down.

TL;DR

  • A small Hetzner VPS (a CX23, about €6 a month at today's prices; mine is still on the old €3.99) runs my scheduled Claude Code jobs: a weekday SEO run, a daily read-only log check, and a sync that keeps the knowledge base the same as on my Mac.
  • Jobs start from cron, either as headless `claude -p` runs or as interactive sessions in tmux with Remote Control, so I can read and answer them from my phone.
  • The agent runs the SEO work on its own: a health crawl of every URL, a check that pages still match the code, one small fix. It commits its own files, but it never deploys, never sends anything and treats production data as read-only.
Jump to
  1. Why a server and not my laptop
  2. Picking the server
  3. Locking it down before Claude goes on it
  4. Installing Claude Code and signing in
  5. Two ways to run it: tmux and headless
  6. Scheduling: cron or systemd timers
  7. Example: the SEO run
  8. Keeping the knowledge base and git in sync
  9. Logs, alerts and cost
  10. Security rules I don't bend
  11. What it's good for, and where it falls short
  12. A starter checklist

Note

Commands are checked against the Claude Code docs as of November 2026.

Until mid-November my scheduled agent jobs ran on my Mac. The SEO run for Simple Commenter was a scheduled task in the Claude desktop app, set for 08:30 on weekdays. It only ran while the app was open, and caught up when I next opened the laptop. Fine for a hobby, not for "check production logs every morning".

So on 15 November 2026 I moved them to a small Hetzner server I call claude-box. Here's the setup, what runs on it, and the rules that keep an unattended agent in line.

Why a server and not my laptop

Speed isn't the reason. The model runs at Anthropic either way, so a job doesn't finish faster on a server. What changes is what the agents cost the machine they run on.

  1. My laptop stays a laptop. An agent working for hours keeps the machine busy: git, node processes, tests, crawls, file watchers. Run a few of those at once and the battery is gone by lunch and the laptop gets hot. On claude-box the same load lands on a machine built for it, and my laptop is free for my own work.
  2. It's always on. A job at 07:05 runs at 07:05, whether my laptop is asleep, in a bag or on a plane.
  3. Storage stays off my SSD. Agents leave things behind: a git worktree for every parallel session, often with its own node_modules, plus logs, screenshots and reports. When I counted, one repository on my Mac had 59 agent worktrees. On a server that's a disk I can watch, clean on a schedule and grow when I need to, and a full disk there doesn't stop me working.
  4. I can pick up anywhere. The box and my Mac share the same git history and the same knowledge base. I can start a task from my phone, let the box work, and sit down at the Mac later with everything in sync. More on how below.
  5. It's cheap and in the EU. The box costs about as much as a coffee a month, Claude runs on my existing subscription, and the data stays in the EU like the rest of my infrastructure.

A bonus: a server agent only knows what's committed, so every rule has to live in a file. That turned out to be the biggest improvement of the move.

Picking the server

I use a Hetzner CX23: 2 shared vCPUs, 4 GB of RAM, 40 GB of disk, in an EU location. New CX23s list at about €5.99 a month including IPv4 (November 2026, before VAT). Mine was created earlier, so it keeps the old €3.99 plus IPv4: Hetzner leaves existing servers on their original price. The cheap CX plans aren't always available to order, so check what's on offer.

That's enough because the model runs at Anthropic; the box only runs the CLI, git and shell commands. What it can't do is build a big Next.js app, so my server prompts say "never run npm run build or the whole test suite". The agent lints the files it changed and runs only the tests that cover them.

If you want to run builds or headless browsers there too, a CX33 (4 vCPU, 8 GB, €8.49 a month at September 2026 prices, and prices have risen since, so check hetzner.com/cloud) is the next step up.

Creating it with the hcloud CLI:

hcloud server create \
  --name claude-box \
  --type cx23 \
  --image ubuntu-24.04 \
  --location hel1 \
  --ssh-key my-laptop

The commands in the rest of this post assume Ubuntu 24.04 LTS.

Locking it down before Claude goes on it

Harden the box first, install the agent second. I reach claude-box only over Tailscale, as a dedicated user with an SSH key. The rest of this section is the baseline I'd put on any fresh Ubuntu server.

Two users: one for you, one for the agent

Log in as root once, create an admin user with sudo for yourself, and copy your SSH key across:

adduser --gecos "" admin
usermod -aG sudo admin
rsync --archive --chown=admin:admin ~/.ssh /home/admin

Then, as admin, create the user the agent runs as. I'll call it agent here. It gets no general sudo:

sudo adduser --disabled-password --gecos "" agent
sudo install -d -m 700 -o agent -g agent /home/agent/.ssh
sudo install -m 600 -o agent -g agent ~/.ssh/authorized_keys /home/agent/.ssh/authorized_keys

If a job really needs one root action, write a root-owned script for exactly that action and allow only that script:

sudo visudo -f /etc/sudoers.d/agent
# agent ALL=(root) NOPASSWD: /usr/local/sbin/one-specific-task

Claude Code also refuses to skip permission prompts when it runs as root, which is one more reason not to run it as root.

SSH keys only

Put the SSH settings in a drop-in file. Name it so it sorts first, because sshd uses the first value it reads and cloud images sometimes ship their own file:

sudo tee /etc/ssh/sshd_config.d/00-hardening.conf >/dev/null <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
EOF
sudo sshd -t && sudo systemctl reload ssh

Test a new login from a second terminal before you log out.

Tailscale, firewall and updates

Any SSH port open to the internet gets password guesses all day, every day. The simplest fix is to not have one. With Tailscale, SSH only answers on your private network:

curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale up
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow in on tailscale0
sudo ufw enable

Check that you can log in over Tailscale before you enable the firewall, or you'll lock yourself out. If you'd rather keep public SSH, use sudo ufw allow OpenSSH instead of the Tailscale rule and add fail2ban (sudo apt install -y fail2ban), which on Ubuntu protects SSH out of the box.

Turn on automatic security updates, and let them reboot when a new kernel needs it. Updates that never reboot leave the old kernel running:

sudo apt update && sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
sudo tee /etc/apt/apt.conf.d/52auto-reboot >/dev/null <<'EOF'
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:30";
EOF

Pick a reboot time when no scheduled job is running.

Installing Claude Code and signing in

As the agent user, install the native build:

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

It installs to ~/.local/bin/claude and updates itself in the background. claude doctor checks the install and shows whether auto-updates are on.

To sign in, I use my Claude subscription, not an API key. Run claude, choose the subscription login, press c to copy the login URL, open it on your laptop, and paste the code back into the terminal. claude auth status shows who you're signed in as. The credentials land in ~/.claude/.credentials.json, readable only by the agent user.

Why the subscription login:

  • Remote Control needs it. Remote Control, which lets me open the server's sessions in the Claude app, works only with a claude.ai account. It doesn't work with an API key, or with the long-lived token from claude setup-token.
  • The cost is known in advance. Scheduled jobs use my plan's limits instead of a per-token bill.

One trap: if ANTHROPIC_API_KEY is set in the job's environment, it takes precedence over the subscription login, and print mode will use and bill that key. That's easy to do by accident if a script loads your app's .env into the shell. My scripts pass .env only to the programs that need it, never into Claude's environment.

Two ways to run it: tmux and headless

Interactive, in tmux, with Remote Control

For work I want to follow or answer, I start an interactive session inside tmux so it survives when I disconnect:

sudo apt install -y tmux
tmux new -s work
cd ~/app && claude --remote-control "claude-box: app"

Detach with Ctrl-b then d, and come back with tmux attach -t work. With --remote-control, the same session shows up in the Claude app on my phone and Mac, by name. That's how I use the box most days: start something from the train, answer its question at lunch.

Headless, with claude -p

For jobs where nobody needs to reply, I use print mode. Claude runs once, prints its answer and exits:

claude -p --output-format json --max-turns 30 \
  --disallowedTools "Edit" "Write" "Bash(git push *)" \
  -- "Read CLAUDE.md, then summarise yesterday's errors in the API logs."

--output-format json adds a session ID, token usage and an estimated cost for your logs. --max-turns stops a run that loops. The prompt goes after --, or --disallowedTools would swallow it.

Scheduling: cron or systemd timers

My jobs start from the agent user's crontab. The server's clock is in UTC, the default on Hetzner images, and I want my jobs at fixed Tallinn times all year, so each job is listed for both possible UTC hours and the script exits unless it's the right local hour:

crontab -e
# m  h    dom mon dow  command
5    4,5  *   *   *    /home/agent/app/scripts/log-check.sh
30   5,6  *   *   1-5  /home/agent/app/scripts/seo-run.sh
*    *    *   *   *    /home/agent/app/scripts/repo-sync.sh follow
# first lines of each script
[ "$(TZ=Europe/Tallinn date +%H)" = 07 ] || exit 0
export PATH="$HOME/.local/bin:/usr/local/bin:/usr/bin:/bin"

The PATH line matters: cron starts with a minimal PATH that doesn't include ~/.local/bin, where claude lives.

If you prefer systemd, a user timer can take the time zone directly. Create ~/.config/systemd/user/log-check.service:

[Unit]
Description=Read-only log check
 
[Service]
Type=oneshot
WorkingDirectory=%h/app
ExecStart=%h/app/scripts/log-check.sh
TimeoutStartSec=1h

And ~/.config/systemd/user/log-check.timer:

[Unit]
Description=Daily log check
 
[Timer]
OnCalendar=*-*-* 07:05:00 Europe/Tallinn
Persistent=true
 
[Install]
WantedBy=timers.target

Then enable it, and let the user's timers run without an open login:

sudo loginctl enable-linger agent
systemctl --user daemon-reload
systemctl --user enable --now log-check.timer
systemctl --user list-timers
journalctl --user -u log-check.service

Either way, wrap every run in two guards. flock -n means a slow run never overlaps the next one, and timeout means no run lasts forever:

flock -n "$HOME/log-check/lock" timeout 1h claude -p ...

Example: the SEO run

Here's how my weekday SEO run for Simple Commenter works on the server.

At 08:30 Tallinn time on weekdays, cron starts a wrapper script. The script starts Claude in tmux as an interactive session with Remote Control, named "SEO autopilot" plus the date. So the run appears as a chat in my Claude app, where I can reply, until the next run replaces it.

There's one catch. The first time Claude runs with permission prompts turned off, it shows a consent screen that a human has to accept once. The script checks the tmux pane after 30 seconds. If that screen is waiting, it kills the session and runs the same prompt headless instead, with the reply saved to a log file. So the run happens either way, and the log says which way.

The prompt starts with a block of hard limits that override anything else the agent reads. In short:

  • Sync the repository with the one script made for it. Never pull, merge, rebase or reset on the server.
  • Commit only your own files on main. Stage them by name, never git add -A. Push your commits so the Mac can merge them. Never force a push.
  • Never deploy.
  • Production data is read-only.
  • Never send email, post, submit forms or create accounts. Write a draft for me instead.
  • Never spend paid API credits. If the run needs data from a paid SEO tool, it writes a request into a file, with how many credits it would cost, and I decide.
  • Ship at most one backlog item per run.
  • End with three or four plain sentences: what shipped, with the commit hash; what broke; and what I need to do.

That's the approval gate. The agent does the preparing: a health crawl of every URL in the sitemap, a check that marketing pages still match the code, one small fix. I do the approving. A commit on main isn't live. It goes live only when I run a release, and only I ask for releases.

The first server run was on 16 November. Its first five weekday runs shipped five small changes, one per run: a worked example on a guide, breadcrumb structured data for the docs, six trimmed meta descriptions, a competitor update on a comparison page, and two em dashes my copy rules don't allow. Each run logged a line with its commit and the paid credits it spent: zero.

Keeping the knowledge base and git in sync

This is the part that makes two machines feel like one. Both my products keep their durable knowledge in plain Markdown: dated measurements, decisions, the SEO backlog, reports, the run log. The agent on the server and I on the Mac have to read the same files, and the same code, at any moment. Here's how they stay the same:

  • The Mac publishes its main to GitHub under a separate ref after every commit, through a git hook. It's not a branch, so it starts no build or deployment.
  • Cron on the server runs a sync script every minute that fast-forwards the server's main to that copy, but only when nothing on the server is half-edited.
  • Commits made on the server are pushed back to GitHub and merged on the Mac.

For Truth or Dare AI the knowledge base is its own private repository, shared the same way. The server's commits come back as a separate branch for the Mac to merge.

I built this after a server session read an old setup doc: the newer text had been committed on the Mac and never left it. Only commits travel. Uncommitted edits, .env files and Claude's own memory files stay on the machine where they were made. If both machines need a fact, it goes into the knowledge base and gets committed.

Sitting down at the Mac

When I switch from the phone back to my own computer, the routine takes a minute:

scripts/repo-sync.sh                # one line: in sync, or what differs
git fetch origin && git status -sb  # did the server push anything?
git merge origin/main               # only if both sides have new commits
npm run where                       # what GitHub, the Mac and the server each have

The sync script prints a single line, and a line starting with NOT says what differs and what to do. If the Mac is only behind, git pull --ff-only is enough. If both sides have new commits, I merge, never rebase. npm run where is a small script of mine that shows which commit GitHub, the Mac and the server each have, and what each holds uncommitted or unpushed. I run it before every release, and it only succeeds when nothing is left out.

Three rules keep it boring:

  • Never amend or rebase on main. The server follows every commit within a minute, so a rewritten commit leaves two machines with histories that disagree.
  • Stage files by name. Several agent sessions can work in the same checkout. git add -A would sweep up someone else's half-finished work.
  • Commit before you switch. Work that isn't committed doesn't exist on the other machine.

Keeping the disk clean

On a 40 GB server, storage is something you manage, not something you forget. A few checks I'd make a habit:

df -h /                                         # how full is the disk?
git worktree list                               # which agent worktrees still exist?
git worktree remove <path>                      # remove one that's finished
find ~/log-check -name '*.log' -mtime +30 -delete   # drop logs older than 30 days

If the jobs outgrow the disk, a Hetzner volume adds storage without rebuilding the server.

Logs, alerts and cost

Every job writes to its own folder in the agent user's home, one file per day: when it started, which prompt it used, how it ran (as a chat or headless) and its exit code.

The read-only log check goes a step further. Its report's first line is always STATUS: OK, WATCH or ALERT. The wrapper reads that line. On ALERT, or when the run ends without a report at all, it emails me. On OK it stays quiet. I want to hear about problems, not about every run.

Temporary jobs clean up after themselves. After I moved Simple Commenter's website off Vercel, the box watched it for 12 hours: a curl probe every five minutes, a read-only Claude check every hour, an email if two probes in a row failed. Then it emailed a summary and removed its own cron lines.

Cost control:

  • The server is fixed: about €6 a month new (I still pay the old €3.99).
  • Claude is my subscription. Scheduled jobs share the plan's limits with my own work, so each one is kept small: one item per run, hard timeouts (one hour for the log check, three for a headless SEO run), and no full builds.
  • On an API key instead, add --max-budget-usd to print-mode runs and set a workspace spend limit in the Claude Console. The CLI's cost figures are estimates; the Console limit is the real cap.
  • Paid third-party APIs go through me. The agent files a request; it doesn't spend the credits.

Security rules I don't bend

Bypass mode, honestly. My scheduled jobs run with --permission-mode bypassPermissions, because nobody is there to answer a prompt at 07:05. Claude Code's docs say that mode is meant for isolated machines like containers or VMs. A VPS that only does the agent's work can be one, but the mode removes the human check, so everything else has to hold:

  • A dedicated, low-privilege user. No general sudo, so a bad run can't change the system.
  • Scripts that check where they are. Each wrapper exits unless the hostname is claude-box, so a copied script can't start a bypass run on my Mac.
  • A written command list for production. When a job has to look at a production server, its prompt lists what it may run there: docker ps, docker logs, df, free, uptime, journalctl and the like. It never writes a file on a server; output is saved on claude-box, outside the SSH command.
  • Changes wait for a human. The agent commits; a release is a separate step that only I start. For a stronger gate, have the agent push a branch and open a pull request instead.
  • As few secrets as possible. Every key and token on the box is one an unattended run can use. Keep production credentials off it if you can. I keep a written list of every access claude-box has and how to take each one away.

The lesson I took from this year's supply-chain incidents: attackers rarely break the app any more. They steal long-lived tokens from developer machines and build pipelines. An agent server is exactly that kind of machine, so treat it like one.

Rules in the prompt, locks in the tools. The prompt says "read-only". The command line says it too:

claude -p --permission-mode bypassPermissions \
  --disallowedTools "Edit" "Write" "Bash(git push *)" \
  "Bash(npm run deploy *)" "Bash(systemctl *)" "Bash(reboot *)" \
  -- "$(cat scripts/log-check-prompt.md)"

Deny rules are checked before anything is allowed. My scripts rely on them holding with prompts turned off; test that on the version you install before you trust it. They're still pattern matches, not a sandbox. Bash(git push *) doesn't catch git -C . push. For a harder boundary, Claude Code has a sandbox for shell commands.

No production writes without a gate. The scheduled jobs are allowed to read production logs and data, not to change them. But a sentence in a prompt is a rule, not a lock. The lock is a database user that can only read, and a deploy that only a human can start.

Secrets stay out of the conversation. Credentials live in files outside git. Scripts read keys at runtime, and nobody pastes a key into a doc or a chat.

Everything is undoable. The agent adds commits; it never amends, rebases or force-pushes.

What it's good for, and where it falls short

What works well:

  • Morning reports before I wake up.
  • Long tasks that don't care that I closed the laptop.
  • Short watches after a risky change.
  • Working from my phone through the Claude app.
  • Shared memory: the same knowledge base on every machine.

The limits:

  • No browser. Search Console and anything else behind a login stays on the Mac; the report marks those steps "not verified".
  • One-time human steps. The consent screen and the login code need me once.
  • Two machines, two sets of local state. Memory files and uncommitted work don't sync.
  • A small box is small. No production builds on a CX23.
  • It doesn't replace judgment. The agent notices; I decide.

A starter checklist

  1. Create a small EU VPS. A CX23 is plenty.
  2. Make an admin user and a separate agent user with no general sudo.
  3. SSH keys only, no root login, SSH over Tailscale (or fail2ban), firewall on, automatic updates with reboots.
  4. Install Claude Code as the agent user and sign in with your subscription. Keep API keys out of the job environment.
  5. Run interactive work in tmux with --remote-control, and scheduled work with claude -p.
  6. Schedule with cron or systemd timers, with flock and timeout around every run.
  7. Put hard limits at the top of every scheduled prompt, and repeat them with --disallowedTools.
  8. The agent prepares and commits. Deploys, emails and spending stay with you.
  9. Log every run. Email only on alerts.
  10. Commit your knowledge base and sync it, so the agent reads what you read.

Next: From comment to deployed fix →

Related