Skip to content
Agent Friendly Code

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-verify is off limits: when a hook fails, fix the cause and commit again.
  • To enforce it in Claude Code, a PreToolUse hook on Bash that exits with code 2 blocks the command and sends its stderr back to Claude (last snippet below).
  • In Cursor, a beforeShellExecution hook in .cursor/hooks.json can answer "permission": "deny" to the same command.
  • Agent hooks also catch problems before commit time: Claude Code's PostToolUse or Cursor's afterFileEdit can format each file as it is edited, and a Stop hook keeps Claude working until a check passes.
  • OpenHands' docs move .openhands/pre-commit.sh checks into Stop hooks in .openhands/hooks.json.
Git hooks compared with Claude Code and Cursor hooks
Git pre-commit hookClaude Code hookCursor hook
Config.pre-commit-config.yaml, .husky/, lefthook.yml.claude/settings.json.cursor/hooks.json
RunsOn git commit, whoever commitsOn agent events: PreToolUse, PostToolUse, StopOn agent events: beforeShellExecution, afterFileEdit, stop
Skipped by--no-verify or -nNo flagNo 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 the husky key older versions read from package.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?

Pass rate by language

Top-scoring repos that pass

Popular repos that fail it

Every check, grouped into what to do first: how to make your repo ready for AI coding agents.