branch-context
Skill11 starsChanged 3 months agoMITView on GitHub
Branch diff mechanics: merge-base detection, branch-context.sh, stacked branches, worktree context. Loaded by the diff-semantics rule module. Triggers: 'what changed on this branch', 'branch diff', 'merge base', 'PR description', 'changelog'.
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 5 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 29
Merge Base Is the Reference Point: - All branch diffs, PR descriptions, and changelogs describe changes relative to the merge base, never …
- Very specific: line 36
Use $SPELLBOOK_DIR/scripts/branch-context.sh to detect branch context automatically:
- Very specific: line 74
Run branch-context.sh --help for the authoritative list.
- Distinctive: line 87
When reviewing stacked branches:
- Very specific: line 89
Run branch-context.sh to confirm the detected merge target.
- Very specific: line 90
Verify the merge target is the parent branch (e.g., branch-A), not main or master.
- Distinctive: line 101
Before running any branch-context command in a worktree, verify you are in the correct directory:
- Distinctive: line 123
Do not narrate the development history ("first we tried X, then switched to Y").
- Distinctive: line 124
Do not reference work from parent branches in stacked PRs.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 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
<analysis>
Reference for inspecting branch diffs, detecting stacked branches, and writing branch-relative documentation using branch-context.sh.
</analysis><reflection>
Did I run branch-context.sh from the correct directory (worktree path, not main repo) and verify the merge target is correct?
</reflection>Branch Context
Type: Reference + Technique
Practical guide for inspecting branch context, handling stacked branches, and producing branch-relative documentation. Core definitions (merge target, merge base, branch diff) live in rules/55-diff-semantics.md; this skill covers usage details.
Invariant Principles
- Directory Determines Truth - Branch-context commands must run from the correct working directory; running from the wrong repo produces silently wrong results.
- Merge Base Is the Reference Point - All branch diffs, PR descriptions, and changelogs describe changes relative to the merge base, never absolute state.
- Stacked Branches Show Only Their Layer - In a stack, each branch's diff includes only what it added on top of its parent branch.
Script Usage
Use $SPELLBOOK_DIR/scripts/branch-context.sh to detect branch context
automatically:
branch-context.sh # summary: target, base, stats, uncommitted state
branch-context.sh diff # full diff (merge base to working tree)
branch-context.sh diff-committed # committed only (merge base to HEAD)
branch-context.sh diff-uncommitted # uncommitted only (staged + unstaged vs HEAD)
branch-context.sh log # commit log since merge base
branch-context.sh stat # diffstat (merge base to working tree)
branch-context.sh stat-committed # diffstat, committed only (merge base to HEAD)
branch-context.sh files # changed file list (merge base to working tree)
branch-context.sh files-committed # changed file list, committed only
branch-context.sh base # the merge base SHA
branch-context.sh target # the detected merge target
branch-context.sh resolution # base provenance on stdout
branch-context.sh json # machine-readable JSON<CRITICAL>
**ENDPOINT is a separate decision from BASE.** The `-committed` variants stop at
HEAD; the plain ones include the working tree. Pick by TASK:| Task | Endpoint pair |
| Reviewing what will merge | files-committed + diff-committed |
| Describing the branch (PR body, changelog) | files + diff |
| Pre-commit self-review | files + diff |
The file list and the diff MUST share one endpoint. Pairing files with
diff-committed builds a coverage manifest of files the diff does not contain,
which lets a review certify N-of-N against zero hunks.
json reports BOTH counts: files_changed (working tree) and
files_changed_committed. Automation deciding "is there anything to review"
must read files_changed_committed.
</CRITICAL>
Run branch-context.sh --help for the authoritative list; this table and the
script's own usage output are ONE contract.
$SPELLBOOK_DIR is substituted at load time from spellbook configuration.
Stacked Branches
This matters for stacked branches: if master -> branch-A -> branch-B, the
work on branch-B is only what branch-B added on top of branch-A. The script
auto-detects stacking via PR base refs.
When reviewing stacked branches:
- Run
branch-context.shto confirm the detected merge target. - Verify the merge target is the parent branch (e.g.,
branch-A), notmainormaster. - The diff will show only branch-B's additions, not the full stack.
Worktree Notes
In worktrees, run this script FROM the worktree directory. It detects worktree context automatically.
Before running any branch-context command in a worktree, verify you are in the correct directory:
cd <worktree-path> && pwd && git branch --show-currentRunning branch-context.sh from the main repo while intending to inspect a
worktree branch will produce silently wrong results (empty diffs, wrong merge
base).
Branch-Relative Documentation
Changelogs, PR titles, PR descriptions, commit messages, and code comments
describe the merge-base delta only. No historical narratives in code comments.
Full policy in finishing-a-development-branch skill.
Rules:
- Describe what the branch introduces relative to its merge base.
- Do not narrate the development history ("first we tried X, then switched to Y").
- Do not reference work from parent branches in stacked PRs.
- PR descriptions should summarize the diff, not the journey.
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- pydantic/pydantic-ai★ 21ksame name
- pydantic/pydantic-ai-harness★ 954same 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 repository65 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- documentation-updatesSkill
- spellbook-auditingSkill
- advanced-code-reviewSkill
- adversarial-reviewSkill
- agent2agentSkill
- analyzing-domainsSkill
- analyzing-skill-usageSkill
- assembling-contextSkill
- async-await-patternsSkill
- auditing-green-mirageSkill
- autonomous-modeSkill
- code-reviewSkill
- creating-issues-and-pull-requestsSkill
- debuggingSkill
- dedupeSkill
- deep-researchSkill
- dehallucinationSkill
- design-explorationSkill
- designing-workflowsSkill
- developSkill
- devils-advocateSkill
- dispatching-parallel-agentsSkill
- distilling-prsSkill
- documenting-projectsSkill
- documenting-toolsSkill
- emotional-stakesSkill
- enforcing-code-qualitySkill
- estimating-ticketsSkill
- executing-plansSkill
- fact-checkingSkill
- finding-dead-codeSkill
- finishing-a-development-branchSkill
- fixing-testsSkill
- fractal-thinkingSkill
- gathering-requirementsSkill
- generating-diagramsSkill
- instruction-engineeringSkill
- isolated-testingSkill
- managing-artifactsSkill
- merging-worktreesSkill
- opportunity-awarenessSkill
- optimizing-instructionsSkill
- polish-repoSkill
- reflexionSkill
- requesting-code-reviewSkill
- resolving-merge-conflictsSkill
- reviewing-design-docsSkill
- reviewing-impl-plansSkill
- reviewing-prsSkill
- rounding-up-worktree-sessionsSkill
- sharpening-promptsSkill
- smart-readingSkill
- test-driven-developmentSkill
- testing-strategySkill
- tooling-discoverySkill
- using-git-worktreesSkill
- using-lsp-toolsSkill
- using-skillsSkill
- The first 60 shown.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
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.

