Skip to main content
Use CodeAnt AI as a pre-commit or pre-push hook to automatically scan your code for secrets before every commit or push.

Manual Setup

  1. Create the hook file at .git/hooks/pre-commit:
  2. Make it executable:
  3. Test it:
You can use any combination of scanning commands. For example, to only scan for secrets:

Using Husky

  1. Install Husky:
  2. Add the pre-commit hook:
  3. Commit the hook configuration:

Using Lefthook

  1. Install Lefthook:
  2. Configure lefthook.yml:
  3. 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 run git commit:
  1. The pre-commit hook runs the configured scanning commands
  2. Each scanner analyzes your staged files (the --staged default)
  3. If issues are found above the --fail-on threshold:
    • The commit is blocked
    • Issue locations and details are displayed
    • Fix the issues, re-stage, and try again
  4. 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

  1. Create the hook file at .git/hooks/pre-push:
  2. Make it executable:

How the Bypass Prompt Works

When secrets are detected during a push, the --hook mode shows an interactive prompt:
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.

Bypassing Hooks

In rare emergencies, you can bypass all pre-commit or pre-push hooks:
Warning: Only use --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.