Secret scanning in Claude Code, before anything is committed.
KeySafe brings secret scanning into Claude Code. It checks every file edit, file read and git command 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 and pushes that contain a live key are blocked, including commits made before KeySafe was installed, and reading .env or key files into the conversation asks first. /keysafe-scan checks the whole repository and its history. Every leak comes with rotation steps, and the same checks install as git hooks.
Free, MIT licence. Node.js 18+ and git.

See 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.
How 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 commitBlockedCompared
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 |
If 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 --allDetectors
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 |
Install
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.
What 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, commit and push- Asks before secrets files are added, blocks commits whose staged lines hold a live key, and blocks pushes whose unpushed commits hold one.
Reads- Asks before Read, cat or head open .env and key files, and before bare printenv, since their values would enter the conversation.
/keysafe-scan- Tracked files and, on request, every commit on every branch, with what to do for each finding.
Detectors- More than 70 formats: cloud, code hosting, payments, messaging and AI services, Supabase service-role tokens, Azure connection strings, PEM keys and passwords in database URLs.
Rotation steps- Where and how to rotate each kind of leaked key, for more than 30 providers.
/keysafe-hooks- The same checks as git pre-commit and pre-push hooks, for commits made outside Claude Code.
Try 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.
Contact usDoes KeySafe send my code anywhere?
No. It is a local Node script that reads the edit, the command or the staged diff on your machine and decides there.
What about test keys and false positives?
Test-mode keys such as Stripe sk_test_, local database URLs and obvious placeholders are allowed. Every finding carries a short id; add it to allowIds in .keysafe.json to allow that value from then on.
What if a key was already pushed?
KeySafe blocks new leaks and /keysafe-scan finds old ones, but it cannot unpublish anything. 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.



