validate-branch-name — Claude Code hook: Git Flow branch check
A hook that inspects Bash commands before they run and blocks any branch name that falls outside Git Flow.
npx claude-code-templates@latest --hook git/validate-branch-nameWhat validate-branch-name does
The hook listens on PreToolUse with a Bash matcher. Every time Claude Code is about to run a shell command, it fires .claude/hooks/validate-branch-name.py via python3, and that script reads the branch name. Three patterns pass: feature/*, release/v*.*.*, hotfix/*. Anything else gets stopped before the command executes.
Install with npx claude-code-templates@latest --hook git/validate-branch-name; the wiring lands in .claude/settings.json. The script ships inside your project and is invoked through python3, so the interpreter has to be on the machine or the hook never runs.
Try creating fix/login and it will be refused. That is the point — the hook keeps branch names in one shape while an agent does the typing.
What it helps with
- block branch names that break Git Flow
- catch a wrong prefix before the command runs
- keep one naming format across the repo
- stop an agent from creating a
fix/...branch
Example prompts for the agent
- Create branch
feature/user-authand switch to it - Branch off main into
release/v1.2.0 - Make a hotfix branch called
hotfix/login-crash
How to install validate-branch-name
1claude-code-templates
npx claude-code-templates@latest --hook git/validate-branch-name2Manually: put the files in place
.claude/settings.jsonThe hooks block: event (PreToolUse, PostToolUse, Stop…) → command. Personal ones go to ~/.claude/settings.json
Step by step, with commands for each platform: Claude Code hooks: what they are, where to configure them, how to block a risky command
Questions about validate-branch-name
How do I install validate-branch-name in Claude Code?
Run npx claude-code-templates@latest --hook git/validate-branch-name. The hook is registered in .claude/settings.json and the script is placed under .claude/hooks/.
Which branch names does the hook allow?
feature/*, release/v*.*.* and hotfix/*. Any other prefix is rejected.
What does the hook need to work?
python3 available in the project environment, since the hook command calls the script through it.
Source text
validate-branch-name.json · MIT
{
"description": "Validate Git Flow branch naming conventions before checkout. Ensures branches follow the pattern: feature/*, release/v*.*.*, hotfix/*. Prevents creation of branches that don't follow Git Flow standards.",
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "python3 \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/validate-branch-name.py"
}
]
}
]
}
}
© davila7 · MIT · davila7/claude-code-templates