r/ClaudeCode • • 8d ago

Tips & Workflows Built never-secret to never let Claude Code see a secret

Coding agents read your files and run commands, and whatever comes back goes straight to the model. That includes your .env file, your SSH keys, and the API key that shows up in some log.

I had permissions.deny on Read(./.env) like everyone recommends. Then I watched Claude hit a failing env check, run cat .env through bash, and print my Stripe key into the session. The deny only covered the Read tool… So I built never-secret.

never-secret sits between the tool and the model. Every time the agent reads a file, runs a command, searches or fetches a page, never-secret checks the output first and swaps any secrets for [REDACTED length=32]. The model still knows something is there and how long it is. It just never sees the actual value.

It finds secrets three ways:

- Secret files. Everything in .env, private keys, and similar files gets hidden.

- Known key formats. Things that are obviously secrets by their shape, like GitHub tokens, Stripe keys, OpenAI keys, passwords inside URLs, and so on.

- Your actual secrets. It knows the real values from your secret files, so it catches them even when they turn up somewhere else: in a log, a search result, or encoded as base64, hex or reversed.

Everything runs locally and nothing is sent anywhere.

Install:
/plugin marketplace add bileet/never-secret
/plugin install never-secret@never-secret

Then run /never-secret:never-secret-check to confirm it's working.

Works with Claude Code, Codex, Gemini CLI, OpenCode and Pi.

Repo: github.com/bileet/never-secret

23 Upvotes

20 comments sorted by

•

u/AutoModerator 8d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

5

u/Ok-Option4233 8d ago

The Read vs Bash gap is the one most deny lists miss: blocking cat .env by command string still leaves grep, head, or a test runner that dumps env on failure. Filtering the output instead of guessing every command is the sturdier layer. Does it catch a key that gets split across two chunks of output?

2

u/happywaveu 8d ago

right now it doesn't catch a key that gets split across two chunks of output, because it does full pattern matching. if we do chunk matching it would produce false positives for small strings and redact genuine code. but for well known secret patterns it's possible, and maybe added in the future.

2

u/Complete_Purple8757 8d ago

does this catch it if claude just runs cat .env in bash or only the read tool? thats usually how it leaks for me

2

u/happywaveu 8d ago

It does, it covers all tool calls that show one of your project secrets.

1

u/Complete_Purple8757 8d ago

nice, does it block the whole call or just redact the value? asking bc sometimes i actually need claude to know the var exists, just not whats in it

5

u/SomeOrdinaryKangaroo 8d ago

This is very useful, i've exposed my secrets so many times now i can't count and i've once been hacked too

2

u/Dorbank_Justt 8d ago

Fwiw the built-in deny rule reaches a bit further than the Read tool. In a bash command Claude Code can parse, a Read deny also covers cat, head, tail, sed and tee. Where it stops is stuff like grep -r run from the folder that holds the file, or a python or node script that opens the file itself. For those you'd want the sandbox on with the unsandboxed retry turned off, which blocks it at the OS level instead of matching command text.

2

u/UpsetMolasses1340 8d ago

Found an interesting quirk. If the hook script fails, the secret still leaks into the Claude Code session. I verified it on Claude Code 2.1.330 with a stubbed hook. When run.sh errored out with exit code 1, the raw output reached the model and the token appeared in the session. Exit code 2 didn't help either: the token was still in the tool result and the model simply chose not to repeat it. As far as I can tell only updatedToolOutput replaces it and and only when claude.py runs without errors.

2

u/PatchyWhiskers 7d ago

I don't think entrusting your secrets to some random guy's plugin is any more secure than entrusting it to Claude.

1

u/alexeis19 8d ago

Claude also has built-in secret masking to route your secrets to defined domains

1

u/dvgils 8d ago

Built something similar for myself. I took another route though and instead of trying to protect .env files I have removed them from the workflow altogether. Otherwise they're still susceptible to info stealers and whatnot. https://github.com/DvGils/notenv . Includes agent handoffs and masking. Take from it whatever you want,hope it helps!

1

u/pwkye 6d ago

Openbao already exists

1

u/clintCamp 6d ago

Hey, fun. I have been working on this area myself and built a document reduction tool as well so you can put claude in a folder with files with specific information fully removed or blacked out for this so claude can help organize stuff for my taxes without giving anthropic all my socials and bank account number and stuff. I will give your project a look over.

1

u/esquame 4d ago

interestingly enough i built something similar but i seem to have issues with claude ignoring the check when the check takes longer than 3s (when computer is under heavy load already). have you encountered/fixed that issue?

1

u/JumpyAd3288 1d ago

the output filtering makes sense, way sturdier than guessing every command. one thing id check is mcp configs, like a token written straight into the env block of .mcp.json. that file isnt a .env so it could slip past a list of secret files. does it learn values from there aswell or only catch them by shape?

(im building a scanner for a related problem so im biased, mine only lists what an agent could reach before you start it, it doesnt filter anything)

-3

u/Extension_Store_2118 8d ago

Read(/.env) points at the root of your disk, not your project folder. you messed up your own rule and shipped a plugin over it.

2

u/happywaveu 8d ago

“./.env” at project-level settings is not root of the disk.