Scan Commits for Secrets With an AI Prompt That Reads Context
Catch leaked credentials regex scanners miss. A scan commit for secrets prompt that reviews a diff with context and emits a redaction plan. Copy the structure.
Regex secret scanners have one job and two failure modes: they miss anything that doesn't match a known pattern, and they cry wolf on every password = "example" in a test fixture. A scan commit for secrets prompt reads the diff with context, so it can tell a live credential from a placeholder and a real token from documentation. That context is the part a regex can't do.
This isn't a replacement for gitleaks. It's the layer on top that makes the judgment calls. The prompt reviews a diff, flags genuine leaks with severity, and emits a redaction-and-remediation plan. Structured output, so a finding becomes a task instead of a line in a log nobody reads.
The pages ranking for this query are regex-tool tutorials — gitleaks, git-secrets, pre-commit hooks. They're fast and pattern-blind. None offer a context-aware prompt with a remediation contract. That's the gap a PromptsCart post fills.
What you can hand the scanner
A scan-commit-for-secrets prompt is a reusable instruction that reviews a diff for leaked credentials and returns findings with a remediation plan. The diff is the input; the context-awareness is why it beats a pattern match.
What it catches that regex tends to miss or over-flag:
- A real API key in a config file regex didn't have a pattern for
- A connection string with embedded credentials in a non-obvious format
- A private key pasted into a comment "temporarily"
- A token that looks like a placeholder but isn't (and vice versa)
- A credential reintroduced in a diff after a previous cleanup
The shared job: decide whether this string is a real secret in a real place, then say what to do about it. Judgment, not just matching.
Anatomy: diff in, redaction plan out
The prompt frames the model as a security reviewer, takes the diff in a variable, and locks the output to findings with remediation.
Variables
{{commit_diff}} — the unified diff to review
{{context}} — repo type, e.g. "public OSS" vs "internal"
Prompt
Role: You are a security reviewer scanning a commit for leaks.
Task: Review {{commit_diff}} for real credentials. Use the
surrounding code to tell live secrets from placeholders.
Ignore obvious examples and test fixtures.
Output contract
findings: for each leak —
type: api_key | token | private_key | connection_string
location: file + line
severity: critical | high | medium
is_real: true | false (with reasoning)
remediation: redact + rotate + purge-from-history steps
verdict: SAFE | LEAKS_FOUND
The is_real field with required reasoning is the whole point. A regex flags key = "AKIA..." whether it's live or a docs example. The prompt has to argue why it's real, which both cuts false positives and makes the genuine findings credible.
The same leaked key is a different severity in a public OSS repo than in an internal one. Set {{context}} so the prompt grades accordingly: a credential in a public diff is already compromised the moment it's pushed and rates critical regardless of value. Tell the prompt where the code lives.
Step-by-step: from diff to rotation
1. Capture the diff
A pre-commit hook, a CI step, or a manual git diff --cached all produce the input for {{commit_diff}}.
2. Set the context
{{context}} tells the prompt whether this is a public repo (assume worst case) or internal.
3. Run and read the verdict
SAFE or LEAKS_FOUND. If leaks, each carries is_real reasoning so you can dismiss the placeholders fast.
4. Act on the remediation
For a real leak, the plan is redact, rotate, purge. Rotation matters most: a pushed secret is already burned, so redacting without rotating is theater.
5. Add patterns it missed
If it flags something novel, note the pattern so your fast regex layer learns it too.
Patterns that keep findings trustworthy
Force is-real reasoning. The model must justify why a string is a live secret, not just flag the shape. This is what separates a useful review from a regex tool's noise. Reasoning you can check beats a flag you can't.
Always include rotation in remediation. Redacting a committed secret without rotating it is the most common half-fix. Bake rotation into the output contract so the model never suggests redaction alone for a pushed credential.
Treat public-repo leaks as already compromised. The remediation for a secret in a public diff isn't "remove it." It's "rotate it now, then remove it." The context variable drives that severity bump.
Variables you'll set
| Variable | Required | What it is |
|---|---|---|
{{commit_diff}} | Yes | The unified diff to review for leaks |
{{context}} | No | Repo visibility and type, for severity grading |
{{known_patterns}} | No | Org-specific secret formats to watch for |
An opinion worth holding
Regex-only secret scanning gives teams false confidence. A clean gitleaks run feels like safety, but it only means nothing matched the patterns it knew. The leaks that hurt are the ones in a format nobody wrote a rule for, and those sail straight through. A context-reading prompt as a second layer catches the unknown-shaped credential a pattern matcher structurally can't. Run the regex for speed and the prompt for judgment. One without the other is a gap.
Getting started
- Copy the anatomy into your model of choice.
- Feed it a real
git diff --cachedfrom a branch. - Set
{{context}}to your repo's visibility. - Confirm it ignores test-fixture placeholders and flags a real key.
- For any leak, follow redact, rotate, purge in that order.
- Wire it as a second layer behind your fast regex scanner.
To run this on every agent-authored commit automatically, the Agent Commit Security Harness scans diffs for credentials, injection flaws, and risky dependencies, then posts a prioritized report to the PR.
Browse the security prompt packs →The Agent Commit Security Harness does this end-to-end: four prompts that catch leaked credentials in agent-authored diffs before they reach main and flag injection and auth flaws with severity ratings, posting a PR-ready security report. It's part of The Complete AI Prompts Bundle, a one-time lifetime license to the whole catalog plus every pack added later, worth it once agents are committing to more than one repo.
For a deeper, structured audit beyond the commit level, the Application Security Audit Playbook maps the threat surface and reviews against the OWASP Top 10. See also how to choose a reusable AI prompt pack and the companion AI CI-gate prompt to block risky PRs.
Common questions
What is a scan-commit-for-secrets prompt?
Why use an AI prompt when gitleaks already exists?
What does the prompt do after it finds a secret?
Get the prompt packs this guide is built on
Ready-to-paste prompts with documented variables and worked examples for ChatGPT, Claude, and Gemini. One-time payment, own it forever.
More prompt guides

A Flaky Test Detection Prompt for Your CI Pipeline
A test goes red, you re-run it, it goes green, and you merge. That reflex is how flaky tests survive for months while quietly training the team to ignore the pipeline. A flaky test detection prompt br…

An AI CI-Gate Prompt That Blocks Risky Pull Requests
A merge gate that blocks everything is as useless as one that blocks nothing. The goal of an ai pr ci gate prompt is judgment: read the diff, classify the risk, and return a verdict your pipeline can…

An AI Release Notes Prompt That Turns Commits Into a Changelog
Release day, and someone's hand-writing a changelog from output at 5 p.m. They're guessing which commits matter to users, paraphrasing terse messages, and missing the breaking change buried on line 40…