← Back to catalog
HookSecurity↓ 448

Backup Before Edit

Creates a timestamped copy of a file before each edit.

Installation
npx claude-code-templates@latest --hook development-tools/file-backup --yes

This hook fires on the PreToolUse event, before an Edit or MultiEdit change. It checks whether the target file already exists.

When it does, it copies the file into a .backups folder with a timestamp in the name. That way you always keep the version prior to the agent’s change.

When to use

  • When you want to be able to revert edits easily.
  • When you touch sensitive files and prefer a local safety net.

How to use

After installing, it creates the backup automatically before each edit. Look for the copies in the .backups folder when you need to restore.