| name | trufflehog |
| description | Detect accidentally committed secrets in git history with TruffleHog — a tool that scans git repositories, filesystems, S3 buckets, and CI/CD systems for exposed credentials, API keys, tokens, and other secrets. Use this skill whenever the user suspects secrets were committed to git, wants to audit their repo history for leaked credentials, or needs to set up secrets scanning in CI/CD. Trigger for "trufflehog", "git secret scan", "leaked credentials git", "secrets in git history", or "scan for api keys". |
| SAFETY NOTE | This skill covers ONLY scanning your own repositories for accidentally committed secrets, to help you revoke and rotate them promptly. Never use secret scanning tools against repositories you don't own. |
TruffleHog: Secrets Detection in Git History
TruffleHog scans git repositories and other sources to find accidentally committed secrets — API keys, passwords, tokens, private keys — so you can revoke them quickly. It uses both regex patterns and Shannon entropy analysis to find high-confidence secrets.
Own your repos only: Only scan repositories and systems you own or have explicit authorization to audit.
Installation
brew install trufflesecurity/trufflehog/trufflehog
curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/main/scripts/install.sh | sh -s -- -b /usr/local/bin
docker pull trufflesecurity/trufflehog:latest
go install github.com/trufflesecurity/trufflehog/v3@latest
Scanning Git Repositories
trufflehog git file://./path/to/repo
trufflehog github --repo https://github.com/your-org/your-repo
trufflehog github --repo https://github.com/your-org/private-repo \
--token $GITHUB_TOKEN
trufflehog git file://./myrepo --since-commit HEAD~100
trufflehog git file://./myrepo --branch main
trufflehog github --repo https://github.com/your-org/your-repo --only-verified
trufflehog git file://./myrepo --exclude-paths .trufflehog-exclude
Scanning Entire GitHub Orgs
trufflehog github --org your-org --token $GITHUB_TOKEN
trufflehog github --org your-org --token $GITHUB_TOKEN --include-wikis
trufflehog github --org your-org --token $GITHUB_TOKEN --only-verified
Scanning Filesystems and Other Sources
trufflehog filesystem ./src/
trufflehog s3 --bucket my-company-artifacts
trufflehog s3 --bucket my-bucket \
--key $AWS_ACCESS_KEY_ID \
--secret $AWS_SECRET_ACCESS_KEY
trufflehog circleci --token $CIRCLECI_TOKEN --project your-project
trufflehog github-actions --token $GITHUB_TOKEN --repo your-org/your-repo
trufflehog docker --image my-app:latest
CI/CD Integration
GitHub Actions (Pre-merge Scanning)
name: Secret Detection
on:
push:
branches: [main, develop]
pull_request:
jobs:
trufflehog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: TruffleHog OSS
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: ${{ github.event.repository.default_branch }}
head: HEAD
extra_args: --only-verified --fail
GitLab CI
secret-detection:
stage: security
image: trufflesecurity/trufflehog:latest
script:
- trufflehog git file://. --since-commit $CI_COMMIT_BEFORE_SHA --only-verified --fail
allow_failure: false
Pre-commit Hook
echo "Scanning for secrets..."
trufflehog git file://. --since-commit HEAD --only-verified --fail
if [ $? -ne 0 ]; then
echo "ERROR: Secrets detected! Please remove them before committing."
exit 1
fi
repos:
- repo: local
hooks:
- id: trufflehog
name: TruffleHog
language: system
entry: trufflehog git file://. --since-commit HEAD --only-verified --fail
pass_filenames: false
always_run: true
Output Formats
trufflehog git file://./myrepo -j
trufflehog git file://./myrepo --json | jq '{
detector: .DetectorName,
secret_type: .DetectorType,
verified: .Verified,
file: .SourceMetadata.Data.Git.file,
commit: .SourceMetadata.Data.Git.commit,
author: .SourceMetadata.Data.Git.email
}'
trufflehog git file://./myrepo -j | jq 'select(.Verified == true)'
Understanding Results
Found verified result 🐷🔑
Detector Type: AWS
Detector Name: AWS
Verified: true
Raw result: AKIAIOSFODNN7EXAMPLE
...
Source metadata:
File: config/database.yml
Line: 45
Commit: abc123def456
Author: developer@company.com
Date: 2024-01-15
- Verified: TruffleHog made a test API call and confirmed the secret is active — Revoke immediately
- Unverified: Pattern matched but couldn't verify — investigate and revoke if real
Incident Response: Secret Found in History
When TruffleHog finds a secret, follow these steps:
Step 1: Revoke Immediately
aws iam delete-access-key --access-key-id AKIAIOSFODNN7EXAMPLE
Step 2: Assess Exposure
git log --all --full-history -- config/database.yml
git log --diff-filter=A --all -- path/to/file
git log --remotes --all --oneline | head -20
Step 3: Remove from Git History
java -jar bfg.jar --replace-text sensitive-patterns.txt myrepo.git
pip install git-filter-repo
git filter-repo --path-glob '*.env' --invert-paths
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch config/secrets.yml" \
--prune-empty --tag-name-filter cat -- --all
git push origin --force --all
git push origin --force --tags
Step 4: Rotate All Related Secrets
Even if you remove from history, assume the secret was already captured.
- Rotate the compromised credential
- Audit access logs for unauthorized use
- Rotate any other credentials that may have been co-located
Configuration File
detectors:
- AWS
- GitHub
- Stripe
- Slack
- Generic
exclude_paths:
- vendor/
- node_modules/
- .git/
- "**/*.test.js"
allowlist:
commits:
- abc123def456
paths:
- tests/fixtures/fake_credentials.yaml
GitNexus Index
This skill is indexed by GitNexus for knowledge graph traversal.
Index path: /Users/localuser/.claude/skills/trufflehog/.gitnexus
Last indexed: 2026-05-24