Skip to main content
CLI
Git Hooks
Set up pre-commit hooks to automatically scan code before committing
Use CodeAnt AI as a pre-commit or pre-push hook to automatically scan your code for secrets before every commit or push.
If the developer confirms bypass, the push proceeds and the bypass event is recorded in CodeAnt (fire-and-forget). If declined, the push is blocked.
Warning: Only use
Manual Setup
-
Create the hook file at
.git/hooks/pre-commit: -
Make it executable:
-
Test it:
Using Husky
-
Install Husky:
-
Add the pre-commit hook:
-
Commit the hook configuration:
Using Lefthook
-
Install Lefthook:
-
Configure
lefthook.yml: -
Initialize and commit:
Customizing Hook Behavior
All scanning commands accept flags to customize behavior. See the Commands reference for the full list. Common examples for hooks:How It Works
When you rungit commit:
- The pre-commit hook runs the configured scanning commands
- Each scanner analyzes your staged files (the
--stageddefault) - If issues are found above the
--fail-onthreshold:- The commit is blocked
- Issue locations and details are displayed
- Fix the issues, re-stage, and try again
- If no blocking issues are found:
- The commit proceeds normally
Pre-Push Hook (Push Protection)
Use the--hook flag to enable push protection mode, which runs secrets scanning as a pre-push hook. This mode activates an interactive bypass prompt so that developers can choose to override a block with a stated reason rather than having to use --no-verify.
Setup
-
Create the hook file at
.git/hooks/pre-push: -
Make it executable:
How the Bypass Prompt Works
When secrets are detected during a push, the--hook mode shows an interactive prompt:
Bypassing Hooks
In rare emergencies, you can bypass all pre-commit or pre-push hooks:--no-verify in emergencies. Bypassing scans can allow secrets into your repository. Prefer the interactive bypass prompt in push protection mode (--hook) for an audited override flow.