Protect Secrets
Blocks the agent from reading or writing secret material — .env files, keystores, private keys, credentials.json, secrets/ directories and any globs in forgekit.yaml security.denyPaths — through file tools and shell commands, while still allowing .env.example.
What it does
Blocks the agent from reading or writing secret material — .env files, keystores, private keys, credentials.json, secrets/ directories and any globs in forgekit.yaml security.denyPaths — through file tools and shell commands, while still allowing .env.example.
- Category
- securitysafety
- Platforms
- any
- Capabilities
- guardrailsecret-protection
Example tasks
- “The agent tries to cat .env to debug a failing build and is told to ask for variable names instead.”
- “A teammate adds vault/** to security.denyPaths and the agent can no longer open files there.”
- “The agent copies .env.example to .env for a new checkout and is blocked, so a human fills in real values.”
Works with
Permissions summary
Files
Reads files only
Shell
No shell commands
Network
No network
Permissions are declared in the component manifest and compiled into each client's tool list. Components are built for least privilege.
Supported environments
| Client | Support | Installed as |
|---|---|---|
| Claude Code | Native | .forgekit/hooks/<id>/ + .claude/settings.json |
| OpenAI Codex | Not supported | Skipped (reported at install) |
| Cursor | Not supported | Skipped (reported at install) |
| VS Code (Copilot) | Not supported | Skipped (reported at install) |
| Generic markdown | Adapter | docs/forgekit/hooks/<id>.md |
Claude Code is the native reference. Other clients use adapters, so behaviour is close but not identical. See the compatibility matrix.
Included in packs
Full hook (free preview)
This is a free component, so its complete content is public. It is exactly what gets installed (before client-specific formatting).
protect-secrets
A deterministic guardrail that keeps secret material out of the model's context and out of its edits. It is the one hook every project should install, so it is free.
What it does
The script inspects every tool call that can touch a file or the shell and exits with code 2 (block) when the target is protected. The reason is printed to stderr as a single line and fed back to the model, together with advice to use .env.example and to ask the user to handle real secrets.
| Protected | Examples |
|---|---|
| Environment files | .env, .env.local, .env.production, prod.env, .envrc |
| Signing material | *.keystore, *.jks, *.p12, *.pfx, *.ppk, AuthKey_*.p8 |
| Private keys | *.pem and *.key unless the name is clearly public (fullchain.pem, public.key), id_rsa*, id_ed25519*, id_ecdsa* (the .pub file is allowed) |
| Credentials | credentials.json, .netrc, .git-credentials, .pgpass, .aws/credentials |
| Directories | any secrets/ (or .secrets/) directory component, such as secrets/api.txt |
| Your own globs | everything under security.denyPaths in ./forgekit.yaml |
Always allowed: .env.example, .env.sample, .env.template.
When it fires
PreToolUse for Edit, Write, MultiEdit, Read and Bash. For file tools it checks file_path. For Bash it splits the command into simple commands (handling ;, &&, |, $(...), backticks, quotes and bash -c "...") and blocks when:
- a redirect target is protected (
echo KEY=1 >> .env,tee secrets/x), or - an argument of a reading or copying command is protected (
cat .env,cp .env.example .env,base64 release.jks,python -c "open('.env')",docker run --env-file=.env).
Harmless uses are left alone: ls secrets/, git rm --cached .env, echo .env >> .gitignore, grep -q .env .gitignore, commit messages that mention .env.
Configure
Add globs to forgekit.yaml; both block lists and inline lists are read by a tiny built-in parser (no YAML dependency):
security:
denyPaths:
- ".env"
- "secrets/**"
- "infra/*.tfvars"
- "vault/**"
A pattern without / matches any path segment or file name; a pattern with / is anchored at the project root. ** spans directories.
Fail-safe behaviour
Malformed or empty hook input exits 0 with a note on stderr, so a broken payload never wedges the session. Clear matches are always blocked. Symlinks and shell indirection (for example building a path from variables) are not resolved, so treat this as a seat belt next to file permissions and secret scanning, not a vault.
Disable
Remove the protect-secrets entry that ForgeKit wrote to .claude/settings.json (listed in .forgekit/manifest.json), or narrow its scope by editing security.denyPaths. Run the tests with node --test "registry/hooks/protect-secrets/scripts/*.test.mjs".
Version and changelog
Latest version 1.0.0. Requires DevBuildKit CLI 1.0.0 or newer.
Changelog — Protect Secrets
1.0.0
- Initial release.