Back to Hooks

auto-git-add

GitยทPostToolUse

Automatically stage modified files with git add after editing

Matcher: Edit|MultiEdit|Write

Configuration

Add to your .claude/settings.json:

{
  "hooks": {
    "PostToolUse": [
      {
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/auto-git-add.sh"
          }
        ],
        "matcher": "Edit|MultiEdit|Write"
      }
    ]
  }
}

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

Hook Details


auto-git-add


Automatically stage modified files with git add after editing


Event Configuration


  • **Event Type**: `PostToolUse`
  • **Tool Matcher**: `Edit|MultiEdit|Write`
  • **Category**: git

  • Environment Variables


    None required


    Requirements


    None


    Script


    ```bash

    jq -r '.tool_input.file_path // empty' | while read -r file_path; do

    if [[ -n "$file_path" ]] && git rev-parse --git-dir >/dev/null 2>&1; then

    git add "$file_path" 2>/dev/null || true

    fi

    done

    ```

    About PostToolUse Hooks

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