Branch Protection Guard
Branch Protection Guard intercepts all file write, edit, and git commit operations to verify the current git branch is not in a configurable list of protected branches. If Claude attempts to modify files while on main, master, production, or any branch you specify, the hook blocks the action and suggests creating a feature branch first. This prevents accidental direct commits to critical branches and enforces your team's branching strategy.
Hook Code
Add this hook to your Claude Code settings or .claude/settings.json to activate.
Terminal Preview
About Branch Protection Guard
Claude Code hooks let you run custom shell commands automatically in response to specific events during Claude's operation. Branch Protection Guard is a Pre-Tool hook at the Beginner level that automates tasks at key moments in your development workflow, reducing manual steps and enforcing consistency across your team.