Skip to content
This project is under active development and subject to breaking changes. See the changelog for release notes.

Hooks

Hooks are lifecycle scripts that run automatically at specific points during agent execution. They are external bash scripts with zero LLM context cost. They execute outside the model and return results via JSON.

TypeWhenPurpose
sessionStartNew agent session beginsAuto-detection, environment setup
postToolUseAfter an agent uses a toolValidation, linting
sessionEndSession endsCleanup

Configuration lives in hooks.json with command path and timeout (default 30 seconds).

detect-repo-platform.sh

Type: sessionStart (10s timeout)

Checks git remote URL. Classifies as GitHub (github.com) or Azure DevOps (dev.azure.com / visualstudio.com). Seeds .memory/board-config.md.

detect-branching-strategy.sh

Type: sessionStart (10s timeout)

Analyzes branch naming patterns. Identifies GitFlow (develop/release/hotfix branches) or Trunk-based (main/feature branches). Seeds .memory/git-config.md.

detect-tool-extensions.sh

Type: sessionStart (10s timeout)

Checks if consumer tool extensions are synced with the current plugin version. Warns if extensions are stale or unsynced.

validate-work-item-tags.sh

Type: postToolUse (10s timeout)

After work item creation or update, validates required tags: copilot-generated and ai-model:*. Ensures AI traceability.

lint-markdown.sh

Type: postToolUse (10s timeout)

Runs markdownlint against .markdownlint.yaml config after markdown file edits. Reports formatting issues.

PostToolUse validation hooks return structured JSON designed for agent self-correction. Hooks that validate or lint agent output must produce output following this contract:

{
"decision": "block | warn | info",
"reason": "Human-readable summary of what was found",
"instructions": "Step-by-step fix instructions the agent should follow",
"files": ["path/to/affected/file"],
"severity": "critical | major | minor"
}
FieldRequiredDescription
decisionYesblock = agent must fix before continuing. warn = agent should fix but may continue. info = informational only.
reasonYesWhat was found, in plain language
instructionsYesActionable steps the agent should take to fix the issue. This is the key field: it tells the agent how to fix, not just what broke.
filesNoArray of affected file paths (empty array if not file-specific)
severityNocritical, major, or minor. Defaults to minor if omitted.

Hooks return JSON on stdout with results. Stderr is used for descriptive error messages. All hooks must:

  • Include a bash shebang (#!/bin/bash or #!/usr/bin/env bash)
  • Output JSON on a single line (use jq -nc to construct)
  • Complete within their configured timeout. Built-in hooks use a 10-second timeout. The schema default is 30 seconds, configurable per hook via timeoutSec
  • Be idempotent (safe to run multiple times)