Contact Us
Webflow Premium Partner Ehab Fayez
Back to MCP & Tools
Security & Quality Featured

Hooks

Deterministic control over agent behavior — run a formatter after every edit or block dangerous commands before they execute.

Claude Code

Overview

Hooks are shell commands that execute automatically at defined points of the agent loop: before a tool call (PreToolUse), after it (PostToolUse), when a response finishes (Stop), and more. The key difference from written instructions: a hook always runs — it is not a suggestion the model can forget.

The most common uses: auto-running Prettier or ESLint on every file the agent edits, blocking dangerous Bash commands (rm -rf and friends) before execution, logging every operation for audits, or sending a notification when a long task completes.

A PreToolUse hook can return an exit code that blocks execution — making hooks a real security layer: your policies are enforced at the system level, not by model goodwill.

Who Is This For?

  • Enforcing formatting and linting automatically on every edit
  • Blocking dangerous commands or writes to sensitive files
  • Keeping an audit log of all agent operations
  • Notifications when long-running tasks complete

Installation

Setup for Claude Code
Add a hooks block to .claude/settings.json — e.g. run Prettier after every file edit (PostToolUse) or block dangerous Bash commands (PreToolUse).

Configuration

{"hooks":{"PostToolUse":[{"matcher":"Edit|Write","hooks":[{"type":"command","command":"npx prettier --write "$CLAUDE_FILE_PATHS""}]}]}}

Subscribe on YouTube

138K+ subscribers

Subscribe