Skip to main content

Hook Event Handlers

Medium COPILOT:S:0006
copilot · structure · mechanical

A "hooks" block in .github/hooks/*.json must list at least one handler under an event. A handler names what it runs: a "type", or one of "bash", "powershell", "command", or "exec". Copilot runs a handler with no "type" as a command, so { "bash": "./scripts/guard.sh" } is a complete handler. A file with no "hooks" key is not this rule's concern.

Antipatterns

  • Empty hooks block. Declaring "hooks": {} or an event with an empty list, so no handler is registered.
  • Handler that runs nothing. Listing an object such as { "timeoutSec": 30 } with no type and no executable field.

Pass / Fail

Pass

{
  "version": 1,
  "hooks": {
    "preToolUse": [{ "bash": "./scripts/guard.sh", "powershell": "./scripts/guard.ps1" }]
  }
}

Fail

{ "version": 1, "hooks": { "preToolUse": [] } }

Limitations

Looks for a "type", "bash", "powershell", "command", or "exec" field inside the "hooks" block itself, not in an unrelated key after it. Does not check that the executable exists or that the event name is valid; the command-field and event-type rules cover those.