Automatically backup files before editing
Edit|MultiEditAdd to your .claude/settings.json:
{
"hooks": {
"PreToolUse": [
{
"hooks": [
{
"type": "command",
"command": ".claude/hooks/file-backup.sh"
}
],
"matcher": "Edit|MultiEdit"
}
]
}
}This hook includes a script file. Download the ZIP bundle for complete installation with script and instructions.
Automatically backup files before editing
None required
None
file_path=$(jq -r '.tool_input.file_path // empty')
if [[ -n "$file_path" ]] && [[ -f "$file_path" ]]; then
backup_dir=".claude/backups"
mkdir -p "$backup_dir"
timestamp=$(date '+%Y%m%d_%H%M%S')
filename=$(basename "$file_path")
cp "$file_path" "$backup_dir/${filename}.${timestamp}.bak"
fi
PreToolUse hooks run before a tool executes. They can validate, modify, or block the tool call.