Back to Hooks

Env File Protection

Hooks security 243

Prevent writing to .env files using the if condition for lightweight filtering. Blocks any Write tool call targeting .env* files, protecting secrets from accidental overwrites. Uses the if field to avoid spawning a process unless the file pattern matches.

Install Command
npx claude-code-templates@latest --hook security/env-file-protection
View on GitHub
claude-code — env-file-protection

Content

JSON
{
"description": "Prevent writing to .env files using the if condition for lightweight filtering. ..."
"hooks": {
"PreToolUse": [1 item]
}
}

Stack Builder

0 components

Your stack is empty

Browse components and click the + button to add them to your stack for easy installation.