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 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.

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 hooksNode.js 18+ and git

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.

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

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
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.

03Compared

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

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.

  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

05Detectors

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

06Install

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.

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.