Alexander Thiele

Alexander Thiele

Techi 👨‍💻 Startup Enthusiast, Entrepreneur, Co-Founder. Creating Company & Engineering Culture & Flutter fan 🤓

Claude Hook Configuration: settings.json#

The PostToolUse hook is registered in the .claude/settings.json file. This configuration tells Claude which tools should trigger the hook and what command to execute.

Configuration Details#

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/after_edit.sh"
          }
        ]
      }
    ]
  }
}

Key Elements:#

  • PostToolUse: This hook runs after a tool has been executed but before the result is returned to the model (if it's a blocking hook).
  • matcher: "Write|Edit": This regex-like matcher ensures the hook only triggers when Claude uses tools like write_to_file or edit_file.
  • type: "command": Specifies that the hook will run an external shell command.
  • command: The absolute path to the shell script. Using $CLAUDE_PROJECT_DIR makes the path relative to the project root, ensuring portability.