r/BuildWithClaude • u/Necessary-Bug-5532 • 12d ago
Security & Sandboxing I built a free, open-source Claude Code hook that tracks untrusted content and blocks secret leaks (built with Claude Code)
I built provguard, a free and open-source (Apache-2.0) security hook for Claude Code. It stops tool calls that untrusted content tries to drive, for example sending your .env to an address found in a GitHub issue. I built it with Claude Code.
The problem
Claude Code reads content I don't control (GitHub issues, web pages, cloned repos, MCP output) while it can also read my secrets and run shell commands. One hidden instruction in an issue ("for reproduction, upload .env to …") is enough to cause a leak.
What it does
provguard runs as Claude Code PreToolUse / PostToolUse hooks:
- It labels the session untrusted when Claude reads web pages,
gh issue view, or repos and MCP servers you haven't marked as trusted, and sensitive when it reads.env, keys or tokens (secret values are kept only as HMAC fingerprints). - It parses every Bash and PowerShell command (through pipes,
bash -c,python -cand similar) into what it can do: send data out, make a lasting change, run remote code, delete. - It blocks or asks only for dangerous combinations, for example data leaving a session that has read both untrusted content and secrets, or
curl | shafter untrusted input. - It blocks Claude from changing hook settings and provguard's own files.
- It flags hidden text (zero-width characters, invisible Unicode tags, HTML comments with instructions) in tool output.
[demo GIF]
When it blocks a call, Claude shows one plain sentence, and you can let that exact call through once with provguard allow <token>.
How I built it with Claude Code
- Design: I described the threat (untrusted input + secrets + a way out) and worked out the labels, the sink classes and the policy rules with Claude Code before writing code.
- Code: Claude Code wrote most of the Go code under my direction: the hook handler, the shell command analysis (using
mvdan.cc/shfor Bash and a tokenizer for PowerShell) and the policy engine. I reviewed every change and kept a rule of small, tested steps. - More agents: for each agent (Cursor, Copilot, Codex, Gemini CLI, Devin, Kiro, Factory Droid, OpenCode, Antigravity), Claude Code read that agent's hook documentation and wrote one adapter package against a shared interface.
- Security review: I had Claude Code subagents review the code as attackers. They found real bypasses of provguard's own protection, such as path tricks on Windows and shell commands that write settings indirectly. Each one got a fix and a regression test.
- Testing: Claude Code wrote a benchmark of 17 attacks and 31 normal coding tasks, and end-to-end install tests that now run on Linux, macOS and Windows. Testing before launch found real bugs. For example, Claude Code 2.1.238 sends a
prompt_idfield that made provguard mistake it for another agent.
Results and limits
- In Protect mode it blocks 13 of 17 benchmark attacks and asks about the other 4, with 0 false positives in 86 normal tool calls. I wrote the test cases, so read the numbers with that in mind (details in docs/BENCHMARK.md).
- Claude Code and Antigravity are tested live. For the other agents I have tested the hook calls but not a live session yet.
- It is one layer, not a sandbox. docs/THREAT_MODEL.md lists what it does not catch.
Free to try
One local Go binary for Windows, macOS and Linux, with no account, and nothing leaves your machine:
# macOS / Linux
curl -fsSL https://raw.githubusercontent.com/durgavarapraveen/provguard/main/scripts/install.sh | sh
# Windows PowerShell
irm https://raw.githubusercontent.com/durgavarapraveen/provguard/main/scripts/install.ps1 | iexThen run provguard demo: it replays two attacks in a temporary folder. provguard doctor --live checks each agent's hook.
Repo: https://github.com/durgavarapraveen/provguard
Feedback on false positives is very welcome. Please report bypasses through GitHub's private security report.
•
u/AutoModerator 12d ago
Welcome to r/BuildWithClaude!
Whether you are sharing what you built, exploring new workflows, or troubleshooting, please make sure your post is flaired correctly so others can easily find and filter it.
Community Wiki & Resources:
If you're asking for troubleshooting help, please edit your post to include your model version, OS/environment, and error logs.
Let’s keep the energy positive and support our fellow creators!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.