heydeer

Secret scanning tools in 2026: Gitleaks, TruffleHog and more

· · 9 min read

The secret scanning tools most teams choose between in 2026 are Gitleaks, TruffleHog, GitHub secret scanning, detect-secrets and GitGuardian. They overlap more than their marketing suggests, and the useful question is where each one sits: on a developer’s laptop before the commit, in CI, on the pull request, or across every repository the organization owns. This comparison covers what each secrets scanner detects, what it costs, where it fits, and what to do on the day one of them finds a live key.

For most teams the best secret scanning setup is layered: a fast local scanner such as Gitleaks or TruffleHog in a pre-commit hook, GitHub secret scanning with push protection on the server, and an organization-wide history scan with credential verification, such as TruffleHog or GitGuardian. When a secret leaks anyway, rotate it first; removing it from git history comes second.

Where secret detection happens

A hardcoded secret can be caught at four points, and each one is cheaper than the next. Before the commit, a pre-commit hook stops the key from ever entering history. On the push, server-side push protection refuses the commit even when someone skipped the hook. On the pull request, CI and reviewers see the change before it merges. And after the fact, an organization-wide scan of full history finds what slipped through years ago.

No single tool covers all four well, which is why the comparison below is organized by where a tool runs as much as by what it detects. A scanner that is excellent at triaging a ten-year history can be the wrong thing to put in front of every commit, and the reverse.

Secret scanning tools compared

ToolLicense and priceChecks if a key is liveBest place in the pipeline
GitleaksMIT; the GitHub Action needs a free license key for organization reposNo: rules, entropy and allowlistsPre-commit hook, CI
BetterleaksMITOpt-in with --validatePre-commit, CI, scans of GitHub and GitLab
TruffleHogAGPL-3.0; separate enterprise productYes: verified, unverified or unknownHistory scans across orgs, buckets and images; CI
GitHub secret scanningFree on public repos; private org repos need Secret Protection ($19 per active committer per month at launch)Validity checks for supported providersPush protection, org-wide alerts
detect-secretsApache-2.0Optional, for some secret typesPre-commit in codebases with known old secrets
GitGuardian (ggshield)ggshield is MIT and needs a GitGuardian account; free for up to 25 developers, larger plans through salesValidity checks on paid plansPre-commit, CI, continuous monitoring
HeyDeerPart of every HeyDeer pull request reviewReports each credential in a known format and asks you to rotate itPull request review

Gitleaks

Gitleaks is the default answer for a local secrets scanner, and for good reason. It ships as one binary under the MIT license, runs offline, and has three commands that cover almost every use: gitleaks git reads a repository’s history through git log -p, gitleaks dir scans files on disk, and gitleaks stdin scans whatever you pipe in. The older detect and protect commands were deprecated in v8.19.0 and are hidden from the help output, so older blog posts that use them are showing their age.

Configuration lives in a .gitleaks.toml at the root of the scanned path. Rules can carry their own allowlists, a gitleaks:allow comment on a line silences it, and --baseline-path points at an earlier report so only new findings fail the run. The pre-commit setup is a few lines:

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.24.2
    hooks:
      - id: gitleaks

In CI, the official Gitleaks Action runs on pushes, pull requests and a schedule. It is free for personal accounts; repositories owned by an organization need a free license key from gitleaks.io, stored as GITLEAKS_LICENSE:

name: gitleaks
on:
  pull_request:
  push:
  workflow_dispatch:
  schedule:
    - cron: "0 4 * * *" # once a day
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0
      - uses: gitleaks/gitleaks-action@v3
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }} # organizations only

Gitleaks is now feature complete. Its README says new releases will be security patches only and that its author is focusing on Betterleaks, a new MIT-licensed scanner from the people who made Gitleaks. Betterleaks adds opt-in validation of live credentials with --validate, filtering of natural-language false positives, and scanning of GitHub, GitLab, Hugging Face, S3 and containers.

