Scan for secrets and restrict agent access before pushing
Scan Git history and staged files, check agent skills, and restrict access to secret files before pushing.
Originally posted · Published here · 6 sources · Resume reading
API keys and other secrets leaked about twice as often in AI-assisted code in 2025, per a GitGuardian vendor report on 1.94 billion public GitHub commits [1]. The claim is based on commits by AI bot accounts or with an AI co-author line, not a controlled experiment, so take the exact number as an estimate. The fix is straightforward: run a scanner before every push.
Install TruffleHog
TruffleHog scans your repo for secrets and verifies whether each one still works [2]. That tells you which leaks are urgent.
brew install trufflehogYou should see TruffleHog added to your path.
Scan for verified and unknown secrets
Run this on repos you own, in the project folder:
trufflehog git file://. --results=verified,unknownYou should see a list of findings, or no output if the repo is clean. Verified findings mean the key still works and needs rotating.
Install Betterleaks for old commits
Betterleaks scans current files and also checks older commits [3]. A secret you deleted months ago is still in the history.
brew install betterleaks && betterleaks git .You should see findings from Git history. To include uncommitted files, run betterleaks filesystem . [3].
Install detect-secrets for new secrets only
detect-secrets flags only new secrets by comparing against a baseline file [4]. This is useful in a pre-commit hook where you want to ignore known patterns.
pip install detect-secrets
detect-secrets scan > .secrets.baselineReview the baseline before treating existing findings as accepted. To check staged files against it, run the hook command from the repo [4]:
git diff --staged --name-only -z | xargs -0 detect-secrets-hook --baseline .secrets.baselineThe hook reports new findings that are absent from the baseline. Creating or committing the baseline alone does not install a hook or block a push.
Install SkillSpector for agent skills
Before you install an agent skill, scan it for hardcoded secrets or unsafe patterns [5]. SkillSpector is from NVIDIA and works on any skill folder.
uv tool install git+https://github.com/NVIDIA/skillspector.git
skillspector scan ./some-skill/ --no-llmYou should see a report of any risky patterns in the skill.
Sandbox your agent's commands
Sandbox Runtime wraps any command you give it in a filesystem sandbox [6]. You can deny reads of .env and other sensitive paths:
{
"filesystem": {
"denyRead": ["**/.env"]
}
}npm install -g @anthropic-ai/sandbox-runtime
srt "your command"You should see your command run with the sandbox active. Attempts to read .env fail.
If a scan finds a live key
Revoke it first, then delete the line. Deleted lines stay in the repo's history, and anyone who clones the repo can find them. Create a new key in your provider's dashboard and update your secrets store.
Keep this guide
Filed under Security
Questions about this guide
Why scan before pushing if GitHub already scans?
GitHub's push protection catches common patterns but can miss custom tokens and credentials from smaller providers. A local scan gives you a second layer and catches problems before the code reaches the remote.
What if the scan finds a key that's already committed?
Revoke it first. Deleting the line from a new commit still leaves the key in the repo's history. Create a new key, then rotate it in your provider's dashboard.
Sources
- GitGuardian State of Secrets Sprawl 2026 (vendor report)gitguardian.com
- TruffleHog repogithub.com
- Betterleaks repogithub.com
- detect-secrets repogithub.com
- SkillSpector repogithub.com
- Sandbox Runtime repogithub.com