Manual Setup
-
Create Pre-commit Hook:
Create a new file at
.git/hooks/pre-commit: -
Make Executable:
Make the hook file executable:
-
Test Hook:
Try making a commit to verify the hook runs:
The hook will automatically scan staged files for secrets before allowing the commit.
Using Husky
-
Install Husky:
Install Husky in your project:
-
Add Pre-commit Hook:
Add the CodeAnt secret scanner:
-
Commit Hook Configuration:
Commit the
.huskydirectory to share the hook with your team:
Using Lefthook
-
Install Lefthook:
Install Lefthook in your project:
-
Configure Lefthook:
Add to your
lefthook.yml: -
Initialize Lefthook:
Set up the hooks:
-
Commit Configuration:
Commit the configuration file:
Customizing Behavior
Change Fail Threshold: Only block commits for HIGH confidence secrets:How It Works
When you rungit commit:
- Pre-commit hook triggers
codeant secrets - CodeAnt scans your staged files
- If secrets are found:
- Commit is blocked
- Secret locations are displayed
- You must remove secrets and try again
- If no secrets (or only false positives):
- Commit proceeds normally
Bypassing Hooks
In rare emergencies, you can bypass the hook:--no-verify in emergencies. Bypassing secret scanning can expose sensitive data to your repository.