Betterleaks setup guide
Find API keys still hiding in your git history, check if they still work, and fix it.

- What it does
- How to install Betterleaks, a free secrets scanner, run it on your repos, read what it finds, and what to do when a key is still live.
- Who it is for
- Developers who have ever pasted a key into code, and anyone whose repo an AI agent committed to.
What it is
Betterleaks (MIT) is a secrets scanner from the people who made Gitleaks. It scans files and every git commit, ranks findings by confidence, and can ask the provider whether a found key is still live.
Checked on November 20, 2026 with betterleaks 1.10.1.
Get the files
Everything on this page, ready to keep.
Install
Use 1.10.0 or newer: older versions could run code from a booby-trapped checkout while scanning (advisory GHSA-93cv-92xc-php5). On macOS and Linux, Homebrew gives 1.10.1:
brew install betterleaks
betterleaks version
Skip the betterleaks/tap cask for now: on November 20 it still pinned 1.8.1.
Daily commands (v1)
# Scan the whole history of the repo you are in
betterleaks git .
# Show each finding in full
betterleaks git . -v
# Ask the provider if a found key still works
betterleaks git . --validation
# Scan a folder that is not a repo
betterleaks dir ./path
# Hide the secret in the output
betterleaks git . --redact
v2 is a release candidate and renames things: -v becomes validate, fs scans folders. Read the v2 migration guide before you switch.
What a finding tells you
Rule (for example github-pat), the line, confidence, the commit message, sha and author, the file path, and with validation a status: VALID, INVALID, REVOKED or UNKNOWN.
Tips
- Run it before your first push, and again on any repo an AI agent committed to.
- VALID means rotate now: revoke the key at the provider, make a new one, update your app. Deleting the line in a new commit does not remove it from history.
- Put scanning in front of every commit: the repo ships a pre-commit hook (
.pre-commit-hooks.yaml) that scans only staged changes. - Keep secrets in a
.envfile that is in.gitignore, never in code.
Gotchas
- Validation sends the found secret to that provider's own API to test it. It is off unless you pass
--validation. - A low-confidence finding can be a false alarm; check before you rotate.
- Only scan checkouts you trust with versions before 1.10.0; update first.
- Rewriting history is a last step, not the fix: the key was public the moment it was pushed. Rotate first.