Claude Code HookPre-Tool214 installs

Backup Before Edit

Create automatic backup of files before any Edit operation for safety. This hook creates a timestamped backup copy (filename.backup.timestamp) of any existing file before Claude modifies it. Provides a safety net to recover previous versions if needed. Only backs up existing files, includes error suppression to handle edge cases gracefully.

Install with the Claude Code Templates CLI
$ npx claude-code-templates@latest --hook="pre-tool/backup-before-edit" --yes

Requires Claude Code. The command adds this hook to your project's .claudedirectory — nothing runs on ToolZip's servers.

What's inside this hook

Component source

{

"description": "Create automatic backup of files before any Edit operation for safety. This hook creates a timestamped backup copy (filename.backup.timestamp) of any existing file before Claude modifies it. Provides a safety net to recover previous versions if needed. Only backs up existing files, includes error suppression to handle edge cases gracefully.",

"hooks": {

"PreToolUse": [

{

"matcher": "Edit",

"hooks": [

{

"type": "command",

"command": "if [[ -f \"$CLAUDE_TOOL_FILE_PATH\" ]]; then cp \"$CLAUDE_TOOL_FILE_PATH\" \"$CLAUDE_TOOL_FILE_PATH.backup.$(date +%s)\" 2>/dev/null || true; fi"

}

]

}

]

}

}

Type
Hook
Category
Pre-Tool
Installs
214
Source
GitHub ↗

Related Claude Code Hooks

Catalog data and component content are sourced from the open-source davila7/claude-code-templates project (MIT license). ToolZip curates the listing and writes original descriptions; every component links back to its original source. Claude Code is a product of Anthropic. ToolZip is an independent catalog and is not affiliated with or endorsed by Anthropic.