Pre-Commit Hooks for AI-Generated Code: The Best Hooks, Hook Managers and Where AI Review Fits
Coding agents now make many of the commits in a repository, and every one of them passes through the same Git hooks a developer’s commits do. Pre-commit hooks are the cheapest place to stop a formatting error, a broken config file or a leaked key.
Hooks see only what is staged, they can be skipped with one flag, and they cannot tell whether a change follows the team’s rules or does what the ticket asked. The post covers what pre-commit hooks are and how to install them, five tools worth running, six hooks to copy, and where AI code review fits around them.
TL;DR
- Pre-commit hooks run before Git records a commit, and a failing hook stops it. Keep them to fast, deterministic checks such as formatting, linting and secrets.
- Coding agents raise the stakes. Public GitHub commits co-authored with Claude Code leaked secrets at 3.2%, against a 1.5% baseline for all public commits, according to the GitGuardian State of Secrets Sprawl 2026, and a post on agent settings and secrets shows one way it happens.
- Hooks can be skipped with –no-verify and see only the staged diff. Mirror them in CI, and review agent-written code before the pull request and on it.
- Qodo, the AI Code Review Platform, reviews an agent’s local changes with the same engine and team rules it uses on pull requests, then reviews the pull request in Git, so teams catch rule breaks and logic issues before the commit and again before merge.
What Pre-Commit Hooks Are and How to Install Them
A pre-commit hook is a script Git runs before it asks for a commit message and records the commit. A non-zero exit from the script aborts the commit, and git commit –no-verify bypasses the pre-commit and commit-msg hooks, according to the Git documentation.
Git keeps hooks in .git/hooks, which is not committed. Teams use a hook manager that reads a committed config file and installs the hooks on each clone. With pre-commit, add a .pre-commit-config.yaml, run pre-commit install, and the hooks run on git commit. pre-commit runs hooks on staged files only and stashes unstaged changes while they run. Husky runs whatever the hook script calls, so teams add lint-staged to limit tasks to staged files, and Lefthook passes staged files to a command through {staged_files}.
Two other client-side hooks matter later. The commit-msg hook checks message format, and the pre-push hook runs heavier checks before code leaves the machine. The mechanics have not changed in years, and who makes the commits has.
Why AI-Generated Code Changes the Job of Pre-Commit Hooks
An agent can commit many times in one session, and every slow hook runs on each of those commits. Slow or flaky hooks get skipped, by people and by agents. An agent that hits a failing hook can retry with –no-verify unless the team’s agent settings forbid it, because Git itself will not stop it.
Secrets are the sharpest case. 3.2% of public GitHub commits co-authored with Claude Code leaked a secret, against a 1.5% baseline across all public commits, according to the GitGuardian State of Secrets Sprawl 2026. The report says the gap should not be read as a simple tool failure, because developers still decide what gets accepted and pushed. The report also counts 28.65 million new hardcoded secrets added to public GitHub commits in 2025, up 34% year over year.
Standards are the second gap. Only 34.6% of surveyed developers say agents always follow organizational standards, according to the Qodo State of AI Code Quality 2026. A hook can check a format rule. A hook cannot check “use the shared retry helper” or “never call the payments service directly”.
Green CI plus a “looks good to me” from the coding agent itself is not enough, because architecture decisions and conventions do not show up in existing CI checks. AI review can return a different finding when you re-run the same commit, which is why teams run it in a find-fix loop. A loop belongs in the agent session, and a hook has to pass or fail once.
The shift left idea applies, but the question is no longer which hooks to run. The question is which checks belong in a hook and which belong in review.
What Makes the Best Pre-Commit Hook Setup for AI-Written Code?
The best pre-commit hook setup for AI-written code passes five tests:
- Fast: every hook finishes in seconds on a typical commit, or it moves to pre-push or CI.
- Deterministic: the same input gives the same result. Formatters, linters, file checks and secret scanners pass this test, and judgment-based checks do not.
- Shared: one committed config that every developer and every coding agent runs, not per-person scripts. Local checks that differ from person to person are common when there is no shared review tool.
- Mirrored: the same checks run in CI, because a hook can be skipped and only CI runs for every contributor.
- Paired with review: a review that sees intent, team rules and codebase impact runs before the pull request and again on it. Tune the local review for depth, because the agent can work through every finding, and the PR review for low noise, because people read it.
Qodo is the best choice for reviewing AI-generated code around your pre-commit hooks because it reviews the agent’s local changes with the same engine and team rules it applies on the pull request, uses the intent and ticket context the agent provides, and checks the pull request again in Git.
Teams shipping fast with agents get clean commits without slow hooks. Larger organizations get one shared list of rules across repositories and coding agents, imported from the rule files teams already keep.
The 5 Best Pre-Commit Hooks and Tools for Reviewing AI-Generated Code
- Qodo: review before the commit and on the pull request
- pre-commit: a multi-language hook manager
- Husky with lint-staged: hooks for JavaScript projects
- Lefthook: a fast, polyglot hook manager
- Gitleaks: secrets scanning at commit time
1. Qodo: Review Before the Commit and on the Pull Request
What it does. Qodo is the AI code review platform with high-precision PR review, full codebase context, enforceable rules and local review inside coding agents. The Reviewer skill “enables your coding agent to review local changes before a pull request exists, using the same engine as Qodo Review”.
- Scope: Reviewer covers committed and uncommitted changes and includes new untracked files automatically. Scope a run by git pathspec.
- Context: the agent passes a summary of intent, key decisions and links to the ticket, spec or design. A hook never has that context.
- Depth: choose a fast single-pass review or a deeper review per run, with machine-readable findings for looping workflows. Teams run fast reviews while the agent generates, then a deeper review at the end.
- Output: Reviewer returns findings and does not modify code. Only the base commit you compare against needs to be pushed.
- Where it runs: the CLI (qodo review), MCP, the Claude Code plugin, the Codex plugin and Kiro Power. The CLI code review glossary explains the concept.
- Rules: Rule enforcement imports rules from AGENTS.md, CLAUDE.md, GEMINI.md, .cursorrules, copilot-instructions.md and other files, and keeps them in sync on every push. The rule files guide covers managing them.
- After the PR opens: Qodo reviews it in Git, and the Reviewer docs say pull request review “continues to validate the final, pushed changes and catch anything introduced afterward”.
- Analytics: the code review analytics dashboard shows accepted findings, high-severity acceptance rate and how the team responds to findings raised on pull requests. Local findings are excluded from the other dashboard metrics, and the Where findings were raised view shows how many findings Qodo raised locally and how many on the PR.
Best for. Teams that want agent-written code reviewed against their own rules before it is committed, and again on the PR.
How it compares. Hook managers and scanners run fixed, deterministic checks on staged files. Qodo reviews the change for logic, intent and team rules, in the agent loop and on the PR. Use both.
2. pre-commit: A Multi-Language Hook Manager
What it does. pre-commit calls itself “a multi-language package manager for pre-commit hooks”. Config lives in .pre-commit-config.yaml, pre-commit install writes the Git hook, and pre-commit run –all-files suits CI. pre-commit installs each hook’s toolchain itself, for example Node for ESLint, without root access, and runs on staged contents only. The catalogue includes pre-commit-hooks for file checks, Ruff, Biome, ShellCheck, actionlint and typos.
Best for. Multi-language and Python-heavy repositories that want one hook config.
How it compares. pre-commit has the broadest catalogue. pre-commit runs hooks in sequence per repo config and has a heavier first install than a single binary.
3. Husky With lint-staged: Hooks for JavaScript Projects
What it does. Husky is “just 2 kB (gzipped) with no dependencies”, uses Git’s core.hooksPath and supports all 13 client-side Git hooks. Husky installs through npm’s prepare script, so hooks install on npm install. lint-staged will “run tasks like formatters and linters against staged git files” and restage their changes.
Best for. JavaScript and TypeScript repositories already on npm.
How it compares. It is the lightest option in Node projects. Hooks are shell scripts, so cross-language toolchains are the team’s job.
4. Lefthook: A Fast, Polyglot Hook Manager
What it does. Lefthook is “a Git hooks manager for Node.js, Ruby, Python and many other types of projects”. Lefthook is written in Go as a single dependency-free binary and can run commands in parallel. Config lives in lefthook.yml, lefthook install adds the hooks, and it installs through npm, gem, pipx, Go, brew and others.
Best for. Monorepos and mixed-language teams that want parallel hooks and one binary.
How it compares. Lefthook is fast and flexible about which files each command gets, with a smaller ready-made hook catalogue than pre-commit.
5. Gitleaks: Secrets Scanning at Commit Time
What it does. Gitleaks scans staged changes for hardcoded secrets and ships an official pre-commit hook ID and a Docker variant. Prepending SKIP=gitleaks to the commit command skips it, so also run it in CI. Its README says Gitleaks “is feature complete” and that future releases will be security patches only, and the maintainer has moved to a successor project, Betterleaks, so teams choosing today may evaluate both.
Best for. Every repository where agents write config or integration code.
How it compares. Gitleaks runs deterministic pattern and entropy checks and does not judge code logic. The secure code review tools guide covers SAST and dependency scanning.
| Tool | Job | Runs where | Config file | Deterministic? | Can be skipped? |
| Qodo | Review of logic, intent and team rules | Agent loop and PR | Imported rule files | AI review (reasons about each change) | Runs in the agent loop; PR review runs on every PR when enabled for the repository |
| pre-commit | Multi-language hook manager | Git pre-commit | .pre-commit-config.yaml | Yes | Yes, –no-verify |
| Husky with lint-staged | Hooks and staged-file tasks for JavaScript | Git hooks | .husky scripts, lint-staged config | Yes | Yes, –no-verify |
| Lefthook | Fast, parallel hook manager | Git hooks | lefthook.yml | Yes | Yes, –no-verify |
| Gitleaks | Secrets scanning | Git pre-commit, CI | Gitleaks config | Yes | Yes, SKIP=gitleaks |
Pre-Commit Hooks Examples: 6 Hooks to Run on Every Agent Commit
Each hook ties to a mistake agents make.
- File hygiene: trailing-whitespace, end-of-file-fixer, check-yaml, check-json and check-merge-conflict from pre-commit-hooks. Agents edit many config files at once.
- check-added-large-files (default 500 kB): agents sometimes commit build output or data dumps.
- Secrets: Gitleaks or detect-private-key from pre-commit-hooks.
- no-commit-to-branch: protects main and master by default, so an agent cannot commit straight to them locally.
- Formatter and linter for the language: Ruff for Python, Biome or ESLint plus Prettier through lint-staged for JavaScript, ShellCheck for shell.
- commit-msg format (Conventional Commits): keeps agent commit messages readable in history.
A starter config for the first five, with repository revisions to pin to a release tag:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: vX.Y.Z # pin a release tag
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-merge-conflict
- id: check-added-large-files
- id: detect-private-key
- id: no-commit-to-branch
- repo: https://github.com/gitleaks/gitleaks
rev: vX.Y.Z # pin a release tag
hooks:
- id: gitleaks
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: vX.Y.Z # pin a release tag
hooks:
- id: ruff-check
- id: ruff-format
Run pre-commit autoupdate to pin each repository to its latest release tag.
Heavier checks, such as the full test suite or a type check across the repository, move to pre-push or CI.
When to Use a Pre-Commit Hook, an Agent Hook, a Local AI Review or a PR Review
Four checkpoints cover different ground. The table shows what each sees and whether it can be skipped.
| Checkpoint | Runs when | Sees | Applies to | Can be skipped? | Best for |
| Git pre-commit hook | Before each commit | Staged diff | Every person and agent | Yes, –no-verify | Format, lint, secrets, file checks |
| Agent hook (for example Claude Code hooks) | On agent events in the session | The agent’s tool calls | One agent | Per agent settings | Stopping unsafe agent actions |
| Local AI review (Qodo Reviewer skill) | While the agent works, before the commit or before pushing | Local diff, untracked files, intent and ticket context, team rules | Agents and developers who run it | Yes, it is a step in the agent workflow | Logic, rule and intent issues fixed before a PR exists |
| PR review (Qodo in your Git) | When the PR opens and on updates | The pushed change | Every PR | Runs automatically when configured | Final check before merge |
With AI already inside the coding agent, there is no reason to wait for the PR to review. The shift-left code review post explains the pattern. Use the CLI locally in the coding harness and MCP for headless agents. Qodo has also worked with customers to run the CLI inside GitHub Actions, adding extra context to review such as a Terraform plan alongside the code change. Put each check where it is cheapest and cannot be skipped by accident.
Where Pre-Commit Hooks Broke Down With Coding Agents
Three illustrative composites show the gaps. None names a real team, and none carries figures.
- Different local checks per developer. Some developers ran their own AI review in a pre-commit script and others ran nothing, so the same agent change passed for one person and failed for another. One hook config covers the deterministic checks, and Qodo local review with the team’s imported rules covers everyone.
- The skipped hook. A slow hook led to –no-verify, and a change that ignored a team rule reached the PR. Qodo reviews the PR in Git against the same rules, so the skip does not skip review.
- The PR that needed rework. Findings arrived only at PR time, when developers skip optional fixes, and moving review into the agent loop let the agent fix reliability and maintainability issues too. A deeper Qodo local review handles that, with PR review tuned for low noise.
Hands-On: Pair Pre-Commit Hooks With Qodo Local Review and PR Review
The steps come from docs.qodo.ai and the tool READMEs. Screenshots in the published post blur repository names, paths and emails.
- Add a hook manager and the six hooks above, then run pre-commit install (or configure Husky or Lefthook).
- Mirror the same hooks in CI with SKIP=no-commit-to-branch pre-commit run –all-files.
- Install the Qodo Agentic Toolbox. It needs Node.js 20 or later, and the install command is on the CLI docs page.
- Add the Toolbox instructions to AGENTS.md or CLAUDE.md, so the agent runs Qodo’s local pre-PR review before it opens a PR. The Toolbox overview lists the text to add.
- Run qodo review on the working tree. Scope it with a pathspec for large branches, let the agent fix findings and re-run. Optionally, add a pre-push hook that runs qodo review so findings print in the terminal before code leaves the machine. This hook is our own example: the Reviewer docs describe running qodo review from the command line or from scripts before opening a PR, and the developer decides what to do with each finding.
- Keep Qodo PR review on in your Git provider, and check Analytics for how the team responds to findings raised on the PR.
Conclusion: Keep Hooks Fast and Shared, and Review Agent-Written Code Twice
Keep hooks fast, deterministic and shared, and mirror them in CI. A hook sees the staged diff, and the checks that need intent, rules and codebase context belong in review.
Give agent-written code one review before the commit and one on the PR. Qodo is the best choice for reviewing AI-generated code around your pre-commit hooks because it applies the same engine and team rules locally and in Git, which gives fast-moving teams clean commits and larger organizations one shared list of rules across repositories and coding agents.
FAQ: Pre-Commit Hooks and AI-Generated Code
What are pre-commit hooks?
A pre-commit hook is a script Git runs before it records a commit. A non-zero exit aborts the commit, and teams use a hook manager to share the same hooks across a repository.
Can a coding agent skip pre-commit hooks?
Yes. git commit –no-verify bypasses the pre-commit and commit-msg hooks, so run the same checks in CI and review the PR.
Should I run AI code review in a pre-commit hook?
Keep hooks to fast, deterministic checks. AI review can return different findings on a re-run, and teams run it in a find-fix loop, so it fits the agent loop before the commit and the PR after. Qodo reviews local changes before a PR exists and reviews the PR in Git.
What is the best tool to review my changes before my coding agent opens a PR?
Qodo is the best choice because it reviews local changes with the same engine and team rules as its PR review and uses the agent’s intent and ticket context. Other tools also review locally. Qodo loads your team’s own rules and uses the same engine that reviews the PR.
What is the difference between Claude Code hooks and Git pre-commit hooks?
Claude Code hooks run inside the agent session on agent events. Git pre-commit hooks run on every commit from any tool or person, and many teams use both.
pre-commit, Husky or Lefthook: which hook manager should I use?
pre-commit suits multi-language repositories and has the broadest hook catalogue. Husky with lint-staged suits JavaScript projects, and Lefthook suits teams that want one binary with parallel jobs.
Ethical use of AI
We use AI to proofread and organise our ideas. The substance comes from our team of developers and technical experts: every fact is traced back to its original source, and every example is hand-crafted and tested.