Skip to content
DevBuildKit
AgentsSkillsCommandsPacksPricingDocsBlogTools
Log inGet DevBuildKit

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.

HookFreev1.0.0
  1. Hooks
  2. Protect Secrets

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

Recommended alongside

  • Secret Management· skill
  • /secrets-scan· command
  • Security Auditor· agent
  • Block Destructive Commands· hook

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

ClientSupportInstalled as
Claude CodeNative.forgekit/hooks/<id>/ + .claude/settings.json
OpenAI CodexNot supportedSkipped (reported at install)
CursorNot supportedSkipped (reported at install)
VS Code (Copilot)Not supportedSkipped (reported at install)
Generic markdownAdapterdocs/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

  • engineering
  • security

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.

ProtectedExamples
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)
Credentialscredentials.json, .netrc, .git-credentials, .pgpass, .aws/credentials
Directoriesany secrets/ (or .secrets/) directory component, such as secrets/api.txt
Your own globseverything 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.

Build with this hook

Create Demo Project

Install in CLI

$ devbuild add hook protect-secrets

Free. Needs a free account: run devbuild login once.

IDprotect-secrets
Version1.0.0
TierFree
EventPreToolUse
DevBuildKit

Your entire AI development team. One install.

DevBuildKit never uploads your source code. Telemetry is opt-in and anonymous.

Product

  • Agents
  • Skills
  • Commands
  • Packs
  • Features
  • Live demo
  • Pricing

Learn

  • Documentation
  • Getting started
  • CLI reference
  • Blog
  • Changelog
  • Compare

Free tools

  • All tools
  • Agent generator
  • Config converter
  • Stack detector
  • Context analyzer

Use cases

  • Android development
  • iOS development
  • SaaS development
  • Backend development
  • App Factory
  • Game development

Company

  • Terms
  • Privacy
  • Refunds
  • Log in
  • Sign up

© 2026 DevBuildKit. All rights reserved.

DevBuildKit is an independent product. Claude, Claude Code, Anthropic, OpenAI, Codex, ChatGPT, Cursor, Visual Studio Code, GitHub Copilot, Microsoft and all other product names are trademarks of their respective owners. DevBuildKit is not affiliated with, endorsed by or sponsored by any of them; names are used only to describe compatibility.