Skip to main content

Overview

The Zenable pre-commit hook automatically checks your code against organizational policies before each commit, preventing policy violations from entering your codebase. This ensures consistent code quality and compliance across your entire development team.

Quick Start

Looking for better performance? Try prek, a drop-in replacement for pre-commit with faster execution. All commands in this guide work with prek by replacing pre-commit with prek.
1

Install UV

Don’t have UV? Install UV hereThen install pre-commit using UV:
2

Configure pre-commit

Add to your .pre-commit-config.yaml:
3

Install the hook

Run this one-time setup in your repository:
This installs the pre-commit hook into your local git repository.
All-in-one setup: After installing UV, you can run everything with:

How It Works

When you commit code, the pre-commit hook:
  1. Intercepts the commit before it’s finalized
  2. Checks changed files against your configured policies
  3. Reports violations with specific line numbers and fix suggestions
  4. Blocks the commit if violations are found (configurable)
  5. Allows the commit once all issues are resolved

Example Workflow

When issues are found, the commit is blocked:
After fixing the issues, the commit succeeds:

Common Use Cases

Security Policies

Prevent security vulnerabilities:

Code Quality

Enforce quality standards:

Compliance Requirements

Ensure regulatory compliance:

Troubleshooting

Ensure the hook is installed:
In emergencies, you can bypass:
⚠️ Use sparingly - this defeats the purpose of policy enforcement
Important: You should expect that developer-local configurations can be worked around, either intentionally or unintentionally. For defense in depth, combine pre-commit hooks with server-side enforcement through our GitHub and GitLab reviewers to ensure comprehensive policy coverage.

Updating the Hook

Keep your policies current:

Best Practices

  1. Start gradually - Begin with warnings before enforcing. Review our deployment guide for proven adoption strategies
  2. Run manually first - Test with pre-commit run --all-files
  3. Keep hooks fast - Use file filters to check only relevant files
  4. Update regularly - Run pre-commit autoupdate monthly via scheduled pipelines
  5. Document exceptions - Make policy exceptions visible and temporary
  6. Provide context - Help developers understand why policies exist
  7. Be Automation-first - See starting new projects to see how you can have pre-commit hooks automatically configured from the first commit

Comparison with Other Tools

Next Steps