dangerous-command-blocker — Claude Code hook: setup and features
Intercepts Bash calls in Claude Code to block dangerous commands like rm -rf / or writes to .git/. Protects project files from unintended agent actions.
npx claude-code-templates@latest --hook security/dangerous-command-blockerWhat dangerous-command-blocker does
The hook triggers on the PreToolUse event before any shell execution via Bash. It calls python3 .claude/hooks/dangerous-command-blocker.py to inspect the command.
The blocker catches destructive operations like rm -rf /, mkfs, or dd. It also shields sensitive paths: .claude/, .git/, and node_modules/. Suspicious patterns trigger detailed safety messages. The hook immediately halts the agent.
Your environment must have python3 installed. Without it, the script cannot run.
What it helps with
- block catastrophic shell commands like
rm -rf /andmkfs - protect
.git/,.claude/, andnode_modules/directories from deletion - intercept risky Bash tool calls before the agent runs them
- surface safety warnings when detecting suspicious command patterns
Example prompts for the agent
- Clean up temporary build artifacts and cache folders
- Remove old dependencies and reinitialize
.git
How to install dangerous-command-blocker
1claude-code-templates
npx claude-code-templates@latest --hook security/dangerous-command-blocker2Manually: put the files in place
.claude/settings.jsonThe hooks block: event (PreToolUse, PostToolUse, Stop…) → command. Personal ones go to ~/.claude/settings.json
Step by step, with commands for each platform: Claude Code hooks: what they are, where to configure them, how to block a risky command
Questions about dangerous-command-blocker
How to install dangerous-command-blocker in Claude Code?
Run npx claude-code-templates@latest --hook security/dangerous-command-blocker. The hook registers in your .claude/settings.json file.
What does dangerous-command-blocker do?
It monitors PreToolUse events for the Bash tool in Claude Code. It blocks destructive commands such as rm -rf / or dd and protects directories like .claude/, .git/, and node_modules/.
What dependencies does dangerous-command-blocker require?
The hook requires python3 to be accessible on your system path because it executes .claude/hooks/dangerous-command-blocker.py directly.
Source text
dangerous-command-blocker.json · MIT
{
"description": "Advanced protection against dangerous shell commands with multi-level security. Blocks catastrophic operations (rm -rf /, dd, mkfs), protects critical paths (.claude/, .git/, node_modules/), and warns about suspicious patterns. Features: catastrophic command blocking, critical path protection, smart pattern detection, and detailed safety messages.",
"supportingFiles": [
{
"source": "dangerous-command-blocker.py",
"destination": ".claude/hooks/dangerous-command-blocker.py",
"executable": true
}
],
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "python3 .claude/hooks/dangerous-command-blocker.py"
}
]
}
]
}
}
© davila7 · MIT · davila7/claude-code-templates