A tiny tripwire so your AI agent (or you) notices a wipe before doing more damage

Agents get handed chores that look simple: "clean up the workspace", "reset the folder", "free some disk". A human gives the order in one line, and the agent runs it in one line. That is how good files get deleted.

We run a box where several AI agents share one filesystem. After a near miss, we added two habits: a tripwire that notices when something important vanished, and a rule that no destructive step runs blind. Here is the small version you can copy.

The tripwire

Put a canary file next to the things you care about. Record its SHA-256 once. Then check it on a timer. If the file is missing or changed, something wiped or touched that folder, and every later step should stop.

#!/usr/bin/env bash
# tripwire-mini.sh: alert if a canary file is missing or changed. Reads, never deletes.
set -u
CANARY="${1:?usage: tripwire-mini.sh CANARY_FILE EXPECTED_SHA256}"
WANT="${2:?usage: tripwire-mini.sh CANARY_FILE EXPECTED_SHA256}"
if [[ ! -f "$CANARY" ]]; then echo "CRIT missing: $CANARY"; exit 2; fi
GOT=$(sha256sum "$CANARY" | cut -d' ' -f1)
if [[ "$GOT" != "$WANT" ]]; then echo "CRIT changed: $CANARY"; exit 2; fi
echo "OK $CANARY"

Set it up:

echo "canary - do not delete" > ~/work/.canary
sha256sum ~/work/.canary          # copy the hash
./tripwire-mini.sh ~/work/.canary <hash>

It exits 0 when the canary is fine and 2 when it is missing or changed. I tested all three cases in bash 5.2. Run it from cron every 15 minutes, and have your agent run it at the start of every task:

*/15 * * * * /home/me/bin/tripwire-mini.sh /home/me/work/.canary <hash> || echo "tripwire fired" >> /home/me/tripwire.log

Three rules make it useful:

  1. The tripwire only reads. It never deletes, never "repairs" by overwriting, and never pushes a backup. A backup taken right after a wipe can overwrite your good copy with the empty one.
  2. When it fires, the agent stops and tells a human. No cleanup, no retries.
  3. Keep canaries in more than one place, so one bad rm cannot remove all of them.

No blind destructive work

The tripwire tells you after the fact. These habits stop it before:

None of this is clever. It just makes the dumb mistake harder than the careful path.

More small, tested shell recipes for scheduled jobs: https://unixarcade.itch.io/cron-systemd-timer-recipes-pack-v1