Aan de slag
Secret Scan: Find Leaked Keys in Your Git History

Secret Scan: Find Leaked Keys in Your Git History

Before a repository goes public, Secret Scan finds API keys, tokens and passwords that were ever committed, including ones deleted in a later commit, and says which are still in your files. One standard-library Python script that runs locally: no network code, it never runs git, and it never prints a full value. Your agent reports the findings and what to do about each. Free and open source (MIT).
#Techniek
Beoordeling
Meer beoordelingen nodig
Verkocht
1
Gebruikswijze
Downloaden

Deleting a key in a later commit does not remove it: it stays in the Git history for anyone who clones the repository. Secret Scan is for developers who are about to make a repository public, share code, or check after a suspected leak. Your agent exports the history, runs one local Python script over it and your current files, and tells you which keys, tokens and passwords were ever committed, which are still in your files, and what to do about each.

What you get

  • SKILL.md: the instructions your agent follows: how to run and report the scan, what to do about a finding and in what order, and the rules.
  • scripts/secretscan.py: one readable Python file, standard library only. Reads a history export (the text file made by git log -p --all) and, with --tree, the files in a folder. Finds AWS access key ids, GitHub tokens, Stripe live keys, Slack tokens, Google API keys, AI provider keys, private key blocks, JSON web tokens, passwords in URLs, and hard-coded password, secret, token and API key assignments (names such as db_password, clientSecret or ApiKey). Writes nothing to disk and prints one JSON report. Local only: no network code, and it never runs git itself.
  • LICENSE.txt: the MIT licence.

Requirements and install

Python 3.8 or newer and git. No pip installs. Unzip the download: you get one folder named secret-scan. Put that folder in your agent client's skills folder. It is written for agent clients that read SKILL.md and can run a shell command, such as Claude Code or Codex CLI. Tested on Windows 11 with Python 3.13 and git 2.55.

How to use

Ask your agent in plain words:

  • "Check this repo's whole history for leaked keys before I make it public."
  • "Did I ever commit an API key or password in this project?"
  • "Scan my working tree for hard-coded credentials before I push."

Sample run

A scratch repository with 6 commits and fake keys made for the test. The AWS key id was deleted in the second commit and is still found. Paths are shortened and ... marks cut lines.

git log -p --all --output=<temp>/history.patch
python <skill-folder>/scripts/secretscan.py <temp>/history.patch --tree .
{
 "clean": false,
 "scanned": {
  "commits": 6,
  "added_lines": 51,
  "files": 11,
  "unreadable_files": 0,
  "values_marked_ignore": 1
 },
 "found": 7,
 ...
 "findings": [
  ...
  {
   "type": "GitHub token",
   "file": "deploy.sh",
   "commit": "c93d2edda7b0",
   "times_seen": 2,
   "in_working_tree": true,
   "line": 3,
   "value": "ghp_... (40 chars)"
  },
  ...
  {
   "type": "AWS access key id",
   "file": "app/config.py",
   "commit": "ab830e4ccd1b",
   "times_seen": 1,
   "in_working_tree": false,
   "value": "AKIA... (20 chars)"
  },
  ...
 ],
 ...
}

Output format

Plain text. The script prints one JSON object: clean, scanned, found, by_type, findings (type, file, oldest commit, line, times seen, in the working tree or not, masked value) and the next steps. Your agent shows it as a table in the chat, values still in your files first. No files are created. An error is one JSON line on standard error with exit code 1.

Network and data

The script contacts no host and sends nothing. A found value is shown as its first 4 characters and its length, never in full. The export holds every value in full, so the instructions keep it outside the repository and delete it after the scan. The skill calls no AI service itself. Your agent client sends the conversation to the model provider you use: the masked report, and a full value too if you ask the agent to open or edit the file that holds it.

What is automatic and what asks first

Automatic, and read-only for your repository: exporting the history to a temporary file, running the scan, reporting, deleting the export. Needs your explicit yes first: editing a file, changing .gitignore, marking a false positive, and any history rewrite or force-push. A rewrite is destructive and breaks other clones: the skill says so, tells you to keep a backup, and never treats it as a substitute for rotating the key. Rotating a key is your own action in the provider's console.

Limits

  • Pattern-based: a secret in a format not listed above can be missed. A clean result is not proof.
  • A hard-coded assignment is found only when the value is in quotes, has 12 or more characters and looks random. An unquoted value, as in most .env files, is found only if it matches a known key format.
  • The working-tree scan reads untracked and ignored files too. A key in an ignored file that was never committed is reported apart as local only, not as leaked.
  • A value added only while resolving a merge, or only on a deleted branch, is not in the export.
  • Skipped: binary files, files over 1 MB in the working tree, submodule history, and folders named .git, node_modules, venv, .venv, dist, build, __pycache__, .next or vendor.
  • Several private keys with the same header line show as one finding with a count.
  • The history export must be UTF-8. A UTF-16 file, which a PowerShell > redirect writes, is refused with an error. The instructions use git's own --output option.

FAQ

Does it send my code or keys anywhere? The script sends nothing: it has no network code, and you can read all of it. What your agent client sends to its model provider is described under Network and data.

Will it clean my history? No, the scan only reads. Your agent can help with a rewrite if you ask, with your explicit yes.

It flagged a test value. What now? Once you confirm it is not a real credential, add secretscan:ignore to that line in your files. A scan of history and files then leaves that value out. A history-only scan still reports it.

Licence

MIT. Copyright (c) 2026 Abdullah Rathore. The full text is in LICENSE.txt and the full source is in the package.