I run several Claude Code agents with access to real projects. The failure I worried about most was an agent running `vercel env pull` or printing `.env.local` and putting every value into a transcript that persists.
Telling the agent "be careful with .env files" didn't hold. It worked around the instruction with grep, `python -c "open(...)"`, `find -exec cat` or a `while read` loop.
So these are four dependency-free Python hooks that enforce the rule at the tool-call boundary:
- secret-exposure-guard (PreToolUse): blocks commands and Read/Edit calls that would print a secret value, covering dotenv printers, copiers, matchers that print the matching line, git show/diff on a dotenv, credential files, secret-manager CLIs and the common evasions. 136 self-test cases: 80 must block, 51 must allow, 5 end-to-end. v1.1 also strips wrappers like `timeout 5` or `nice -n 10` before matching, after one slipped through on a real session.
- secret-guard (UserPromptSubmit): blocks a prompt that contains a pasted credential.
- chrome-secret-redact (PostToolUse on browser tools): rewrites browser-tool text output (known key prefixes, long hex, key-shaped tokens on API-key pages) before the model reads it. It can't redact a screenshot, so pair it with a rule never to screenshot key pages.
- needs-you-gate (Stop): when the agent ends a turn by handing work back to you, it makes the agent check once whether it could do the work itself. It blocks at most once per turn, so it can't loop.
Design rules: names are free, values are not, so every block message names a safe alternative (`vercel env ls`, `cut -d= -f1 .env.local`) and the self-test covers each one. Everything fails open, because a guard that breaks sessions gets deleted.
Known gaps, on purpose: `grep -r NAME .` across a tree that holds a dotenv looks exactly like a code search, so it stays open. Nothing can pull a value back out of a transcript once it's there. And an agent can type the override prefix itself, so this is a speed bump against accidents, not a sandbox.
MIT. I'd like to hear about workarounds it misses.
j1mmyhackett•17m ago
Telling the agent "be careful with .env files" didn't hold. It worked around the instruction with grep, `python -c "open(...)"`, `find -exec cat` or a `while read` loop.
So these are four dependency-free Python hooks that enforce the rule at the tool-call boundary:
- secret-exposure-guard (PreToolUse): blocks commands and Read/Edit calls that would print a secret value, covering dotenv printers, copiers, matchers that print the matching line, git show/diff on a dotenv, credential files, secret-manager CLIs and the common evasions. 136 self-test cases: 80 must block, 51 must allow, 5 end-to-end. v1.1 also strips wrappers like `timeout 5` or `nice -n 10` before matching, after one slipped through on a real session.
- secret-guard (UserPromptSubmit): blocks a prompt that contains a pasted credential.
- chrome-secret-redact (PostToolUse on browser tools): rewrites browser-tool text output (known key prefixes, long hex, key-shaped tokens on API-key pages) before the model reads it. It can't redact a screenshot, so pair it with a rule never to screenshot key pages.
- needs-you-gate (Stop): when the agent ends a turn by handing work back to you, it makes the agent check once whether it could do the work itself. It blocks at most once per turn, so it can't loop.
Design rules: names are free, values are not, so every block message names a safe alternative (`vercel env ls`, `cut -d= -f1 .env.local`) and the self-test covers each one. Everything fails open, because a guard that breaks sessions gets deleted.
Known gaps, on purpose: `grep -r NAME .` across a tree that holds a dotenv looks exactly like a code search, so it stays open. Nothing can pull a value back out of a transcript once it's there. And an agent can type the override prefix itself, so this is a speed bump against accidents, not a sandbox.
MIT. I'd like to hear about workarounds it misses.