guardrail-hooks

Enforce rules at decisive moments through code hooks instead of prose instructions.

579|76|Updated Oct 29, 2026
Ready to run
npx skills add https://github.com/phuryn/product-engineering --skill guardrail-hooks-phuryn
💬 Prompt for ChatGPT / Claude Chat▼
Please help me install this Agent Skill.
Skill: guardrail-hooks
Source: https://github.com/phuryn/product-engineering/tree/main/agent-harness/skills/guardrail-hooks
Command: npx skills add https://github.com/phuryn/product-engineering --skill guardrail-hooks-phuryn

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Agent instructions written in prose often lose to competing context the agent has read. When an agent repeatedly breaks a rule despite instructions, moving that rule into code—permission checks, hooks, or script guards—makes enforcement deterministic and unavoidable. ## Core Features & Use Cases - Permission Rules: Block commands by pattern (e.g., Bash(gh repo delete *)) checked against every subcommand, even inside loops and subshells. - PreToolUse Hooks: Guard irreversible or public actions (GitHub deletes, npm publishes) by scanning command text and inline scripts before execution. - Commit Identity Guard: Prevent commits authored with a forbidden email address while still allowing searches for that address. - Use Case: An agent keeps deleting production posts by mistake. Wire a hook that asks before any public delete runs, forcing explicit human approval for each one-way door. ## Quick Start Copy the guard scripts into .claude/hooks/, replace the example rules with your own one-way doors and blocked identities, run the test file to validate them, then wire both hooks in .claude/settings.json with PreToolUse matchers and onFailure: block.

Frequently Asked Questions about guardrail-hooks

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I block an agent from deleting production resources?▼

Wire a PreToolUse hook that scans the command for deletion patterns (e.g., `gh repo delete`) and exits with code 2, blocking the call. The hook runs before the agent executes, making the block impossible to work around through retries or rephrasing.

What is the difference between a permission rule and a hook?▼

Permission rules match command patterns in settings and block or ask without running any script; they are checked inside subshells and loops. Hooks run arbitrary code to inspect arguments, heredoc bodies, and local scripts, allowing complex logic like blocking an email only on commits, not on log searches.

Can hooks see all the ways an agent might run a dangerous command?▼

Hooks have blind spots: `python -c` inline code, scripts run after `cd`, piped code, and paths with spaces are not always visible to PreToolUse. For complete coverage of inline code, also list patterns under `command_rules` so they trigger on the mention alone.

Why do hooks sometimes let through actions they should block?▼

Common causes are typos in the settings path (hook never runs), invalid JSON output (unreadable decision), or the action reaching a tool outside the hook's scope—MCP tools, browser clicks, or hosted services. Always test with canaries and check the debug log for `hook error` notices.

How do I prevent an agent from committing with the wrong identity?▼

Use `block_wrong_identity.py` to exit 2 when a forbidden email appears in `git config user.email`, `-c user.email=`, environment variables, or `--author` flags. Searching for the address with grep or `git log` is still allowed, so cleanup is possible.

What should I do if a hook blocks legitimate work?▼

Narrow the rule by matching only what the owner would actually want to click for—the original guard fired on heredocs merely mentioning a command and was cut down the same day. Use look-alike test cases in `test_hooks.py` to catch over-broad rules before deploying.