ZENSHINZO全心像Truth Heart Vision

Signal offlineSoutheast Asia · UTC+7

Words

7 Habits for Letting an AI Agent Work on Your Machines

tech

The rules Claude Code works under on my setup, and the incidents behind them

7 habits for letting an AI agent work on your machines

Claude Code runs on my always-on Linux servers. From there it reaches my other machines over SSH, on a private Tailscale network: more servers, a streaming ingest server, small boards and a test box.

I've worked as a sysadmin, network engineer and developer for years. These rules come from that experience. They live in Claude's memory files and my project notes, and each one went in after something went wrong with Claude on my machines. Here they are, with the incident behind each.

Habit 1: Ask before anything hard to undo or outward-facing

Some actions are hard to undo. Others reach outside the machine. Those need a yes first:

  • running an installer, a package manager, a driver, or anything that enrolls a box somewhere
  • changing production config I work in
  • deleting
  • anything public
  • spending money
  • changing, rotating, resetting or removing a password or a key (Habit 3)

Downloading an installer, checking its hash and staging it are fine. Writing an install script is fine. Running it is my call. Claude once had a Chrome installer downloaded and verified on a box, one command from running it. I told it: before installing anything, ask.

"Can we enable X?" means make it possible and report. It doesn't mean change my setup. I once asked whether a mic and webcam option could be enabled. Claude checked the hardware, then added two new sources to both of my live OBS scenes. It hadn't asked.

Three reversible actions on my private network don't need a yes: starting a server on the tailnet, restarting a running service, and creating or updating a Docker Compose stack under /opt/docker. Claude does those and reports. The Compose work is pre-approved in Claude Code's auto-mode allow list. Enabling a service at boot isn't one of the three. Neither is touching SSH, the firewall or sudoers (Habit 6). The list above still needs a yes, and core-system changes outside those three need a plan.

Habit 2: Bigger changes go through a written plan I approve

Aside from the three reversible actions in Habit 1, changes that touch core systems get a plan first: servers, Docker, DNS, live services. The plan lives in my notes vault. Claude runs it only after I explicitly approve it, and the approval is recorded in the note.

"Resume the migration" is not approval. Claude once read it that way and ran staging steps I wasn't ready for.

Habit 3: No password or key change without a yes in the moment

Claude never changes, rotates, resets or removes a password or a key on its own. A runbook line isn't a yes. An earlier plan isn't a yes either.

During a server lockdown, my lockdown note listed "rotate root and administrator passwords". Claude followed it and set both to random values. I didn't want that. I always need a way into a machine in case of catastrophic data loss.

That way in is a break-glass login: the provider's console, plus a password I know, stored off the machine.

If a password looks lost, Claude searches my notes vault before calling it unrecoverable. It once told me a password couldn't be recovered and made a new one. The plaintext was in my vault the whole time.

Habit 4: Prove the target before you act

In three different ways, the action was right and the target was wrong.

Processes. Don't kill by pattern. pkill -f <pattern> can match the agent's own shell command, because the pattern is in it. Claude has killed its own shell that way at least five times. For the same reason, pgrep -f has reported a process alive after it had exited. Kill by listening port, by service, by exact name, or by a PID you recorded. For an exact name, run pgrep -x NAME. It can return more than one PID, so check each one with ps -fp PID first. Check which process owns the port before you kill it. On Linux, run ss with sudo. Without it, a port can show up with no process name and no PID:

sudo ss -ltunp 'sport = :PORT'
# read the process name and PID. If it's the one you mean:
sudo kill PID

Ports. Check that a port is free before you use it. If something else has it, pick another port. After starting your process, confirm it's the one listening on that port. Claude once started a headless Chrome with a remote-debugging port to take a screenshot. That port was already an SSH tunnel to my own browser on another machine. Chrome couldn't bind it, and the script drove my real browser instead. It navigated a tab and pressed keys.

Apps. Ask "which URL are you on?" first. I have two apps with the same UI and different databases. I reported a bug on one, and Claude spent a long time on the other. Everything it saw looked consistent, because nobody was writing to that database.

Habit 5: Port, don't rewrite, and carry the enabled state over

When you replace working code, copy it. Don't rebuild it from the spec. Claude once rewrote a bot command from a spec instead of copying it. It looked right, but it had lost checks added after real failures. An app that was off the network now showed as just "idle".