Gitleaks keeps working, and a team happy with it has no urgent reason to move. For a new setup, Betterleaks is worth a look before committing to a config format.

TruffleHog

TruffleHog’s defining feature is verification. For each match, it can call the provider’s API to see whether the credential still works, and labels the result verified (confirmed live), unverified (found but not confirmed) or unknown (the check failed, for example on a network error). Its README counts more than 800 classified secret types. When an old monorepo produces four hundred matches, being able to run with --results=verified and start from the dozen keys that still open a door changes the size of the job.

It also reaches further than git. Besides trufflehog git and filesystem, there are sources for a whole GitHub organization, GitLab, S3 and GCS buckets, Docker images, Jenkins, Postman, Hugging Face and more. TruffleHog’s own pre-commit instructions recommend a local hook that scans only what changed since HEAD:

# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: trufflehog
        name: TruffleHog
        entry: bash -c 'trufflehog git file://. --since-commit HEAD --results=verified,unknown --fail --trust-local-git-config'
        language: system
        stages: ["pre-commit", "pre-push"]

Two trade-offs come with it. Verification makes network calls to providers during the scan, which some security teams want to approve first. And since v3, TruffleHog is licensed AGPL-3.0, which legal teams read carefully before anyone embeds it in a product; running the CLI in your own pipeline is the common case. Truffle Security sells a separate enterprise product for continuous monitoring of Git, Jira, Slack and Confluence.

Gitleaks vs TruffleHog

The choice usually comes down to four differences:

  • Live credential checks. TruffleHog verifies matches against provider APIs and lets you filter by result. Gitleaks reports matches without calling anyone; Betterleaks brings validation back as an opt-in flag.
  • License. Gitleaks and Betterleaks are MIT. TruffleHog is AGPL-3.0.
  • Speed. An offline regex scan has nothing to wait on. A verifying scan waits on provider APIs for each candidate, which matters little in a pre-commit hook on a small diff and a lot on a full-history scan. Neither project publishes a head-to-head benchmark, so time both on your largest repository.
  • Config. Gitleaks rules are TOML with regexes, keywords, entropy and allowlists, and inline gitleaks:allow comments. TruffleHog is mostly driven by flags such as --results and --since-commit.

A pattern that works for many teams: Gitleaks (or Betterleaks) in the pre-commit hook and on every pull request, where speed and a predictable config matter, and TruffleHog on a schedule across the organization, where telling live keys from dead ones saves the most time.

GitHub secret scanning and push protection

GitHub secret scanning runs on the server, so nobody has to install anything. It scans the entire git history on all branches, plus issue descriptions and comments, pull request titles, descriptions and comments, Discussions, wikis and secret gists. For partner patterns, GitHub reports the credential directly to the provider instead of showing it in your alerts. Validity checks show whether a detected secret is still active, and custom patterns let you add regexes for your own internal token formats.

Push protection moves the check before the push lands: a push containing a detected secret is blocked from the command line, the web UI or a file upload. Anyone with write access can bypass it by giving a reason, such as “It’s used in tests” or “I’ll fix it later”, and each bypass is recorded and alerts the repository’s admins. Push protection for users, on by default on GitHub.com, separately stops you from pushing secrets to public repositories.

On cost, public repositories get secret scanning free. Private and internal repositories owned by an organization need GitHub Secret Protection, launched in April 2025 at $19 per active committer per month and available on GitHub Team and Enterprise Cloud. A committer counts as active if one of their commits was pushed in the last 90 days, and is counted once across repositories.

detect-secrets

Yelp’s detect-secrets takes a different stance on old secrets. Instead of failing on everything in history, you run detect-secrets scan > .secrets.baseline once, triage the results with detect-secrets audit, and commit the baseline. The pre-commit hook then blocks only secrets that aren’t in it. By default it scans the files git tracks rather than digging through all history, and alongside its format rules it has entropy and keyword plugins for “secret-looking” strings and suspicious variable names. It is Apache-2.0 licensed and can optionally verify some secret types.

