## Introduction

Les hooks Claude Code permettent d'executer des scripts automatiquement avant ou apres certaines operations. SmartStack CLI inclut des hooks pre-configures pour la validation des migrations EF Core et la securite.

Claude Code hooks allow running scripts automatically before or after certain operations. SmartStack CLI includes pre-configured hooks for EF Core migration validation and security.

## Types de hooks Hook Types

Hook | Declenchement Trigger | Usage
--- | --- | ---
`PreToolUse` | Avant l'execution d'un outil Before tool execution | Validation, securite Validation, security
`PostToolUse` | Apres l'execution d'un outil After tool execution | Logging, notifications
`SessionStart` | Au demarrage de la session At session start | Setup environnement Environment setup
`Stop` | A la fin de la session At session end | Cleanup, rapports Cleanup, reports

## Configuration

Les hooks sont configures dans `~/.claude/hooks/hooks.json` :

Hooks are configured in `~/.claude/hooks/hooks.json`:

    {
      "hooks": {
        "PreToolUse": [
          {
            "matcher": "Bash",
            "hooks": [
              {
                "type": "command",
                "command": "node ~/.claude/scripts/validate-command.js"
              }
            ]
          }
        ],
        "PostToolUse": [
          {
            "matcher": "Write",
            "hooks": [
              {
                "type": "command",
                "command": "echo 'File written: $TOOL_OUTPUT'"
              }
            ]
          }
        ]
      }
    }

## Hook: EF Core Migration Check Hook: EF Core Migration Check

Ce hook pre-commit detecte les operations destructives dans les migrations EF Core et bloque le commit si necessaire.

This pre-commit hook detects destructive operations in EF Core migrations and blocks the commit if necessary.

### Operations BLOQUANTES

### BLOCKING Operations

### Comportement

### Behavior

    $ git commit -m "Add migration"

    Scan des migrations EF Core...
    Analyse: Migrations/20240120_RemoveUsers.cs

    OPERATIONS DESTRUCTIVES DETECTEES:
    ────────────────────────────────────────────────
      15: DropTable(name: "Users");
      23: DropColumn(name: "Email", table: "Profiles");
    ────────────────────────────────────────────────

    COMMIT BLOQUE - OPERATIONS DESTRUCTIVES DETECTEES

    ACTIONS REQUISES :
    1. Verifier que vous avez un BACKUP des donnees
    2. Confirmer que cette suppression est intentionnelle
    3. Utiliser --no-verify pour bypasser ce check

### Bypass

    # Option 1 : Flag no-verify
    git commit --no-verify -m "Drop users table (intentional)"

    # Option 2 : Variable environnement
    EF_MIGRATION_FORCE=1 git commit -m "message"

## Creer un hook personnalise Create a custom hook

    {
      "hooks": {
        "PreToolUse": [
          {
            "matcher": "Bash",
            "hooks": [
              {
                "type": "command",
                "command": "node my-validation-script.js",
                "blocking": true
              }
            ]
          }
        ]
      }
    }

💡

##### Variables d'environnement

##### Environment variables

Les hooks ont acces a `$TOOL_NAME`, `$TOOL_INPUT`, `$TOOL_OUTPUT`, et `$CLAUDE_PLUGIN_ROOT`.

Hooks have access to `$TOOL_NAME`, `$TOOL_INPUT`, `$TOOL_OUTPUT`, and `$CLAUDE_PLUGIN_ROOT`.

## mcp-check

`mcp-check` MCP

Verification rapide de la disponibilite MCP avant les appels aux outils MCP. Se declenche sur `mcp__smartstack__*`.

Quick MCP availability check before MCP tool calls. Triggers on `mcp__smartstack__*`.

#### Trigger

    type: tool-use
    pattern: mcp__smartstack__*

`templates/hooks/mcp-check.md`

## docs-drift-check

`docs-drift-check` Warning

Avertissement de derive de documentation lors des commits (non-bloquant). Detecte quand le code change sans mise a jour de la documentation.

Documentation drift warning on commit (non-blocking). Detects when code changes without documentation updates.

#### Trigger

    type: tool-use
    pattern: git commit*

`templates/hooks/docs-drift-check.md`