agentleFS
axiomanticaxiomantic/spellbook/skills/branch-context/SKILL.md

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
  1. Distinctive:

    Merge Base Is the Reference Point: - All branch diffs, PR descriptions, and changelogs describe changes relative to the merge base, never …

    line 29
  2. Very specific:

    Use $SPELLBOOK_DIR/scripts/branch-context.sh to detect branch context automatically:

    line 36
  3. Very specific:

    Run branch-context.sh --help for the authoritative list.

    line 74
  4. Distinctive:

    When reviewing stacked branches:

    line 87
  5. Very specific:

    Run branch-context.sh to confirm the detected merge target.

    line 89
  6. Very specific:

    Verify the merge target is the parent branch (e.g., branch-A), not main or master.

    line 90
  7. Distinctive:

    Before running any branch-context command in a worktree, verify you are in the correct directory:

    line 101
  8. Distinctive:

    Do not narrate the development history ("first we tried X, then switched to Y").

    line 123
  9. Distinctive:

    Do not reference work from parent branches in stacked PRs.

    line 124

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<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

  1. Directory Determines Truth - Branch-context commands must run from the correct working directory; running from the wrong repo produces silently wrong results.
  2. Merge Base Is the Reference Point - All branch diffs, PR descriptions, and changelogs describe changes relative to the merge base, never absolute state.
  3. 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:
TaskEndpoint pair
Reviewing what will mergefiles-committed + diff-committed
Describing the branch (PR body, changelog)files + diff
Pre-commit self-reviewfiles + 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:

  1. Run branch-context.sh to confirm the detected merge target.
  2. Verify the merge target is the parent branch (e.g., branch-A), not main or master.
  3. 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-current

Running 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.

Download now (ZIP)

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.