KeySafe logo
KeySafeClaude Code plugin by Dude Lemon

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.

KeySafe blocking a live Stripe secret key written into src/pay.js, then allowing it in a gitignored .env file read through process.env
At a glanceClaude Code pluginkeysafe@dudelemon2 hooks, 2 commandsNode.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.

KeySafe blocking a live Stripe secret key written into src/pay.js, then allowing it in a gitignored .env file read through process.env
A live key kept out of the code, and put where it belongs

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
A tracked source fileGit would commit it. Read the key from an environment variable instead.
.envAllowed
A gitignored env fileThe right place for a secret: git will not commit it.
.env.exampleBlocked
An example fileExample files get committed, so they must hold placeholders.
test/pay.test.jsAllowed
A Stripe test keysk_test_ keys and obvious placeholders are not secrets.
git add -f .envAsks first
Forcing a secrets file into gitUsually a mistake; you confirm if it is intended.
git commitBlocked
A live key in the staged linesWhatever file it is in, the commit stops until it is removed.

Compared

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.

KeySafegitleaksTruffleHog
When it runsBefore Claude writes a file or runs git add or commitAs a pre-commit hook or in CIOn demand or in CI, across repos and other sources
What it readsThe new content of each edit, and the staged linesCommits and git historyGit history, and sources such as cloud storage
Checks if a key is liveNo; it matches exact key formatsNoYes, it can verify many key types
Best forStopping a leak while you work with Claude CodeBlocking leaks at commit and in pull requestsFinding 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.

  1. Rotate the key at the provider, so the leaked one stops working.
  2. Check the provider's logs for use you do not recognise.
  3. Move the new key into an environment variable or a gitignored .env file.
  4. Remove the old key from history if the repository is public or shared, then force-push and ask collaborators to re-clone.
  5. Keep it from happening again: KeySafe while you work, gitleaks in CI.
Remove a string from git history with git-filter-repo
# replacements.txt holds one line per secret:
# sk_live_51Qx...9d==>REMOVED

git filter-repo --replace-text replacements.txt
git push --force --all

Detectors

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.

DetectorCoversDecision
Key formatsAWS, 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, DopplerBlocked
Private keysPEM blocks: -----BEGIN ... PRIVATE KEY-----Blocked
Passwords in URLspostgres://user:password@host and similar, skipping local hosts and stock passwordsAsks first
Named secretsHigh-entropy values assigned to names such as client_secret, api_key or tokenAsks first

Install

Install KeySafe.

Install KeySafe from the Dude Lemon marketplace inside Claude Code. Node.js 18+ and git.

Inside Claude Code2 commands, in order
/plugin marketplace add https://plugins.dudelemon.cloud/marketplace.json/plugin install keysafe@dudelemon

Run 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 us
Does 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.