Skip to main content
hook

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.

Install into Claude Code · claude-code-templates All methods and platforms ↓
npx claude-code-templates@latest --hook security/dangerous-command-blocker
Open on GitHub

What 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 / and mkfs
  • protect .git/, .claude/, and node_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-blocker

2Manually: put the files in place

.claude/settings.json

The 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

Similar hooks

All hooks for Security →

From the same set804

The whole set →
all-tools Lists tools available in the current Claude Code session alongside TypeScript signatures and brief purpose descriptions. Useful when checking capabilities before starting a task. 1,381installs terraform-specialist A Terraform subagent that builds modules, wires up remote state and hunts drift. Useful once your infrastructure outgrows a single main.tf. 1,349installs supabase-realtime-optimizer This subagent reviews Supabase Realtime subscriptions, WebSocket connections, latency, and message flow. Use it when realtime behavior needs diagnosis or tuning. 1,346installs backup-before-edit A Claude hook that copies a file with a timestamp before every edit. Useful when the agent rewrites code and you want a way back. 1,328installs vercel-deployment-specialist Configures Vercel platform deployments, creates vercel.json setups, and implements edge logic. Helps automate releases and routing. 1,309installs computer-vision-engineer This subagent helps build image and video analysis pipelines, from object detection and OCR to face recognition and tracking. Use it when a task calls for a dedicated computer-vision system. 1,248installs containerize-application A slash command that writes the Docker setup for your project: Dockerfile, .dockerignore, docker-compose and Kubernetes manifests. 1,200installs review-agent Audits Obsidian vault changes by checking reports, metadata, links, tags, and MOCs. Run it after enhancement work to spot inconsistencies across the vault. 1,198installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor