DEV Community

Sangmin Lee
Sangmin Lee

Posted on • Originally published at claudeguide.io

Claude Code Hooks: Automate and Control Every Tool Call

Originally published at claudeguide.io/claude-code-hooks

Claude Code Hooks: Automate and Control Every Tool Call

Claude Code hooks are shell commands that execute automatically before or after tool calls. They give you programmatic control over what Claude Code does — logging every file it touches, blocking certain edits, running formatters after writes, or sending Slack notifications on commit in 2026.

This guide covers every hook type, how to configure them, and 12 production examples.

What hooks are

Every time Claude Code calls a tool (Read, Edit, Write, Bash, etc.), two hook points fire:

  • PreToolUse: before the tool executes — can block the call by exiting non-zero
  • PostToolUse: after the tool executes — receives the result, can trigger side effects

Hooks are configured in your Claude Code settings (~/.claude/settings.json for user-level, or .claude/settings.json for project-level). Project-level settings override user-level for the hooks they define. For a full reference of all settings fields, see the Claude Code settings.json reference.

Hook configuration format


json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "echo \"Running bash: $CLAUDE_TOOL_INPUT\" 

40 slash command templates. Token-optimized variants. JSONL file for direct import. Tested in production sessions.

[→ Get Claude Code Power Prompts 300 — $29](https://shoutfirst.gumroad.com/l/agfda?utm_source=claudeguide&utm_medium=article&utm_campaign=claude-code-hooks)

*30-day money-back guarantee. Instant download.*
Enter fullscreen mode Exit fullscreen mode

Top comments (0)