security/env-file-protection
Denies any Write to .env files, so secrets are not overwritten by accident.
- Kind
- Hook
- Works with
- Claude Code
- Source
- Claude Code Templates @ 72e5f237f64d
- Path
- cli-tool/components/hooks/security/env-file-protection.json
- License
- MIT
- Jobs
- Guardrails
InstallInstall it by hand, following the source.
{
"description": "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.",
"hooks": {
"PreToolUse": [
{
"matcher": "Write",
"hooks": [
{
"type": "command",
"if": "Write(.env*)",
"command": "echo '{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"deny\",\"permissionDecisionReason\":\"Writing to .env files is blocked by hook\"}}'"
}
]
}
]
}
}