Do pre-commit hooks run when an AI coding agent commits?
Yes: when an AI coding agent runs git commit, git runs your pre-commit hook and aborts the commit if it fails. But git commit --no-verify (or -n) skips it, so forbid that in AGENTS.md, or block it with an agent hook.
By Himanshu Singh · Updated · How we score →
How many repos use pre-commit hooks?
Of the 434 repos on the leaderboard, 131 pass in full (30%), 0 pass in part (0%) and 303 fail (70%). By framework: pre-commit 64, Husky 49, Lefthook 8, package.json hooks 8, other 2.
Why do pre-commit hooks help AI coding agents?
A hook runs the formatter and linter at commit time, so an agent learns of a problem in seconds, not minutes later from a failed CI run.
How do I stop an agent skipping the hooks?
- Say in AGENTS.md that
--no-verifyis off limits: when a hook fails, fix the cause and commit again. - To enforce it in Claude Code, a
PreToolUsehook onBashthat exits with code 2 blocks the command and sends its stderr back to Claude (last snippet below). - In Cursor, a
beforeShellExecutionhook in.cursor/hooks.jsoncan answer"permission": "deny"to the same command. - Agent hooks also catch problems before commit time: Claude Code's
PostToolUseor Cursor'safterFileEditcan format each file as it is edited, and aStophook keeps Claude working until a check passes. - OpenHands' docs move
.openhands/pre-commit.shchecks into Stop hooks in.openhands/hooks.json.
| Git pre-commit hook | Claude Code hook | Cursor hook | |
|---|---|---|---|
| Config | .pre-commit-config.yaml, .husky/, lefthook.yml | .claude/settings.json | .cursor/hooks.json |
| Runs | On git commit, whoever commits | On agent events: PreToolUse, PostToolUse, Stop | On agent events: beforeShellExecution, afterFileEdit, stop |
| Skipped by | --no-verify or -n | No flag | No flag |
.pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
hooks:
- id: ruff
- id: ruff-format
Husky + lint-staged
npx husky init
echo "npx lint-staged" > .husky/pre-commit
# package.json
"lint-staged": { "*.{js,ts,tsx}": ["eslint --fix", "prettier --write"] }
lefthook.yml
pre-commit:
commands:
lint:
glob: "*.{js,ts,tsx}"
run: npx eslint --fix {staged_files}
stage_fixed: true
.claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "jq -r '.tool_input.command' | grep -q -- '--no-verify' && { echo 'Fix the failing hook instead of skipping it' >&2; exit 2; } || exit 0"
}
]
}
]
}
}
131 of 434 leaderboard repos pass this check in full (30%). Sources: git-scm.com/githooks (new tab), code.claude.com/hooks (new tab), cursor.com/hooks (new tab), pre-commit.com (new tab), typicode.github.io/get-started.html (new tab), github.com/lint-staged (new tab), lefthook.dev/configuration (new tab), docs.openhands.dev/repository (new tab).
What counts as pre-commit hooks?
- Full pass: a config at the repo root for pre-commit or prek, Husky (
.husky/, or thehuskykey older versions read frompackage.json), Lefthook, simple-git-hooks, yorkie, overcommit, CaptainHook, GrumPHP, rusty-hook, cargo-husky or hk. - Fail: none. Hooks set up any other way, such as a script that writes to
.git/hooks, are not detected.
How checks become a score: methodology.
How do I add pre-commit hooks to my repo?
Add one of the configs above, running the formatter and linter on staged files. Keep it fast; slow checks belong in CI.
Which AI coding agents weigh pre-commit hooks most?
- OpenHands6% of its score
- Devin6% of its score
- Pi5% of its score
- Claude Code5% of its score
- Kimi Code CLI5% of its score
- Codex5% of its score
- Gemini CLI4% of its score
- Aider4% of its score
- Cursor3% of its score
Pass rate by language
- Python40 of 56 (71%)
- TypeScript49 of 88 (56%)
- JavaScript8 of 16 (50%)
- Ruby5 of 11 (45%)
- C++6 of 21 (29%)
- Rust10 of 47 (21%)
- Clojure1 of 5 (20%)
- Scala1 of 6 (17%)
- Go6 of 41 (15%)
- Elixir1 of 7 (14%)
- C1 of 10 (10%)
- PHP1 of 14 (7%)
- Java1 of 32 (3%)
- Kotlin0 of 15 (0%)
- Swift0 of 14 (0%)
- C#0 of 12 (0%)
- Dart0 of 12 (0%)
- Haskell0 of 7 (0%)
- Zig0 of 6 (0%)
Top-scoring repos that pass
- Ruby · 48.1k ★
- Rust · 6.8k ★
- PostHog/posthog91.2Python · 41.2k ★
- novuhq/novu91.2TypeScript · 40.4k ★
- jdx/mise91.2Rust · 36.6k ★
- TypeScript · 136.4k ★
- Python · 68.4k ★
- TypeScript · 395.3k ★
- vercel/next.js89.5JavaScript · 143.8k ★
- astral-sh/ruff89.5Rust · 51.6k ★
- apache/airflow89.5Python · 47.7k ★
- getsentry/sentry89.5Python · 45.9k ★
Popular repos that fail it
- react/react75.4JavaScript · 253k ★
- TypeScript · 211.5k ★
- microsoft/vscode82.6TypeScript · 195.9k ★
- ollama/ollama82.6Go · 188.3k ★
- flutter/flutter72.0Dart · 181.6k ★
- Python · 169.4k ★
- Python · 165.4k ★
- TypeScript · 157.3k ★
Every check, grouped into what to do first: how to make your repo ready for AI coding agents.