Setting up hooks for Claude Code
Failproof AI integrates with Claude Code via its hooks system. When you runfailproofai policies --install, it registers hook commands in Claude Code’s settings.json that fire on every tool call.
Verify hooks are registered
PreToolUse, PostToolUse, Notification, and Stop events.Setting up hooks for the Agents SDK
If you’re building with the Agents SDK, you can use the same hook system programmatically.Configure hooks in your agent
Pass hook commands when creating your agent process. The hooks fire the same way as in Claude Code - via stdin/stdout JSON:
Block destructive commands
The most common setup - prevent agents from doing irreversible damage.block-sudo- blocks allsudocommandsblock-rm-rf- blocks recursive file deletionblock-force-push- blocksgit push --forceblock-curl-pipe-sh- blocks piping remote scripts to shell
Prevent secret leakage
Stop agents from seeing or leaking credentials in tool output.PostToolUse - after a tool runs, they scrub the output before the agent sees it.
Get Slack alerts when agents need attention
Use the notification hook to forward idle alerts to Slack.Keep agents on a branch
Prevent agents from switching branches or pushing to protected ones.Require tests before commits
Remind agents to run tests before committing.Lock down a production repo
Commit a project-level config so every developer on your team gets the same policies. Create.failproofai/policies-config.json in your repo:
More examples
Theexamples/ directory in the repo contains:
| File | What it shows |
|---|---|
policies-basic.js | Starter policies - block production writes, force-push, piped scripts |
policies-notification.js | Slack alerts for idle notifications and session end |
policies-advanced/index.js | Transitive imports, async hooks, PostToolUse output scrubbing, Stop event handling |

