Secret scanning in Claude Code, before anything is committed.
KeySafe brings secret scanning into Claude Code. It checks every file edit and every git add or commit before it happens. Writing a live key into a file git would commit is blocked, with a note to use an environment variable; the same key in a gitignored .env file is allowed. Commits that include .env files, private keys or credential files ask you first, and staged lines that contain a live key are blocked.

01See it work
KeySafe, in real use.
4 screens from real runs of KeySafe. Every value shown is what the tool returned; click a screen to open it full size.
02How it works
The same key, judged by where it is going.
A live key is not the problem; a live key in a file git will publish is. KeySafe checks every edit and every git add or commit, and decides by the destination. Real decisions on one Stripe key:
src/pay.jsBlocked.envAllowed.env.exampleBlockedtest/pay.test.jsAllowedgit add -f .envAsks firstgit commitBlocked03Compared
KeySafe, gitleaks and TruffleHog.
They work at different moments, so they fit together. KeySafe stops a secret before Claude writes it; gitleaks and TruffleHog find secrets in commits and history.
| KeySafe | gitleaks | TruffleHog | |
|---|---|---|---|
| When it runs | Before Claude writes a file or runs git add or commit | As a pre-commit hook or in CI | On demand or in CI, across repos and other sources |
| What it reads | The new content of each edit, and the staged lines | Commits and git history | Git history, and sources such as cloud storage |
| Checks if a key is live | No; it matches exact key formats | No | Yes, it can verify many key types |
| Best for | Stopping a leak while you work with Claude Code | Blocking leaks at commit and in pull requests | Finding leaks that already happened |
04If it already happened
A leaked API key: rotate first, then clean up.
Once a key has been pushed, assume someone has it. Removing it from history does not make it safe again; replacing it does.
- Rotate the key at the provider, so the leaked one stops working.
- Check the provider's logs for use you do not recognise.
- Move the new key into an environment variable or a gitignored .env file.
- Remove the old key from history if the repository is public or shared, then force-push and ask collaborators to re-clone.
- Keep it from happening again: KeySafe while you work, gitleaks in CI.
# replacements.txt holds one line per secret:
# sk_live_51Qx...9d==>REMOVED
git filter-repo --replace-text replacements.txt
git push --force --all05Detectors
35 key formats, and three more checks.
Keys are recognised by their exact format: prefix, length and alphabet. That is why a real key is blocked while test keys and placeholders pass.
| Detector | Covers | Decision |
|---|---|---|
| Key formats | AWS, GitHub (six token types), GitLab, Slack, Stripe live and restricted keys and webhook secrets, Anthropic, OpenAI, xAI, Groq, Google API and OAuth, npm, PyPI, Shopify, Hugging Face, DigitalOcean, Mailgun, Twilio, Sentry, Linear, Notion, Doppler | Blocked |
| Private keys | PEM blocks: -----BEGIN ... PRIVATE KEY----- | Blocked |
| Passwords in URLs | postgres://user:password@host and similar, skipping local hosts and stock passwords | Asks first |
| Named secrets | High-entropy values assigned to names such as client_secret, api_key or token | Asks first |
06Install
Install KeySafe.
Install KeySafe from the Dude Lemon marketplace inside Claude Code. Node.js 18+ and git.
/plugin marketplace add https://plugins.dudelemon.cloud/marketplace.json/plugin install keysafe@dudelemonRun both commands inside Claude Code. The first adds the Dude Lemon marketplace once; the second installs the plugin.
07What it adds
What the plugin adds to Claude Code.
File edits- Scans new content from Write, Edit and MultiEdit. Live keys in tracked files are blocked; gitignored .env files are fine; example files must hold placeholders.
git add and commit- Asks before .env files, .pem and .key files, SSH keys, keystores and credential files are added, and blocks commits whose staged lines contain a live key.
Detectors- AWS, GitHub, GitLab, Google, Stripe live and webhook, Slack, SendGrid, Twilio, Shopify, OpenAI, Anthropic, xAI, Groq, Hugging Face, npm, PyPI and more, PEM private keys, passwords in database URLs.
08Try it
Use it as you work.
Hooks work on their own; commands run when you type them in Claude Code.
- Add Stripe payments using my secret key.
- Commit everything.
- Set up the database connection.
FAQ
KeySafe, answered
Anything we have not answered here, ask us directly. A senior engineer replies.
Does KeySafe send my code anywhere?
No. It is a local Node script that reads the edit or the staged diff on your machine and decides there.
What about test keys?
Test-mode keys such as Stripe sk_test_ and obvious placeholders are allowed. Values that only look like secrets (a long random string assigned to client_secret, say) ask instead of block.
What if a key was already pushed?
KeySafe prevents new leaks; it cannot unpublish old ones. Rotate any key that has been pushed, then remove it from the code.
Is KeySafe free?
Yes. KeySafe is free and MIT licensed.
How do I install KeySafe?
In Claude Code run /plugin marketplace add https://plugins.dudelemon.cloud/marketplace.json, then /plugin install keysafe@dudelemon.
Should I use KeySafe and gitleaks together?
Yes. KeySafe stops secrets during work in Claude Code; gitleaks in CI covers commits made outside it and by other people.


