Back to Blog

Soft Delete: The Backup Layer Your Coding Agents Need

Why AI agents that run cleanup and file operations need a safety net—and how Vectra Guard's soft delete backs up every rm so you can restore.

Coding agents are great at tidying up: removing node_modules, clearing dist/, deleting temp files, or "organizing" folders. One mistaken path or overbroad rm -rf and that cleanup becomes permanent data loss—no Trash, no undo. That's why we built soft delete into Vectra Guard: a backup layer that intercepts rm when it runs through vectra-guard exec, moves files to a rotating backup instead of deleting them, and lets you restore with a single command.

When Agents "Clean Up"

Agents routinely run commands that delete or move files. Common patterns:

  • Dependency cleanuprm -rf node_modules, rm -rf .venv before a fresh install.
  • Build artifactsrm -rf dist/, rm -rf build/, rm -rf __pycache__.
  • Temp and cacherm -rf /tmp/foo, rm -rf .cache.
  • User-requested organization — "Clean my desktop," "Remove old office temp files," "Delete that folder." A wrong path or a rename-gone-wrong can wipe irreplaceable data.

When the agent runs these in the raw shell, there is no safety net. When it runs them through Vectra Guard with soft delete enabled, every such rm is backed up first. Critical patterns (like rm -rf / or rm -rf ~/*) are still blocked; everything else is moved to backup so you can list and restore.

What Soft Delete Does

Soft delete is a backup layer for agent security:

  • Intercepts — When you (or your agent) run vectra-guard exec -- rm -rf <path>, Vectra Guard doesn't execute rm directly. It moves the target files/dirs into a timestamped backup under ~/.vectra-guard/backups/.
  • Rotates — Backups are managed by policy: max age, max count, max size. Old backups can be cleaned automatically so disk doesn't fill up.
  • Protects Git.git and git config files get extra protection and longer retention when protect_git is enabled.
  • Restorable — You can list backups, inspect what was "deleted," and restore by ID to the original location or to a different path.

This gives you an undo for agent-driven cleanup—without changing how the agent thinks about the task. The agent still runs "delete this"; Vectra Guard makes it safe.

Enable Soft Delete and Run Cleanup Safely

Soft delete is enabled by default in many setups. To be sure, add this to your config (vectra-guard.yaml or .vectra-guard/config.yaml with vectra-guard init --local):

Code
# vectra-guard.yaml
soft_delete:
  enabled: true
  max_age_days: 30
  max_backups: 100
  max_size_mb: 1024
  auto_cleanup: true
  protect_git: true

Then run cleanup through Vectra Guard so it gets backed up:

Code
# Clean build output (backed up, not permanently deleted)
vectra-guard exec -- rm -rf dist/

# Clean node_modules before fresh install (backed up)
vectra-guard exec -- rm -rf node_modules

# Remove a folder the agent created by mistake (backed up)
vectra-guard exec -- rm -rf some-experiment/

After each soft delete, the CLI prints a backup ID. You can use that to restore later.

Example: Clean Up Build Artifacts, Then Restore

A typical flow: the agent suggests cleaning dist/ before a rebuild. You (or the agent) run:

Code
vectra-guard exec -- rm -rf dist/

Output might look like:

Code
♻️  Files moved to backup (ID: a1b2c3d4e5f6)
   Restore with: vg restore a1b2c3d4e5f6

If you realize you needed something from dist/, list backups and restore:

Code
# List all backups
vectra-guard restore list

# Inspect what was in this backup (optional)
vectra-guard restore show a1b2c3d4e5f6

# Restore to original location
vectra-guard restore a1b2c3d4e5f6

# Or restore to a different path (e.g. avoid overwriting)
vectra-guard restore a1b2c3d4e5f6 --to ./restored-dist

Same idea applies when an agent "organizes" or deletes the wrong folder: if the command went through vectra-guard exec, it's in the backup list and restorable.

Restore Commands at a Glance

CommandWhat it does
vg restore listList all backups (ID, time, command, file count, size)
vg restore show <id>Show details and file list for one backup
vg restore <id>Restore backup to original paths
vg restore <id> --to /pathRestore to a different directory
vg restore cleanClean old backups (respects rotation policy)
vg restore statsBackup counts and total size

Make Agents Use the Backup Layer

For the backup layer to apply, destructive commands must run through Vectra Guard. Seed your project so the agent is instructed to use vectra-guard exec for any command that modifies system state (including cleanup):

Code
# Install (if needed)
curl -fsSL https://raw.githubusercontent.com/xadnavyaai/vectra-guard/main/install.sh | bash

# Seed agent instructions (Cursor, Claude, etc.)
vectra-guard seed agents --targets "claude,cursor"

The seeded rules tell the agent to run shell commands that change files via vectra-guard exec -- <command>. Then every rm is subject to blocking (for critical paths) or soft delete (backed up, restorable). No change to how you describe tasks—just a safety net underneath.

Soft delete is the backup layer coding agents need: cleanup and file operations stay in your workflow, but nothing is permanently gone until you decide. Enable it, run destructive commands through vg exec, and use vg restore when you need something back.