Block Dangerous Bash Commands: PreToolUse Hook With Tests
A SKILL.md that installs a Claude Code PreToolUse hook blocking rm -rf, force pushes, hard resets and DROP TABLE, plus a test script that proves each pattern blocks or allows.
Prompt
Installs to .agents/skills/block-dangerous-bash-commands-pretooluse-hook-with-tests/
mkdir -p .agents/skills/block-dangerous-bash-commands-pretooluse-hook-with-tests && curl -sL "https://prompts-gpt.com/prompts/block-dangerous-bash-commands-pretooluse-hook-with-tests/raw" -o .agents/skills/block-dangerous-bash-commands-pretooluse-hook-with-tests/SKILL.mdExample output
Tips and common edits
Why this works
- It fails closed: a missing jq, unreadable input or missing pattern file exits 2, because any other non-zero code lets the command run.
- Near-miss test cases such as --force-with-lease and rm -r build catch patterns that would block normal work.
- Patterns live in a text file, so you can add one and rerun the tests without touching the script.
Save as .claude/skills/destructive-command-guard/SKILL.md and ask Claude Code to "add a safety hook". For which commands to block, approve or log, write the policy first with Checkable Guardrail Rules for a Coding Agent. Needs jq.
Common edits
- Add patterns for your stack, such as kubectl delete, terraform destroy or aws s3 rm --recursive, with a matching block case in the tests.
- Swap exit 2 for a JSON permissionDecision of ask when you want a confirmation prompt instead of a hard block.
Reuse it: Use in a workflowAdapt in the builder
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
More like this
Claude Code Permission Allowlist and Deny Rules for This Repo in settings.json
Has Claude Code read your repo's scripts and CI, then propose allow, ask and deny permission rules with a reason for each, split into shared and local settings files, plus commands to test them.
Package Skills, Hooks and MCP Into a Claude Code Plugin
A SKILL.md that turns the skills, subagents, hooks and MCP servers in your .claude folder into an installable Claude Code plugin with a marketplace file, then validates and test-installs it.
Create Selective Pre-Commit Hooks for Claude Code
This prompt generates a bash script that triggers specific tests and typechecks only for packages modified in your current git branch.
Claude Code Hook Writer: Auto-Run Lint, Typecheck or Tests After Edits
Produces a PostToolUse hook entry for settings.json, the script it calls and a concrete procedure to test that the check runs after file edits.
Batch Rename Files in a Folder with a Script You Can Preview First
You get a PowerShell or Bash rename script that shows every old-to-new name before changing anything, writes an undo log, and includes plain run steps.
Write a Blog Intro That Hooks Readers in Under 100 Words
You get three blog intros under 100 words each, built on a problem, a surprising fact from your notes, and a short scene, each checked for a payoff by sentence three.
- Write a Full YouTube Video Script with a 15-Second Hook and Re-Hooks
- Write 15 Scroll-Stopping Hooks for One Topic, Grouped by Hook Type
- Design an AI Agent With Tools, Guardrails and Eval Cases Before You Build It
- Checkable Guardrail Rules for a Coding Agent: Blocked Commands, Approvals, Secrets and Hooks
- Short-Form Hook Test Plan for Reels, TikTok, and Shorts
- Coding Agent Task Brief with Guardrails, Test Plan, and Rollback Steps