Git Hooks
AIDF includes git hooks that validate your workflow automatically at commit and push time.
What the Hooks Do
Section titled “What the Hooks Do”| Hook | Purpose |
|---|---|
pre-commit | Validates staged files against active task scopes (forbidden paths) |
commit-msg | Validates conventional commit message format |
pre-push | Runs configured validation commands (lint, typecheck, tests) |
Quick Start
Section titled “Quick Start”# Install hooks (auto-detects husky if present)aidf hooks install
# Remove hooksaidf hooks uninstallInstallation Methods
Section titled “Installation Methods”Direct Git Hooks
Section titled “Direct Git Hooks”If your project does not use husky or pre-commit, AIDF installs hooks directly into .git/hooks/:
aidf hooks installThis creates executable scripts in .git/hooks/pre-commit, .git/hooks/commit-msg, and .git/hooks/pre-push.
Use --force to overwrite existing hooks:
aidf hooks install --forceHusky Integration
Section titled “Husky Integration”AIDF auto-detects husky by checking for:
- A
.husky/directory huskyinpackage.jsondependencies- A
preparescript containinghusky
When husky is detected, hooks are installed in .husky/ instead of .git/hooks/.
You can also force husky mode:
aidf hooks install --huskySetting up husky from scratch
Section titled “Setting up husky from scratch”If your project doesn’t have husky yet:
npm install --save-dev huskynpx husky initaidf hooks install --huskyExample: husky + lint-staged + AIDF
Section titled “Example: husky + lint-staged + AIDF”A common setup combines husky, lint-staged, and AIDF hooks:
{ "scripts": { "prepare": "husky" }, "lint-staged": { "*.{ts,tsx}": ["eslint --fix", "prettier --write"], "*.{json,md}": ["prettier --write"] }}.husky/pre-commit:
npx lint-staged# AIDF - scope and format validationnpx aidf-hook-pre-commitWhen AIDF detects existing hooks, it appends its validation rather than replacing the file.
pre-commit Framework (Python)
Section titled “pre-commit Framework (Python)”For projects using the pre-commit framework:
aidf hooks install --pre-commitThis generates a .pre-commit-config.yaml (or appends to an existing one):
repos: - repo: local hooks: - id: aidf-scope-check name: AIDF Scope Validation entry: npx aidf-hook-pre-commit language: system always_run: true - id: aidf-commit-msg name: AIDF Commit Message Format entry: npx aidf-hook-commit-msg language: system stages: [commit-msg]Then activate with:
pre-commit installHook Details
Section titled “Hook Details”pre-commit: Scope Validation
Section titled “pre-commit: Scope Validation”The pre-commit hook reads all active (non-completed) task files in .ai/tasks/ and checks staged files against their forbidden path patterns.
Behavior depends on the scopeEnforcement setting in .ai/config.yml:
| Mode | Behavior |
|---|---|
strict | Blocks commit if any staged file matches a forbidden pattern |
ask | Shows a warning but allows the commit |
permissive | Skips validation entirely |
commit-msg: Format Validation
Section titled “commit-msg: Format Validation”Validates that commit messages follow Conventional Commits:
type(scope?): descriptionValid types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
Examples:
feat: add user authenticationfix(api): resolve timeout issuedocs: update READMErefactor(auth): simplify token validationMerge and revert commits are allowed without validation.
The hook also warns (but does not block) if the header exceeds 72 characters.
pre-push: Validation Commands
Section titled “pre-push: Validation Commands”Runs validation commands from .ai/config.yml before pushing:
validation: lint: npm run lint typecheck: npm run typecheck test: npm run testIf any command fails, the push is blocked.
Uninstalling
Section titled “Uninstalling”aidf hooks uninstallThis removes only AIDF-generated hooks. If AIDF was appended to an existing husky hook, only the AIDF block is removed.