That makes detect-secrets a good fit for a large, older codebase where a strict scanner would fail every build on day one. The baseline turns “clean up everything first” into “stop it getting worse, then clean up.”

GitGuardian

GitGuardian is a hosted platform with an open-source CLI, ggshield (MIT), which detects more than 500 types of secrets. ggshield secret scan pre-commit runs as a hook, ggshield secret scan repo . scans a repository, and ggshield also runs in CI. Scanning goes through GitGuardian’s API, so ggshield needs an account and an API key; per its README, only metadata about each call is stored, not the secrets.

The free plan covers up to 25 developers with unlimited real-time scanning and internal secrets monitoring. Validity checks, monitoring of public GitHub for your company’s secrets and larger teams are on paid plans, priced through sales. GitGuardian fits teams that want a dashboard, incident workflow and ownership tracking more than another CLI.

Where each tool fits

  • Pre-commit: Gitleaks or Betterleaks for speed and an offline scan, detect-secrets when a baseline of known secrets is needed, ggshield if GitGuardian is already the platform.
  • Push: GitHub push protection, because it can’t be skipped by a developer who never installed the hook.
  • Pull request: a scanner in CI (the Gitleaks Action or TruffleHog’s Action on pull_request), plus the review itself.
  • Organization-wide history: GitHub secret scanning where it is enabled, and TruffleHog or GitGuardian across everything else, including buckets, images and chat tools.

Whichever you pick, the history scans look much the same:

# Gitleaks: the whole history of a local clone, or a range of commits
gitleaks git -v .
gitleaks git -v --log-opts="--all main..feature-branch" .

# TruffleHog: a whole GitHub organization, live credentials only
trufflehog github --org=your-org --results=verified

# detect-secrets: start a baseline of what is already in the tree
detect-secrets scan > .secrets.baseline
detect-secrets audit .secrets.baseline

Secrets in pull request review

The pull request is where a person decides whether a change ships, so a leaked key should be on the page they are reading, next to the rest of the review. HeyDeer, an AI code review agent for GitHub pull requests, checks every commit of each pull request for credentials in known formats, such as API keys, access tokens and private keys. Each one still in the code becomes a finding that asks you to revoke and rotate it. A credential committed and later removed gets a review note asking for the same, because it is still in the branch’s history. The review leaves out the values it finds, and states how many security issues it found, in the pull request comment and in the HeyDeer Review check.

That covers the pull request layer. Keep pre-commit hooks and push protection in front of it, and an organization-wide history scan behind it. See HeyDeer’s AI security code review for what else each review checks, or the Claude Code security review guide for running a security pass from your terminal.

HeyDeer checks every commit of a pull request for credentials in known formats and reports each one as a finding asking you to rotate it, with the value left out of the review. Each HeyDeer review also says how many security issues it found, in the PR comment and in the HeyDeer Review check.

What to do after a leaked API key

When a scanner finds a real key, the order of operations matters more than the tool that found it.

  1. Revoke and rotate the credential. GitHub’s own guide puts this first. Once the old value no longer grants access, the leak is contained, whatever happens to the history.
  2. Check what it was used for. Read the provider’s access logs for the window between the commit and the revocation.
  3. Decide whether to rewrite history. A rotated key in history is mostly noise for future scans. Rewriting is disruptive, so do it when the value still matters or policy requires it.
  4. Remove the secret from git history with git-filter-repo 2.47 or later, whose --sensitive-data-removal flag fetches all refs and prints instructions for cleaning up other copies.
  5. Contact GitHub Support with the repository, the number of affected pull requests and the first changed commits, so it can remove cached views and pull request references.
# 1. Work in a fresh clone (git-filter-repo 2.47 or later)
git clone https://github.com/your-org/your-repo.git && cd your-repo

