π‘οΈ Prevent secrets and PII from being accidentally shared with Claude Code.
A privacy-first plugin for Claude Code that scans prompts for sensitive data and blocks them before they reach the AI.
- β Blocks prompts containing sensitive data before they're sent to Claude
- β Detects PII, secrets, API keys, tokens, and sensitive information
- β Works locally - all scanning happens on your machine
- β Zero configuration - works out of the box
- β Detailed reporting - shows exactly what was detected
# Add the marketplace (if not already added)
/plugin marketplace add datumbrain/claude-code-privacy-guard
# Install the plugin
/plugin install claude-code-privacy-guard
β οΈ Important: Restart RequiredAfter installing the plugin, you must restart your Claude Code session for it to take effect. This is because hooks are registered at session startup - Claude Code doesn't dynamically load new hooks mid-session.
Simply close and reopen Claude Code, or start a new session.
Once restarted, the plugin will automatically scan all prompts before they reach Claude.
β Secrets
- OpenAI API keys (
sk-...,sk-proj-...) - AWS credentials
- GitHub tokens
- Stripe keys
- JWT tokens
- Bearer tokens
- SSH private keys
- Generic API key patterns
β Personal Information (PII)
- Email addresses
Phone numbers, Social Security Numbers, and credit card numbers are not currently detected by the default configuration - see #7 for tracking status.
- You type a prompt in Claude Code
- Privacy Guard intercepts it via a
UserPromptSubmithook - Scans for sensitive data using regex patterns
- Blocks the prompt if sensitive data is found
- Shows you exactly what was detected
Blocking relies on the UserPromptSubmit hook JSON protocol: the hook prints {"decision": "block", "reason": "..."} to stdout and exits with code 0. (Exit code 0 is required for the JSON decision to be honored - a non-zero exit is treated as a non-blocking hook error, and the prompt would go through anyway.)
Input:
My API key is sk-proj-abc123xyz and email is john@example.com
Result:
π‘οΈ Privacy Guard blocked this prompt
Found 2 sensitive item(s):
- API_KEY: sk-proj-abc123xyz...
- EMAIL: john@example.com...
Risk Score: 100/100
Secrets: 1 | PII: 1
Please remove or anonymize sensitive data before proceeding.
Create a .privacy-guard.json file (searched upward from your current
working directory, so a repo-root or home-directory config both work) to
override the defaults. See .privacy-guard.example.json for a starter
file.
| Option | Type | Default | Status |
|---|---|---|---|
enabled |
boolean |
true |
β
Implemented. Set to false to disable the plugin entirely without uninstalling it. |
disabledRules |
string[] |
[] |
β
Implemented. Rule IDs to skip - see the built-in id fields in src/scanner/detectors.ts or the name fields in data/regex_list_1.json for external rules. |
externalRulesJsonPath |
string |
./data/regex_list_1.json |
β Implemented. Path (relative to the config file's directory) to the external regex dataset. |
externalRulesMode |
"coding-only" | "all" |
"coding-only" |
β
Implemented. "coding-only" filters the external dataset down to rules whose name/description mentions a coding-secret keyword (key, token, secret, password, private key, etc.); "all" loads every external rule. |
strictMode |
boolean |
false |
|
allowedDomains |
string[] |
[] |
|
redactionStyle |
"placeholder" | "mask" | "remove" |
"placeholder" |
|
autoMaskOnHighRisk |
boolean |
true |
Example:
{
"enabled": true,
"disabledRules": [],
"externalRulesJsonPath": "./data/regex_list_1.json",
"externalRulesMode": "coding-only"
}# Clone the repository
git clone https://github.com/datumbrain/claude-code-privacy-guard.git
cd claude-code-privacy-guard
# Install dependencies
npm install
# Build
npm run build
# Test the scanner directly
echo "test sk-proj-abc123" | node scripts/prompt-guard.jsRelease:
make releaseThis runs an interactive flow that asks for version bump, confirms release actions, updates CHANGELOG.md, runs build/test, creates commit+tag, and optionally pushes/publishes.
See CONTRIBUTING.md for how to add a detection rule and the dist/ rebuild requirement, and docs/ for detailed architecture and integration guides.
- β All scanning happens locally on your machine
- β No data is sent to external services
- β No telemetry or tracking
- β Open source and fully auditable
- β The plugin only blocks - it doesn't store or log your sensitive data
Claude Code's hook system doesn't support transforming prompts - only blocking or adding context. Blocking ensures sensitive data never reaches the AI, which is the safest approach.
Debug logging is off by default. To enable it, set PRIVACY_GUARD_DEBUG=1 in your environment before starting Claude Code, then check the log:
cat "${XDG_CACHE_HOME:-$HOME/.cache}/claude-code-privacy-guard/debug.log"The log only contains execution metadata (working directory, Node version, exit codes) - it never contains matched secret or PII values.
Contributions welcome! See CONTRIBUTING.md for dev setup, how to add a detection rule, and the release process.
MIT Β© Datum Brain
