Security for Claude Code Development: Add two hooks

Part 10 of 16

Add two hooks

A PreToolUse hook runs before every tool call. Exit code 2 blocks the action with no prompt to click through and feeds the hook’s message back to Claude.

You need two hooks. When Write is blocked from editing .env, the model often retries through Bash with echo "KEY=value" >> .env, which a file hook never sees. One hook guards Edit and Write, resolving symlinks so a disguised name is judged by its real target, and the other guards Bash.

Both match patterns, so treat them as guardrails and keep the sandbox underneath. Copy both hooks from the audit’s fix section.