How does detect-secrets work?
It reads the files git tracks today, not past commits, with 27 plugins, and writes what it finds to a .secrets.baseline file. Its README says this "avoids the overhead of digging through all git history".
| Plugin type | What it matches | What it caught in the test |
|---|---|---|
| Format rules (24) | One key format each: AWS, GitHub, Slack, Stripe, private keys, JWTs, URLs with a password and more | AWS, GitHub classic, Slack, Stripe live, Twilio, SendGrid, npm and GitLab keys, the private key, the JWT and the database URL |
| Entropy (2) | Base64HighEntropyString, HexHighEntropyString: any long random-looking string in quotes | The only catch for the GitHub fine-grained token, Stripe test, Google and Hugging Face keys |
| Keyword (1) | KeywordDetector: values assigned to names like password or secret | The password in a config file; backed up the OpenAI and hex keys |
Plugin list from detect-secrets scan --list-all-plugins, version 1.5.0. Results from the 20 runs below.
Its OpenAI plugin matched only 2 of 20 new-style sk-proj keys; the entropy and keyword plugins caught all 20. Entropy depends on each random value, which is why some types were found in 18 or 19 runs, not 20.
How do you create and update a .secrets.baseline?
Run one scan, commit the file it writes, then let the hook compare each commit against it. Findings already in the baseline don't fail a commit; new ones do.
| To | Run |
|---|---|
| Record today's findings | detect-secrets scan > .secrets.baseline |
| Mark each finding real or false | detect-secrets audit .secrets.baseline |
| Update the baseline | detect-secrets scan --baseline .secrets.baseline |
| Scan files git doesn't track | detect-secrets scan --all-files |
| Skip checks with providers | detect-secrets scan --no-verify |
| List the 27 plugins | detect-secrets scan --list-all-plugins |
From the detect-secrets README, read December 4, 2026. An update adds new findings, removes ones that are gone, and keeps your labels.
How do you run detect-secrets as a pre-commit hook?
Add it to .pre-commit-config.yaml with your baseline:
repos:
- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
- id: detect-secrets
args: ['--baseline', '.secrets.baseline']
Without the pre-commit framework, scan the staged files yourself:
git diff --staged --name-only -z | xargs -0 detect-secrets-hook --baseline .secrets.baseline
For a value you mean to commit, such as a test fixture, end the line with # pragma: allowlist secret, or put # pragma: allowlist nextline secret on the line above. A hook runs only where it is installed, and git commit --no-verify skips it.
What did detect-secrets find in a 20-key test?
19 of the 20 planted key types with its checks off, the same count as Gitleaks. It caught the database URL with a password that Gitleaks missed, missed the Anthropic API key, and flagged 3 of 6 decoys in every run.
| Item | detect-secrets, checks off | Its plugin | Gitleaks | TruffleHog |
|---|---|---|---|---|
| AWS access key ID and secret access key | 20/20 | AWS Access Key | 20/20 | 20/20 |
| GitHub personal access token (classic) | 20/20 | GitHub Token | 20/20 | 20/20 |
| GitHub fine-grained personal access token | 20/20 | Base64 High Entropy String | 20/20 | 20/20 |
| Slack bot token | 20/20 | Base64 High Entropy String; Slack Token | 20/20 | 20/20 |
| Slack incoming webhook URL | 20/20 | Slack Token | 20/20 | 20/20 |
| Stripe live secret key | 20/20 | Base64 High Entropy String; Stripe Access Key | 20/20 | 20/20 |
| Stripe test secret key | 20/20 | Base64 High Entropy String | 20/20 | 0/20 |
| OpenAI project API key | 20/20 | Base64 High Entropy String; OpenAI Token; Secret Keyword | 19/20 | 20/20 |
| Anthropic API key | 0/20 | none | 20/20 | 20/20 |
| Google API key | 19/20 | Base64 High Entropy String | 20/20 | 0/20 |
| RSA private key (PEM) | 20/20 | Private Key | 20/20 | 20/20 |
| Supabase service_role key (JWT) | 20/20 | JSON Web Token | 20/20 | 0/20 |
| Password in a config file | 20/20 | Secret Keyword | 15/20 | 0/20 |
| Database URL with a password | 20/20 | Basic Auth Credentials | 0/20 | 20/20 |
| High-entropy hex secret | 20/20 | Hex High Entropy String; Secret Keyword | 19/20 | 0/20 |
| Twilio API key | 20/20 | Secret Keyword; Twilio API Key | 20/20 | 0/20 |
| SendGrid API key | 20/20 | SendGrid API Key | 20/20 | 20/20 |
| npm access token | 20/20 | NPM tokens | 20/20 | 20/20 |
| Hugging Face access token | 18/20 | Base64 High Entropy String | 20/20 | 20/20 |
| GitLab personal access token | 20/20 | GitLab Token | 20/20 | 20/20 |
| AWS's documented example key pair (decoy) | 20/20 | AWS Access Key | 0/20 | 0/20 |
| Placeholder value (decoy) | 20/20 | Basic Auth Credentials | 0/20 | 0/20 |
| UUID request ID (decoy) | 0/20 | none | 0/20 | 0/20 |
| Package integrity hash (decoy) | 0/20 | none | 0/20 | 0/20 |
| Password read from the environment (decoy) | 0/20 | none | 0/20 | 0/20 |
| Git commit SHA (decoy) | 20/20 | Hex High Entropy String | 0/20 | 0/20 |
Runs that reported each item, of 20; for a decoy, 0/20 is right. The three decoys it flagged: AWS's documented example key, a placeholder database URL and a git commit hash.
Method. 20 runs on December 4, 2026 (UTC). Each run made a scratch git repo with one commit: 20 fake keys in their real formats, with fresh random values, and 6 decoys. Commands: detect-secrets -c 1 scan --no-verify in the repo, gitleaks git <repo> and trufflehog git file://<repo> --no-verification, with default rules. Versions: detect-secrets 1.5.0, Gitleaks 8.30.1, TruffleHog 3.100.1. A run counts when the tool reported the item's file. No real key was used.
Download: secret-detection-test-2026-12-04.csv (26 rows, with each tool's rule names and a column for detect-secrets with default settings) and secret-detection-tools-2026-12-04.csv (six tools: where each runs, price, license, live-key checks).
Does detect-secrets check whether a key works?
Yes, for 9 of its 27 plugins, and it is on by default: AWS, Slack, Stripe, Mailchimp, Telegram, Cloudant, IBM Cloud IAM, IBM COS HMAC and SoftLayer. A match the provider rejects is dropped from the results.
With default settings, the Slack and Stripe plugins reported none of the fake keys. The fake Slack webhook went unreported in all 20 runs (all 20 found with --no-verify). A scan with checks on sends those matches to the provider. Add --no-verify to keep a scan offline, or --only-verified to report only keys that work.
detect-secrets vs Gitleaks: which should you use?
Gitleaks, for most repos: it reads history, flagged no decoys, and had a release in 2026. detect-secrets fits a repo with many known findings, where the baseline and audit flow save a cleanup.
| detect-secrets | Gitleaks | |
|---|---|---|
| Written in, license | Python, Apache-2.0 | Go, MIT |
| Reads past commits | No: current files | Yes: gitleaks git |
| Known findings live in | .secrets.baseline | .gitleaksignore, .gitleaks.toml or --baseline-path |
| Planted key types found | 19 of 20 | 19 of 20 |
| Decoys flagged | 3 of 6 | 0 of 6 |
| Missed | Anthropic API key | Database URL with a password |
| Latest release | 1.5.0, May 6, 2024 | 8.30.1, March 21, 2026 |
Releases from PyPI and GitHub; results from the test above. Gitleaks config: .gitleaks.toml guide.
What if a key is already committed?
Revoke it with the provider first. GitHub's guide to a leaked secret warns that removing it from the code, pushing a new commit, or deleting and recreating the repository doesn't stop it from being used. Then run Gitleaks or TruffleHog over the full history once, since detect-secrets won't see past commits. A step-by-step from IonCipher covers cleaning git history.
For every repo in a GitHub org, IonCipher is the pick: a GitHub App whose secret, Actions, config and dependency rules read every repo, then a model triages each finding as real, unsure or noise. Free covers unlimited public repos and 10 private repos nightly; Pro is $39 a month per org, with scans on every push (IonCipher pricing). Its site lists no pre-commit hook, so keep detect-secrets there. It wasn't run in this test.
How was this page checked?
The plugins that check with providers were read in detect-secrets 1.5.0's own code (the plugins with a verify step, and the filter that drops a rejected match). Errors: support@winding.ai.
- detect-secrets on GitHub; PyPI: 1.5.0, May 6, 2024; its plugins in 1.5.0, where the 27 plugins and the 9
verifysteps were counted - Gitleaks 8.30.1 and TruffleHog 3.100.1: READMEs and releases
- GitHub: remediating a leaked secret; git commit --no-verify