Available in
Marketplaces, most starred first
Tags
Add to README
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
By karanb192v1.1.3MITIn 1 marketplace
Blocks Claude from reading, editing or leaking .env files, SSH keys and cloud credentials before each file, search or shell call runs. Matches are denied with the rule id, or prompted if you enable ask mode per safety level via HOOK_SAFETY_LEVEL.
Trending plugins
7-day copy clicks
Run automatically on Claude Code events. Claude doesn't decide.
2 cautions to review before installing
A hook runs when Claude uses the Bash tool
A hook runs when Claude writes or edits files
Static checks of hooks, mods, MCP servers and commands. Not a security audit.
1 marketplace, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Secrets firewall: stops Claude from reading, modifying, or exfiltrating sensitive files (.env, SSH keys, cloud credentials) before the tool call runs.
A PreToolUse hook fires before every Read, Edit, Write, Bash, and Grep call. File tools and searches are checked against sensitive-path patterns (.env and .envrc, SSH private keys and authorized_keys, AWS/kube/gcloud/azure/docker credentials, .netrc/.npmrc/.pypirc, PEM/key/PKCS12 files, keystores, vault tokens); Bash commands are checked against secret-exposing patterns (cat/less/head on secrets, printenv and bare env dumps, echo $SECRET_KEY-style variable prints, sourcing .env, /proc/*/environ) and exfiltration patterns (curl/wget uploads, scp/rsync/nc of secrets, plus cp/mv/rm/truncate on them). A match returns permissionDecision: "deny" (or "ask", see below) with the pattern id and reason, so you always know exactly which rule fired. Template files like .env.example, .env.sample, and .env.template are explicitly allowlisted. In a Bash command the allowlist applies to each path on its own, so a template name elsewhere in the command (cat .env # .env.example) does not clear the real file. Path matching is separator-agnostic, so a Windows C:\Users\me\project\.env is treated exactly like /home/me/project/.env.
/plugin marketplace add karanb192/claude-code-hooks # once per machine
/plugin install protect-secrets@claude-code-hooks
Restart Claude Code, done. (Or from a shell: claude plugin install protect-secrets@claude-code-hooks.)
| Event | Runs | What happens |
|---|---|---|
PreToolUse (Read|Edit|Write|Bash|Grep) | sync (must decide before the tool runs) | Matches the file path (Read/Edit/Write), the search target (Grep) or the command (Bash) against tiered sensitive patterns; on a hit, denies or asks with the pattern id and reason. Everything else passes through untouched. |
Grep checks path, glob, and the legacy include field, plus each filter joined to the search directory. For example, path: C:\Users\me\.aws with glob: credentials is blocked. Every candidate is checked at the configured safety level; an allowed template or an inactive rule cannot hide another sensitive target. When several targets match, the most severe rule wins.
The guard normalizes backslashes in file and search targets, including relative paths, UNC paths, and mixed separators. It does not resolve symlinks, expand globs, or change filename case rules. Bash command strings keep their existing checks because backslashes there can be shell escapes. PowerShell calls are outside this plugin's matcher.
Broad searches can still expose secrets. A directory-only search, a pattern-only search, or a glob such as * need not name a sensitive file. This hook does not enumerate the files a search will read or filter its output. Use the native permissions and sandbox controls alongside it.
Patterns are tiered; each level includes everything below it:
| Level | Blocks | Use case |
|---|---|---|
critical | SSH keys, AWS creds, .env files, PEM/key/PKCS12 files | Maximum flexibility |
high (default) | + secrets/credentials files, env dumps, secret-variable echoes, exfiltration, copy/move/delete of secrets, secrets fed to an external model CLI or model API (delegation sinks) | Recommended |
strict | + database configs, known_hosts, .gitconfig, recursive greps for passwords, any file contents fed to an external model | Maximum safety |
All optional, set via environment variables (in the hook command, or exported where Claude Code runs):
| Variable | Default | Purpose |
|---|---|---|
HOOK_SAFETY_LEVEL | high | Safety level: critical, high, or strict. Invalid values fall back to high, so a typo can never silently disable the guard. |
HOOK_ASK_CRITICAL | unset (deny) | Literal string true makes critical-level matches prompt you instead of blocking. |
HOOK_ASK_HIGH | unset (deny) | Same, for high-level matches. |
HOOK_ASK_STRICT | unset (deny) | Same, for strict-level matches. |
Ask mode is strictly opt-in and per level: only the literal string true enables it, and enabling it for one level never softens another. A common setup: keep critical on deny, set HOOK_ASK_STRICT=true so cautionary patterns prompt instead of blocking.
Built from public signals: copy clicks on this site, GitHub stars and activity, the README and the manifest. Not a security audit or an endorsement.
npx claudepluginhub karanb192/claude-code-hooks --plugin protect-secretsPlugins from other owners that cover similar ground