Run Archgate ADR compliance checks before every commit with native git hooks or a hook manager. Catch architecture violations before they reach CI.
A pre-commit hook runs archgate check --staged before each commit, so architecture violations are caught on the developer’s machine — before they ever reach a pull request. Because --staged checks only the files in the git staging area, the hook stays fast enough for everyday use.
This guide shows the native git-hook approach plus the two common hook managers. For the full flag reference, see the CLI pre-commit guide at cli.archgate.dev.
Why --staged
Section titled “Why --staged”archgate check --staged restricts evaluation to git-staged files:
- A project with hundreds of source files but three staged files checks only those three.
- Rules whose
filesglobs match nothing in the staging area are skipped entirely. - Typical pre-commit checks complete in under a second.
When a rule fails, the command exits with code 1 and the commit is blocked. Violations print to stderr with the ADR ID, rule name, file path, and line number, so you can locate and fix them immediately. Re-stage with git add and commit again.
Native git hook
Section titled “Native git hook”No extra tooling required — git looks for an executable at .git/hooks/pre-commit:
Create the hook and make it executable:
cat > .git/hooks/pre-commit <<'EOF'#!/bin/sharchgate check --stagedEOFchmod +x .git/hooks/pre-commitGit for Windows runs hooks through its bundled shell, so a POSIX sh script works. Create the file with a shebang and no .ps1 extension:
@'#!/bin/sharchgate check --staged'@ | Set-Content -NoNewline .git/hooks/pre-commitHook managers
Section titled “Hook managers”Hook managers store hook configuration in a committed file, so every clone of the repo gets the same hooks. Both managers below run archgate check --staged exactly as the native hook does.
Lefthook is a fast, cross-platform git hooks manager. Add the check to lefthook.yml:
pre-commit: commands: adr-check: run: archgate check --stagedThen install the hooks:
lefthook installHusky is a popular git hooks tool for Node.js projects. Add the check to the pre-commit hook:
archgate check --stagedEnsure the hook is executable:
chmod +x .husky/pre-commitRunning alongside other hooks
Section titled “Running alongside other hooks”Pre-commit hooks usually run several checks. Each command runs independently, and the commit is blocked if any exits non-zero. With Lefthook:
pre-commit: commands: lint: run: npm run lint typecheck: run: npm run typecheck adr-check: run: archgate check --stagedUseful flags
Section titled “Useful flags”The check command takes the same flags here as elsewhere; these are the ones relevant to hooks. The complete list lives in the CLI reference.
| Flag | Purpose |
|---|---|
--staged | Check only git-staged files — required for pre-commit |
--verbose | Show passing rules and timing — helpful when debugging why a hook is slow |
--adr <id> | Check rules from a single ADR — useful for isolating one rule while debugging |
--json | Emit JSON — for piping to custom reporting scripts |