Claude Code HookSecurity19 installs

Env File Protection

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 with the Claude Code Templates CLI
$ npx claude-code-templates@latest --hook="security/env-file-protection" --yes

Requires Claude Code. The command adds this hook to your project's .claudedirectory — nothing runs on ToolZip's servers.

What's inside this hook

Component 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\"}}'"

}

]

}

]

}

}

Type
Hook
Category
Security
Installs
19
Source
GitHub ↗

Related Claude Code Hooks

HookSecurity

File Protection

Protect critical files from accidental modification. Prevents editing of important system files, configuration files, and production code.

237 installsView →
HookSecurity

Security Scanner

Scan code for security vulnerabilities and secrets after modifications. Uses multiple security tools to detect potential issues.

220 installsView →
HookSecurity

Secret Scanner

Automatically detects hardcoded secrets before git commits. Scans for API keys from 30+ providers (Anthropic: sk-ant-..., OpenAI: sk-..., AWS: AKIA..., Stripe: sk_live_..., Google: AIza..., GitHub: ghp_..., Vercel, Supabase, Hugging Face: hf_..., Replicate: r8_..., Groq: gsk_..., Databricks: dapi..., GitLab, DigitalOcean, npm, PyPI, and more), tokens, passwords, private keys, and database credentials. Blocks commits containing secrets and suggests using environment variables instead.

137 installsView →
HookSecurity

Dangerous Command Blocker

Advanced protection against dangerous shell commands with multi-level security. Blocks catastrophic operations (rm -rf /, dd, mkfs), protects critical paths (.claude/, .git/, node_modules/), and warns about suspicious patterns. Features: catastrophic command blocking, critical path protection, smart pattern detection, and detailed safety messages.

120 installsView →
HookSecurity

Force Push Blocker

Block git force push commands using the if condition for efficient filtering. Prevents accidental force pushes that can overwrite remote history. Covers --force, --force-with-lease, and the -f shorthand.

14 installsView →
HookSecurity

Shell Wrapper Guard

Detects destructive commands hidden inside shell wrappers (sh -c, bash -c, python3 -c, node -e, perl -e, ruby -e). Complements dangerous-command-blocker by catching bypass vectors like 'sh -c "rm -rf /"' that evade direct command checks. Covers 8 bypass patterns: interpreter one-liners, nested wrappers, pipe-to-shell, here-strings, and env-based wrappers.

12 installsView →

Catalog data and component content are sourced from the open-source davila7/claude-code-templates project (MIT license). ToolZip curates the listing and writes original descriptions; every component links back to its original source. Claude Code is a product of Anthropic. ToolZip is an independent catalog and is not affiliated with or endorsed by Anthropic.