Agent skill
branch-context
Triggers: 'branch diff', 'what changed on this branch', 'merge base', 'stacked branches', 'branch-context.sh', 'what does this branch do', 'PR description', 'changelog', 'branch comparison', 'diff since', 'what work is on this branch'. Also relevant during PR creation and finishing-a-development-branch workflows.
Install this agent skill to your Project
npx add-skill https://github.com/axiomantic/spellbook/tree/main/skills/branch-context
SKILL.md
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 AGENTS.spellbook.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 files # changed file list
branch-context.sh json # machine-readable JSON
$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-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.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
spellbook-auditing
Meta-audit skill for spellbook development. Spawns parallel subagents to factcheck docs, optimize instructions, find token savings, and identify MCP candidates. Produces actionable report.
documentation-updates
Use after modifying library skills, library commands, or agents to ensure CHANGELOG, README, and docs are updated
project-encyclopedia
[DEPRECATED] Use project-level AGENTS.md files instead. Previously used for first-session codebase onboarding and persistent glossary creation.
reviewing-impl-plans
Use when reviewing implementation plans before execution. Triggers: 'is this plan solid', 'review the plan', 'check before I start building', 'anything missing from this plan', 'will this plan work', 'audit the implementation plan'. NOT for: reviewing design documents (use reviewing-design-docs) or creating plans (use writing-plans).
session-resume
Session resume protocol and session repairs handling. Loaded when spellbook_session_init returns resume_available: true, or when session_init returns a repairs array. Triggers: 'resume', 'continue', 'where were we', session resume, session repairs.
brainstorming
Use when exploring design approaches, generating ideas, or making architectural decisions. Triggers: 'explore options', 'what are the tradeoffs', 'how should I approach', 'let's think through', 'sketch out an approach', 'I need ideas for', 'how would you structure', 'what are my options'. Also invoked by develop when design decisions are needed.
Didn't find tool you were looking for?