Skip to content
Agent loop · Security

Secret Scan Until Clean

Scan the repository for committed credentials, move each one to environment configuration, flag it for rotation, and re-scan until no findings remain.

Up to 6 iterationsStop rules and safety limits
The prompt

Copy the Secret Scan Until Clean loop

Stops when the secret scanner reports no findings in the working tree, or after 6 iterations. Edit the settings block, then paste the whole prompt into your agent.

secret-scan-until-clean.prompt.md
You are running the "Secret Scan Until Clean" loop.

Settings (edit before running):
- Scan command: gitleaks detect --no-git --redact --report-format json --report-path /tmp/secret-scan.json
- Example env file: .env.example
- Max iterations: 6

Goal: no secret scanner findings in the working tree, with every real credential flagged for rotation.

Each iteration:
1. Run the scan command and read the report. Refer to findings by file, line, and rule only.
2. Classify each finding: real credential, test fixture, documentation example, or false positive.
3. For real credentials: replace the value with a read from an environment variable or the project's secret manager, add the variable name with a placeholder value to the example env file, and add it to the rotation list.
4. For fixtures and examples: replace with obviously fake values (for example "sk_test_EXAMPLE").
5. For false positives: add a narrowly scoped allowlist entry with a comment explaining why.
6. Re-run the scan.

Stop when:
- The scan reports no findings. Success.
- You reach the max iteration count.

Rules:
- Never print, log, copy, or echo a secret value, in your messages or in any file. Use redacted output only.
- Do not rewrite git history. Removing a secret from the working tree does not remove it from history, so every real credential must be rotated.
- Do not commit .env files or add real values to the example file.

Final report: the rotation list (variable name, file it came from, provider if known), changes made, and a reminder that history still contains the old values.
When to use it

When this loop fits

  • You are about to open-source a private repository or share it with a contractor.
  • A secret scanner in CI started failing after someone committed a config file.
  • You inherited a project and want to know which keys have been sitting in the code.
How it works

What happens on each pass

The agent repeats these steps until the stop condition holds or it runs out of iterations.

  1. Scan. Run the secret scanner on the working tree and list findings by file, line, and rule, with values redacted.
  2. Triage. Separate real credentials from test fixtures, examples, and false positives.
  3. Externalize. Replace each real secret with an environment variable or secret manager reference and add a placeholder to the example config.
  4. Re-scan. Run the scanner again and continue until the working tree is clean.
Recommended servers

MCP servers for this loop

The 6 strongest of 1754 matching servers, ranked by how closely they fit and then by trust score.

More in Security
  • Trust score 70 of 100, Good

    Vault Cortex

    by aliasunder · TypeScript

    Standalone MCP server for Obsidian vaults — hybrid search, notes & files, memory, tasks, OAuth 2.1

    Registry
    LicenseQualityMaintenanceLicense: A. MIT is a permissive open source license.Quality: Not graded. No README or tool list has been captured yet.Maintenance: A. Last commit or release 9 days ago.
    32 stars66/wk weekly downloads— tools
  • Trust score 55 of 100, Fair

    Browse, inspect, and retrieve installable React and Next.js interaction effects from Hyperiux Vault.

    Registry
    LicenseQualityMaintenanceLicense: Not graded. No license is recorded for this server.Quality: Not graded. No README or tool list has been captured yet.Maintenance: Not graded. No commit or release date has been recorded.
    — stars—/wk weekly downloads— tools
  • Trust score 55 of 100, Fair

    Indexed search, schema-checked writes and session hooks for a markdown notes vault

    Registry
    LicenseQualityMaintenanceLicense: Not graded. No license is recorded for this server.Quality: Not graded. No README or tool list has been captured yet.Maintenance: Not graded. No commit or release date has been recorded.
    — stars—/wk weekly downloads— tools
  • Trust score 55 of 100, Fair

    Value-blind secret metadata and gated workflows for AI coding agents through Phantom's local proxy.

    Registry
    LicenseQualityMaintenanceLicense: Not graded. No license is recorded for this server.Quality: Not graded. No README or tool list has been captured yet.Maintenance: Not graded. No commit or release date has been recorded.
    — stars—/wk weekly downloads— tools
  • Trust score 55 of 100, Fair

    Figma designs pulled once into a local vault; AI agents read them offline with no rate limits

    Registry
    LicenseQualityMaintenanceLicense: Not graded. No license is recorded for this server.Quality: Not graded. No README or tool list has been captured yet.Maintenance: Not graded. No commit or release date has been recorded.
    — stars—/wk weekly downloads— tools
  • Trust score 55 of 100, Fair

    Request and send secrets for AI agents, end-to-end encrypted and never shown in the chat.

    Registry
    LicenseQualityMaintenanceLicense: Not graded. No license is recorded for this server.Quality: Not graded. No README or tool list has been captured yet.Maintenance: Not graded. No commit or release date has been recorded.
    — stars—/wk weekly downloads— tools
Run it

How to run this loop

  1. Connect the tools. Install a server the loop can use, for example Vault Cortex, or rely on your agent's built-in terminal and file access.
  2. Edit the settings block. Replace the example commands, targets, and limits with your project's own. Keep the iteration cap low on the first run.
  3. Paste it into an agent session. Start a fresh session in Claude Code, Cursor, or VS Code agent mode, in the repository root, and paste the prompt.
  4. Review before you merge. Read the final report and the diff. The loop leaves its work for you to review rather than shipping it.
FAQ

Secret Scan Until Clean questions

When does the Secret Scan Until Clean loop stop?

It stops as soon as the secret scanner reports no findings in the working tree. It also stops after 6 iterations by default, or earlier when the prompt's own stop rules say it is stuck, and then reports what changed and what is left. Change the cap in the settings block at the top of the prompt.

Does this loop remove secrets from git history?

No, on purpose. Rewriting history is destructive and needs coordination with everyone who has a clone. More importantly, a secret that was ever pushed must be treated as leaked, so the real fix is rotation. The loop produces the rotation list for you.

Will the agent see my secrets while it works?

The scanner runs with redaction, and the prompt forbids printing or copying values. The agent still has file access, so run it in a session you trust, and rotate anything real regardless.

Keep exploring
All loops