branch-guard
Skill7 starsChanged 4 months agoMITView on GitHub
Enforce "never write on main/master/trunk". Backing PreToolUse hook blocks Write/Edit/MultiEdit/NotebookEdit when HEAD is on a protected branch, aborting with exit 2. This skill documents the rule and provides the "branch off and continue" recipe Claude should reach for whenever the guard fires or whenever a task begins on a protected branch. Auto-trigger when the guard blocks a write, when the user asks "am I on main?" / "create a new branch", or at the start of any task that will write to a git repo.
- Commits and pushes
2 other projects use a version of this.
Adopted by
Most recently taken up by
- gerivdb/SKILLStheir own version, first seen Aug 7, 2026
- fotowizzard/taskctl-osstheir own version, first seen Jun 12, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- fotowizzard/taskctl-oss★ 1same name
- gerivdb/SKILLS★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository14 other files it gives its agents.
- ai-tell-cleanupSkill
- frontend-perf-impact-scanSkill
- jvm-memory-leak-reviewSkill
- kotlin-coroutine-reviewSkill
- nestjs-provider-reviewSkill
- nextjs-app-router-reviewSkill
- parallel-devSkill
- parallel-dispatchSkill
- parallel-prSkill
- pr-impact-scanSkill
- react-hooks-reviewSkill
- review-loopSkill
- reviewSkill
- spring-kafka-listener-reviewSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
If the current branch is main / master / trunk (or configured as protected), exits 2 with a message.
- Distinctive: line 17
If not in a git repo, exits 0 (no-op).
- Very specific: line 49
Use git commit --amend on main to "fix" the guard.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
branch-guard — never write on protected branches
Direct writes to main / master / trunk are the most common cause of "oh no I pushed straight to main". A hook (installed by this project's install.sh) enforces the rule at tool-call time; this skill teaches the recovery flow.
What the hook does
PreToolUse hook ~/.claude/hooks/branch-guard.sh:
- Runs before
Write/Edit/MultiEdit/NotebookEdit. - Runs
git rev-parse --abbrev-ref HEADin the tool's target directory. - If the current branch is
main/master/trunk(or configured as protected), exits 2 with a message. - If not in a git repo, exits 0 (no-op).
Bypass:
WW_ALLOW_MAIN_WRITE=1env var (temporary, for CI / setup scripts).- Writing to non-repo paths (
~/.claude/,/tmp/, etc.).
When this skill triggers
- The hook blocked a write. The tool result will include
exit code 2and a message like "branch-guard: refuse write on protected branch 'main'". - The user asks "am I on main?" / "let's branch" / "create a new branch".
- You're about to start a task that will write to a git repo and haven't verified the branch.
Recovery recipe
# 1. Confirm current state
git status
git rev-parse --abbrev-ref HEAD
# 2. Branch off. Name the branch by scope:
# feat/<short-scope> — a feature
# fix/<issue-or-symptom> — a bug fix
# chore/<what> — non-code (docs, deps, config)
git checkout -b feat/<scope>
# 3. Re-attempt the write. The hook now allows it.Do NOT
- Set
WW_ALLOW_MAIN_WRITE=1in your shell rc permanently. That defeats the guard for interactive sessions. - Force-push after branching. The commit stays on the feature branch;
mainis untouched. - Use
git commit --amendonmainto "fix" the guard. If you got here, your prior commit is still onmain— reset it:git reset --soft HEAD~1(moves the change back to staged), branch off, commit again on the branch,git pushon the branch, PR normally.
Configuration
The hook reads WW_PROTECTED_BRANCHES env var (comma-separated, default main,master,trunk). Set it in your shell rc if your repo uses a different name.
# Example: also protect a release branch
export WW_PROTECTED_BRANCHES="main,master,trunk,release"Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

