Guardrail Hooks — rules held by code
Turn rules an agent keeps breaking into hooks, permission rules or tool-level refusals so code enforces them instead of prose.
Security & ReviewAdvanced★ 788⑂ 95AI score 9/10Last updated: Nov 21, 2026
What it does
- Fires on cues like "it did it again", "make this impossible", "add a hook", "my hook didn't fire".
- Gives a decision table for picking the smallest code path that holds a rule: permission rules (
permissions.ask/deny), PreToolUse hooks, a refusal inside your own tool, git pre-commit hooks, and Stop / SessionStart / PostToolUse hooks. - Twelve field rules for guards that hold without becoming noise: strip heredocs before matching, open the scripts a command runs, pick
askvsdenyvs exit 2 deliberately, never block the escape hatch, setonFailure: block, and start new blocking hooks in observe mode. - Ships three template scripts:
guard_one_way_doors.py(gate irreversible or public actions),block_wrong_identity.py(forbid a commit author address), andtest_hooks.py(payload-driven test runner). - Covers Windows pitfalls, Codex and Cursor differences, and a re-verification routine for dated vendor facts.
Who it's for
- Claude Code, Codex or Cursor users who need hard limits on what an agent may run.
- Anyone whose CLAUDE.md rules keep getting ignored at the decisive moment.
- Teams that want a human click before destructive or public one-way-door actions.
Examples
- Require a human prompt before the agent runs
gh repo deleteor any publish command, even in auto mode. - Block commits authored by a forbidden email across
user.email,-c user.email=and--author, while still allowinggit log --author=searches. - Add a Stop hook returning
decision: "block"so the agent cannot claim it is done before tests have run.
· · · Install guide · · ·
Try it now, no install
Paste this into Claude to use the skill without installing anything.
Read the instructions in this file and follow them to help me: https://raw.githubusercontent.com/phuryn/product-engineering/HEAD/agent-harness/skills/guardrail-hooks/SKILL.md What I want: (describe your task here)
If Claude can't open the link, open it yourself and paste the contents instead.
↓ If it works for you, download the ZIP below and install it. Then it runs on its own — no pasting each time.
Install in the Claude app (no terminal)
- Download the ZIP with the button below.
- In Claude, open Settings → Capabilities and turn on 'Code execution and file creation'. (one time)
- Go to Customize → Skills → + → 'Upload a skill' and upload the ZIP.
Install in Claude Code
Let Claude do it — paste this into Claude Code
Install the skill I found on AI Skill Mart. Copy the agent-harness/skills/guardrail-hooks folder from the GitHub repo phuryn/product-engineering into my ~/.claude/skills/guardrail-hooks/. When it's done, tell me in one line what this skill can do.
Install with a command instead
git clone https://github.com/phuryn/product-engineering.git && mkdir -p ~/.claude/skills && cp -r product-engineering/agent-harness/skills/guardrail-hooks ~/.claude/skills/⚠ This is a third-party skill. Check the source repository before installing.
- Clone the repository:
git clone https://github.com/phuryn/product-engineering.git - Install the skill:
mkdir -p ~/.claude/skills && cp -r product-engineering/agent-harness/skills/guardrail-hooks ~/.claude/skills/ - Copy the Python files from
scripts/into your hooks directory —.claude/hooks/for a single project, or~/.claude/hooks/machine-wide. - Edit the
CONFIGblock at the top of each script, replacing the example rules with your own commands and addresses. - Run the tests until they pass:
python .claude/hooks/test_hooks.py(usepython3if needed). - Wire the hooks in
settings.jsonunderhooks.PreToolUsewithmatcher: "Bash", exec form (args), and"onFailure": "block". - Verify with
/hooksin Claude Code, then run the canaries:true guard-canaryandtrue user.email=<a blocked address>. Never test a guard with a real destructive command.
View source on GitHub ↗License: MIT