File Deletion Protection
Blocks rm -rf on critical paths and enforces
a TRASH directory pattern. Requires approval
for other rm commands.
The safety-hooks plugin provides a comprehensive
set of hooks that enhance Claude Code’s behavior and
prevent dangerous operations. These hooks intercept
commands before execution and either block them
outright, require user approval, or suggest safer
alternatives.
Install the plugin via the Claude Code marketplace:
claude plugin install safety-hooks@cctools-pluginsFile Deletion Protection
Blocks rm -rf on critical paths and enforces
a TRASH directory pattern. Requires approval
for other rm commands.
Git Commit Protection
Requires explicit user approval before any
git commit, using Claude Code’s built-in
permission prompt UI.
Git Add Protection
Smart staging control that hard-blocks dangerous
patterns like git add . and git add -A,
while allowing new files and prompting for
modified files.
Environment Security
Blocks all .env file operations (read, write,
edit) and suggests the
env-safe command for
safe inspection.
Context Management
Blocks reading files longer than 500 lines to prevent context bloat in Claude Code sessions.
Command Enhancement
Enforces rg (ripgrep) over grep for better
search performance and output.
Safety hooks intercept commands at different stages:
Each hook returns one of three results:
| Hook File | What It Protects |
|---|---|
bash_hook.py | Main orchestrator for all bash command checks |
git_commit_block_hook.py | User permission prompt for git commit |
git_add_block_hook.py | Smart staging: blocks dangerous patterns, prompts for modified files |
env_file_protection_hook.py | Blocks all .env file operations (read/write/edit) |
file_size_conditional_hook.py | Prevents reading files over 500 lines |
grep_block_hook.py | Enforces ripgrep (rg) over grep |
notification_hook.sh | Sends ntfy.sh notifications on events |
The git add hook applies layered protection:
Hard blocks (always denied):
git add .git add ../git add *git add -A / git add --allNew files — allowed without a prompt, since they pose minimal risk.
Modified files — require user approval via the permission prompt.
Directories — the hook performs a dry-run to detect which files would be staged. If any modified files are included, approval is required.
All operations on .env files are blocked:
cat .env, Read tool)The hook directs users to the env-safe CLI for safe inspection of environment variables.
Reading files longer than 500 lines is blocked to prevent context window bloat. When a large file is detected, the hook suggests reading specific line ranges or using search tools instead.
When Claude Code attempts to use grep, the hook
blocks the command and suggests using rg (ripgrep)
instead. Ripgrep provides better performance,
respects .gitignore, and produces cleaner output.