resources

Hooks run outside the LLM loop.Deterministic. Zero token cost. Total control.

Advanced Hooks Mastery

Hooks run outside the LLM loop.Deterministic. Zero token cost. Total control.

Hooks intercept every tool call, session event, and notification before or after it happens. No AI reasoning involved. Pure logic gates you define.

The Complete Event System

Every hook fires on a specific lifecycle event. 8 events cover the entire Claude Code runtime, from session start to teardown.

The Exit Code System

Your hook's exit code tells Claude what to do next. Three possible outcomes, each with different behavior.

Context Injection

When a hook returns JSON to stdout, Claude reads it as a message. This creates a feedback loop where your tools inform the AI without spending tokens on reasoning.

The 3 Hook Types

Most people only know shell scripts. Two more types exist and they unlock patterns that shell scripts cannot reach.

Type A: Shell Script Hooks

A shell script that runs on the event. Receives tool input via environment variables. Returns exit code + optional JSON.

  • Full access to the filesystem and CLI tools
  • Can run any language (bash, python, node)
  • Best for: file ops, linting, git checks, system commands

Type B: HTTP Hooks

Instead of running a script, send an HTTP request to an endpoint. The response body becomes the hook output. Perfect for integrating with external systems.

  • Trigger Slack notifications on specific events
  • Update Notion pages when files change
  • Log to analytics or monitoring dashboards
  • Call webhooks on any platform

Type C: Prompt Hooks

Run an LLM on the hook event data. The prompt receives the tool input and returns a judgment. Use this for nuanced decisions that regex cannot handle.

  • AI code reviewer before every bash execution
  • Semantic safety checks on file writes
  • Context-aware permission decisions
  • Natural language policy enforcement

Async Hooks

Add "async": true and the hook runs in the background. Claude does not wait for it. Use for fire-and-forget operations.

When to use async

Logging to external services, analytics tracking, sending notifications, syncing state. Anything where you do not need the result to decide whether to proceed.

Matcher Patterns

Matchers filter which tool calls trigger your hook. Click any pattern below to highlight it.

Matcher Builder

Select a tool and optional filter to generate the matcher JSON.

The 10 Most Powerful Hook Patterns

Production-ready patterns. Each one is a full implementation you can copy and use immediately.

After Claude edits a JS/TS file, ESLint runs automatically. If errors are found, the results are returned as JSON context. Claude reads the errors and fixes them in the next turn without you asking.

Every time Claude finishes a response, this hook logs the session cost to a daily log file. Over time, you build a complete cost history across all sessions.

When working on Client A, block any write to Client B's folder. Prevents cross-contamination of client data during multi-project sessions.

Intercepts git commit commands and scans staged files for API keys, tokens, passwords, and other secrets. Blocks the commit if anything suspicious is found.

Combines a shell hook to detect config file changes with an HTTP hook to send a Slack notification. Two hooks chained on the same event.

A prompt hook that runs an LLM judgment on every bash command. For high-risk environments where regex patterns are not enough and you need semantic understanding of intent.

Before Claude edits any file, create a timestamped backup. Keeps the last 10 versions. Cheap insurance against bad edits.

After a git push, extract the branch name (which contains the Jira ticket ID) and update the ticket status via Jira API. Keeps project management in sync automatically.

Plays a sound and shows a macOS notification when Claude finishes responding. Walk away from your desk and know when to come back.

When a session starts, gather dynamic context (git status, open PRs, current branch, recent commits) and inject it as a JSON message. Claude starts every session already knowing the project state.

Hook Builder

Configure your hook and get ready-to-paste code. Select your options, generate the settings.json snippet and the shell script.

Knowledge Check

5 questions. Test what you just learned.

Q1: What exit code blocks a tool call?

Q2: What makes async hooks different from regular hooks?

Q3: What is a "prompt hook" used for?

Q4: If a PostToolUse hook returns JSON with a message, what happens?

Q5: Which hook event fires when Claude finishes a response?

don't miss what's next.

playbooks, templates, and tools that actually save you hours. straight to your inbox. no spam. unsubscribe anytime.

Want this running in your business, not just your terminal? Our Claude Code development agency ships it for you, or book a free consultation to scope your setup.

Day 34: FIRE CEO OS: Run a Company From a Terminal

Day 36: Agent Swarms: Coordinate Multiple Agents

Ready to transform your business?

Let’s turn your next automation opportunity into a system that works.

Book a Free Strategy Call