# 2a. Remove a file from every commit on every ref
git-filter-repo --sensitive-data-removal --invert-paths --path config/prod.env

# 2b. Or replace the value wherever it appears in history
#     (each line of passwords.txt is a literal; it becomes ***REMOVED***)
git-filter-repo --sensitive-data-removal --replace-text ../passwords.txt

# 3. See how many pull requests reference the old commits
grep -c '^refs/pull/.*/head$' .git/filter-repo/changed-refs

# 4. Push the rewritten history
git push --force --mirror origin

Expect side effects. Every commit after the first changed one gets a new hash, signatures are dropped, open pull requests lose comments on old diffs, and branch protection may need to be relaxed for the force push. Collaborators should re-clone or rebase rather than merge, because one merge from an old clone brings the secret back. Forks keep their own copies. All of which is why rotation comes first, and why a hook that stops the next key before it is committed is the cheapest tool on this list.

Sources

  1. Gitleaks README
  2. Gitleaks Action README
  3. Betterleaks README
  4. TruffleHog README
  5. TruffleHog: pre-commit hook setup
  6. GitHub Docs: About secret scanning
  7. GitHub Docs: About push protection
  8. GitHub Changelog: Introducing GitHub Secret Protection and GitHub Code Security
  9. GitHub Docs: GitHub Advanced Security billing
  10. Yelp detect-secrets README
  11. GitGuardian ggshield README
  12. GitGuardian pricing
  13. GitHub Docs: Removing sensitive data from a repository
  14. git-filter-repo documentation

Frequently asked questions

What is secret scanning?

Secret scanning is the automated search of code, commits and other text for credentials such as API keys, access tokens, private keys and database connection strings. Scanners match known credential formats with regular expressions, use entropy and keyword heuristics for generic secrets, and some confirm a match by calling the provider’s API to see whether the credential still works.

Is Gitleaks or TruffleHog better?

Gitleaks and TruffleHog suit different jobs. Gitleaks is an MIT-licensed, offline scanner with a simple TOML config, well suited to pre-commit hooks and CI. TruffleHog is AGPL-3.0 and verifies whether each credential is live, which makes it better for large history scans where most findings are stale. Note that Gitleaks is now feature complete, and its author’s new work goes into Betterleaks.

Is GitHub secret scanning free?

GitHub secret scanning is free for public repositories, where it runs automatically. For private and internal repositories owned by an organization, it needs GitHub Secret Protection, which GitHub launched at $19 per active committer per month and is available on GitHub Team and GitHub Enterprise Cloud.

Does deleting a secret from the code remove it from Git?

Deleting a secret in a new commit leaves it in every earlier commit, so anyone with the repository’s history can still read it. Revoke and rotate the credential first, which makes the leaked value useless. Then, if needed, rewrite history with git-filter-repo --sensitive-data-removal and ask GitHub Support to remove cached views and pull request references.

What is the difference between Gitleaks and detect-secrets?

Gitleaks scans git history, directories or standard input against a large set of credential rules. Yelp’s detect-secrets scans the files currently tracked in the repository and records known secrets in a .secrets.baseline file, so its pre-commit hook blocks only new secrets. That baseline approach suits older codebases that already contain secrets the team has triaged.

Can secret scanning run in a pre-commit hook?

Secret scanning runs well in a pre-commit hook, which is the cheapest place to catch a key because it never reaches a shared branch. Gitleaks, TruffleHog, detect-secrets and GitGuardian’s ggshield all publish pre-commit setups. A hook is optional on each laptop, so pair it with a server-side check such as push protection or a CI job.

How do I find secrets across all my repositories?

Finding secrets across every repository takes an organization-wide scan of full history. GitHub secret scanning does this for repositories where it is enabled and also covers issues and pull request descriptions. TruffleHog can scan a whole GitHub organization with trufflehog github --org, and GitGuardian monitors connected repositories continuously.

Start with your first PR.

Free plan. No credit card required.

Get started free