Hook Configuration in AI

From the Claude Code cheat sheet ยท Hooks System ยท verified Jul 2026

Hook Configuration

Setting up hooks in settings.json

json
# ~/.claude/settings.json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "jq -r '\"Running: \" + .tool_input.command' >> ~/.claude/log.txt"
          }
        ]
      }
    ],
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "python3 ~/.claude/hooks/validate_prompt.py"
          }
        ]
      }
    ]
  }
}
json
// EXAMPLE: Log all bash commands
{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Bash",
      "hooks": [{
        "type": "command",
        "command": "date >> ~/.claude/bash.log && echo '{{tool_input.command}}' >> ~/.claude/bash.log"
      }]
    }]
  }
}
๐Ÿ“Œ Matcher filters by tool name
๐Ÿ” Can run commands or scripts
๐Ÿ“Œ Access tool data via placeholders
hooksconfig

Continue with Claude Code

Save the full cheat sheet or work through every related task.

More AI tasks

Back to the full Claude Code cheat sheet