Nothing gets deleted from the original until the new one is proven: same inputs, same output, including the error states.

A service's enabled or disabled state is part of what you copy. Claude copied a camera service to a new machine. It was disabled on purpose. A comment at the top of its file said it is started by a stream command, not at boot. Claude ran systemctl enable --now on it, which set it to start at boot and started it right away. A room camera was on a public, unauthenticated page for about two and a half hours, with nobody streaming.

start is how you test. If starting it makes anything public, that's Habit 1: ask first. If your test is what started it, stop it when you're done and leave it disabled. enable is the owner's decision.

Habit 6: Never lose your way back in

Some configs decide whether you can reach the machine at all: SSH, the firewall, sudoers. Test those in the same session that changed them, and keep a way back.

On a remote Mac, a helper piped a password into sudo -S. That Mac had passwordless sudo, so sudo never read the password. It passed through to tee and was written into an sshd config file instead of the real content. Every new SSH connection failed. I got back in through screen sharing. The password also sat in plain text in a readable file.

No password gets piped into sudo now. For SSH, a change goes in as a new drop-in file, in a folder sshd actually reads (on most Linux systems, /etc/ssh/sshd_config.d/):

  1. Keep your current session open until the end.
  2. Write the new file as a normal user, under a name that isn't already used. Then removing it can't delete a file that was working.
  3. Give it root ownership and mode 0644, then move it into place.
  4. Check the whole config with sudo sshd -t. If it fails, remove the new file and stop.
  5. Reload sshd rather than restarting it.
  6. Try a brand-new connection. If it fails, remove the file and reload again from the session you kept.

Better still, set a timer that removes the file and reloads unless you cancel it. Then a dropped session can't leave the bad config in place.

For sudoers, open a root shell first and leave it open. Write the new file somewhere else first, with no dot in its name. Check it with sudo visudo -cf FILE, give it owner root and mode 0440, then move it into /etc/sudoers.d/. A broken sudoers file stops sudo itself, and the root shell is how you undo it.

A firewall change can drop every SSH session at once. Open the provider's console first, or set a timed rollback.

A remote wipe can also leave you with no way in. Claude remotely flashed a new Ubuntu image onto a small board. There was no monitor at that location. It booted, but SSH accepted the connection and closed it with no banner, most likely because there were no host keys. The board was unreachable.

Before wiping a box with no screen, build the new image for SSH and prove it first:

  • host keys generated ahead of time
  • sshd enabled at boot
  • a static IP as a fallback
  • that exact image booted in QEMU first, with a working SSH login

QEMU can't prove the board itself will boot. Keep a fallback boot on the box: a second partition or disk you don't overwrite, set up to boot by itself if the new one fails.

Habit 7: Don't load-test a live server

An uncapped iperf3 bandwidth test (two streams, about 500 Mbps) was pointed at my streaming ingest server while I was live. For about ten minutes the server received no inbound UDP. Both phone uplinks dropped, two VPN tunnels dropped, and the stream showed its fallback scene. It recovered on its own. I never confirmed the cause. Most likely it was the provider's DDoS filter.

Now a load test never hits a server while anything is live on it. Cap the rate, run it off-air, and test the actual path your traffic takes.

The checklist

  • Hard to undo or outward-facing? Ask first.
  • Touches a core system, outside the three reversible actions in Habit 1? Written plan, explicit approval, approval recorded.
  • Changing, rotating, resetting or removing a password or key? Only with a yes in the moment. Search the vault before calling one lost. Break-glass: the provider's console, plus a password kept off the machine.
  • Right process, port and app? Prove it first.
  • Replacing code or moving a service? Copy it, carry its enabled state, prove it before deleting the old one. Ask before a start that makes anything public.
  • Access config? A way back first: your open session for SSH, a root shell for sudoers, the console for the firewall. Check the change, then prove a brand-new connection.
  • Remote wipe? Image built for SSH, tested in QEMU with a login, fallback boot kept.
  • Load test? Never while anything is live. Cap the rate, run off-air, test the actual path.

Alongside the seven habits, every piece of work gets a one-line entry in my daily log and a git commit of my notes vault. When something goes wrong, the rule it teaches goes into Claude's memory.