Skip to content

Git hooks

Git hooks allow you to run kluster.ai code reviews automatically every time you commit or push. Set up a pre-commit or pre-push hook and kluster-cli will review your changes in the background, blocking the operation if issues above your severity threshold are found.

Hook types

Hook When it runs What it reviews
pre-commit Before each git commit Staged changes
pre-push Before each git push Commits being pushed

Which one should I use?

  • Use pre-commit for fast feedback on every commit. Best for individual workflows.
  • Use pre-push to review the full set of changes before they leave your machine. Best for team workflows.
  • Use both for maximum coverage.

How hooks work

When a hook triggers, the CLI runs a review and checks the results against your severity threshold.

If issues meet the threshold — the operation is blocked:

git push origin feature-branch kluster.ai: Reviewing changes from a1b2c3d to e4f5f6a... → Reviewing code [████████████████████████████████████████] 100% ✓ Reviewing code complete! Review: 507f1f77bcf86cd799439013 Found 1 issue(s) #1 HIGH [P1] security API key exposed in source code. at src/config.js:15 Fix Move the API key to environment variables and access via process.env.API_KEY kluster.ai: Push blocked due to code review issues (severity threshold: high). kluster.ai: Fix the issues above or use 'git push --no-verify' to skip. kluster.ai: View this review again: kluster show 507f1f77bcf86cd799439013

If no issues meet the threshold — the operation proceeds:

git push origin feature-branch kluster.ai: Reviewing changes from a1b2c3d to e4f5a6b... → Reviewing code [████████████████████████████████████████] 100% ✓ Reviewing code complete! ✓ Code review complete - no issues found! Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 340 bytes | 340.00 KiB/s, done.

Install hooks

Install a single hook:

kluster hooks install <hook_name>
kluster hooks install pre-push ✓ pre-push hook installed successfully → Hook location: .git/hooks/pre-push → Mode: blocking on high severity and above

Or install all hooks at once:

kluster hooks install all
kluster hooks install all ✓ pre-commit hook installed successfully ✓ pre-push hook installed successfully Reviews will block on HIGH severity or above

Existing hooks

If a hook file already exists, the CLI will warn you. Use --force to overwrite it.

Configure blocking severity

By default, hooks block on high severity or above. Use --block-on to change the threshold:

kluster hooks install pre-push --block-on critical
Threshold Blocks on
critical Critical issues only
high (default) High and critical issues
medium Medium, high, and critical issues
low Any issue blocks

Warn-only mode

To show review results without blocking, use --warn-only:

kluster hooks install pre-push --warn-only

In this mode, the review runs and displays any issues found, but the git operation always proceeds.

Check hook status

See which hooks are installed:

kluster hooks status
kluster hooks status ✓ pre-push: installed (kluster.ai) ! pre-commit: not installed

Bypass hooks

In an emergency, you can skip hooks with git's --no-verify flag:

git commit --no-verify -m "hotfix: urgent production fix"
git push --no-verify

Use sparingly

Bypassing hooks skips the code review entirely. Reserve this for urgent hotfixes and follow up with a manual review.

Uninstall hooks

Remove hooks when no longer needed:

kluster hooks uninstall all
kluster hooks uninstall all ✓ pre-push hook uninstalled successfully ✓ pre-commit hook uninstalled successfully

You can also uninstall a specific hook:

kluster hooks uninstall pre-commit

The CLI only removes hooks it installed (identified by the KLUSTER_HOOK_START marker). Other hooks are left untouched.

Custom hook paths

The CLI respects git's core.hooksPath configuration. If you use a custom hooks directory:

git config core.hooksPath .githooks
kluster hooks install pre-push
# Hook is installed at .githooks/pre-push

If core.hooksPath is not set, hooks are installed in .git/hooks/.

Next steps

  • Review commands: Run reviews manually when you need them.
  • Reference: Configuration, exit codes, and full command reference.