Skip to content

Instantly share code, notes, and snippets.

@monperrus
Last active June 19, 2026 12:33
Show Gist options
  • Select an option

  • Save monperrus/71edbe5a84311273db3df4d8df9ba109 to your computer and use it in GitHub Desktop.

Select an option

Save monperrus/71edbe5a84311273db3df4d8df9ba109 to your computer and use it in GitHub Desktop.
Recoverable failures for AI coding agents

Safe rm defaults for agent-heavy Linux machines

Ordinary file deletion should moves files and directories to the trash instead of permanently unlinking them.

That matters a lot when using coding agents, especially in YOLO mode. Agents can run broad shell commands quickly, expand globs, execute cleanup scripts, or apply generated commands with more confidence than the situation deserves. A trash-backed rm does not make destructive work impossible, but it turns many accidental deletions from irreversible data loss into a recoverable operation.

What is protected

Interactive shell deletion is redirected to trash:

alias rm='trash-put'
alias rmdir='trash-put'

There is also a user-level wrapper at:

~/.local/bin/rm

Because ~/.local/bin is ahead of /bin and /usr/bin in PATH, normal command lookup resolves rm to the wrapper. The wrapper calls trash-put by default.

Escape hatches

Permanent deletion is still available, but it is explicit:

real-rm path
rm --permanent path

This is intentional. Some operations genuinely need permanent deletion, but they should stand out in shell history and during review.

Recovery

Useful trash-cli commands:

trash-list
trash-restore
trash-empty 60

trash-list shows deleted files. trash-restore lets you recover them. trash-empty 60 permanently removes trash entries older than 60 days.

Automatic cleanup

A user-level systemd timer runs daily:

systemctl --user status trash-empty-old.timer

The service executes:

/bin/trash-empty 60

That keeps recent accidents recoverable while preventing trash from growing forever.

Important limitations

This setup protects normal user-level shell deletion. It does not fully protect against:

  • sudo rm ...
  • /bin/rm ...
  • programs that unlink files directly
  • scripts that set their own PATH
  • filesystem damage or overwrites

For stronger protection, add filesystem snapshots such as Btrfs, ZFS, LVM, or Timeshift. Trash-backed deletion is the first line of defense; snapshots are the next layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment