Back to Hooks

build-on-change

AutomationยทPostToolUse

Automatically trigger build processes when source files change

Matcher: Edit

Configuration

Add to your .claude/settings.json:

{
  "hooks": {
    "PostToolUse": [
      {
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/build-on-change.sh"
          }
        ],
        "matcher": "Edit"
      }
    ]
  }
}

This hook includes a script file. Download the ZIP bundle for complete installation with script and instructions.

Hook Details


build-on-change


Automatically trigger build processes when source files change


Event Configuration


  • **Event Type**: `PostToolUse`
  • **Tool Matcher**: `Edit`
  • **Category**: automation

  • Environment Variables


  • `CLAUDE_TOOL_FILE_PATH`
  • `CLAUDE_PROJECT_DIR`

  • Requirements


  • Build tool appropriate for your project (npm, make, etc.)

  • Script


    ```bash

    file_path=$(jq -r '.tool_input.file_path // empty')

    if [[ "$file_path" =~ \.(ts|tsx|js|jsx)$ ]]; then

    npm run build 2>/dev/null || true

    elif [[ "$file_path" =~ \.(c|cpp|h|hpp)$ ]]; then

    make 2>/dev/null || true

    fi

    ```

    About PostToolUse Hooks

    PostToolUse hooks run after a tool completes execution. They can modify the result or trigger additional actions.