
A short Stop hook that runs the test suite when Codex tries to finish, feeds the failure back as the next prompt, and gives up after three tries. Ten minutes to wire in.

The agent hit an API error halfway through a job and nobody knew until morning. This setup records why it stopped, retries the errors that time fixes and stops on the ones that don't. About fifteen minutes to set up.

Claude Code now tells hooks what a /model switch will cost before it happens. A 40-line script turns that into a confirmation, a hard refusal for unattended sessions and a ledger.

In a headless run there's nobody to read the denial notice. A 25-line hook turns every auto-mode refusal into a ledger you can query in the morning. Ten minutes to wire up.

A PostToolUse hook with asyncRewake runs your suite after each edit without blocking the agent, stays silent on a pass and wakes Claude Code with a trimmed failure report on a fail. Fifteen minutes to set up.

One 60-line hook rebuilds the agent's bearings from git and a plan file after /clear and compaction, and puts a price on resuming a cold session. About fifteen minutes to set up.

Claude Code's /rewind only restores files its own edit tools touched. A 40-line UserPromptSubmit hook gives you a restore point for everything else, and it takes five minutes to set up.

Tell an agent a test is flaky and it will add a retry. This setup makes it measure the failure rate, replay a failing seed and prove the fix, and it blocks the commit if the 'fix' is a retry, a sleep or a skip. About 15 minutes to try.

Version 2.1.307 added a telemetry event for each call a rule, hook or sandbox blocked. Point it at a 45-line local receiver and a 34-line report, and you can see what your guardrails actually do. About 15 minutes.

Two small scripts log every instruction file a session pulls in, why it loaded and what it costs, then flag the rules that never fire. About 15 minutes to set up.

A fresh worktree has no .env, no node_modules and the same port as the session next to it. Two small hook scripts fix all three and clean up safely. About 15 minutes to set up.

A 70-line script, a pre-commit hook and one CI step catch the frontmatter mistakes Claude Code skips without telling you. About 15 minutes to set up.

Codex hooks are on by default in 0.163.0. Here's a 40-line guard, the config that wires it in, the trust step that silently skips it, and the failures that let a command through.

A deny hook makes the agent stop and try something else. A rewrite hook fixes the command and lets the work continue. Ten minutes to build, with the failure cases shown.

One 50-line script stops AWS keys, GitHub tokens, private keys and connection strings leaving your terminal, and puts the repo state into every other prompt. About 15 minutes, and the gaps are listed.

A /spec skill, a 50-line checker and one PreToolUse hook that stops the agent writing code outside a spec you've signed off. About 15 minutes to set up.

A /work-issue skill, five permission rules and a 40-line hook turn a ticket into a questioned, planned, tested draft pull request. About 15 minutes to set up.

The Claude Code hooks reference now documents the option that closes the fail-open gap. Nine broken hooks, run for real, show where the protection ends.

A commit and push gate that an agent can't skip with --no-verify, plus a Stop hook that won't let it call red code finished. Fifteen minutes to set up.

A hook that crashes, times out or can't start lets the action through by default. Ten minutes to find out which of your gates are really gates.

Permission prompts depend on what mode you're in. A PreToolUse deny hook doesn't. Here's a small one that blocks force pushes, and where it falls short.

A Stop hook turns 'please run the tests' from a request into a rule. Here's a working setup and the trap to avoid.