Prepare Branch Context
Create a read-only handoff pack so the next agent can act without re-running basic discovery. Optimize for speed: gather shape first, read only the highest-signal patches, and state unknowns instead of exhaustively proving every edge.
Execution mode: run in a subagent. Default: thrifty unless the user explicitly asks for another agent.
Inputs
- Preferred:
prepare-branch-context from <base-branch>
- Also supports: omitted base branch,
commits <rev-range>, or files <path1,path2,...>
- If no base is given: detect GitHub default branch; if that fails, fall back to
staging and say so.
Fast workflow
Resolve scope
- Determine current branch and
BASE_BRANCH.
git fetch origin "$BASE_BRANCH"; use origin/$BASE_BRANCH when available, otherwise local $BASE_BRANCH with a note.
- Respect explicit commit/file subset scopes.
- If there is no diff from the compare ref, emit a minimal summary and stop.
Collect cheap facts
- Run: branch, status, merge-base, PR lookup, diff stat, name-status, commit log.
- If a PR exists, read title/body for intent, acceptance criteria, constraints, and known risks.
- Keep committed, staged, and unstaged deltas separate.
Read patches selectively
- Always read full patches for high-risk files.
- For small diffs, reading the full patch is fine.
- For medium/large diffs, skip low-signal tails: lockfiles, generated files, snapshots, vendored code, bulk formatting. List them as skipped.
- For huge diffs, cap inline patch reads around the top 8-10 files. Do not delegate unless the missing context blocks a useful summary.
Rank hotspots
- Risk signals: critical path, API/schema/contract boundary, shared library, large/complex control-flow change, concurrency/state, data migration, auth/access, payments, encryption, test gap.
- Output every changed file as
[high|medium|low] <path> - <reason>.
- Treat behavior-changing source without related tests as a real hotspot signal.
Map only necessary boundaries
- For
[high] hotspots only, capture one-hop context when cheap: changed signatures/exports, obvious callers, and important internal imports/dependencies.
- Do not build a full dependency graph.
- If context is expensive, record the unknown and the exact next lookup.
Output
Start with the standard handoff fields:
answer: <1-3 sentence branch intent/readiness summary>
evidence:
- <command/output/path/PR section> - <what it proves>
confidence: <0.00-1.00>
next_step: <single best continuation>
Then emit this block:
BRANCH_CONTEXT_SUMMARY
SCOPE:
current_branch: ...
base_branch: ...
compare_ref: ...
mode: pr | branch | commits | files
pr: #<number> | none
INTENT:
objective: ...
acceptance_criteria:
- ...
open_questions:
- ...
CHANGESET:
commits: <count>
- <sha> <message>
files_changed: <count>
- <path> (<A|M|D>, +X/-Y)
skipped_low_signal:
- <path> - <why>
HOTSPOTS:
- [high] <path> - <why>
- [medium] <path> - <why>
- [low] <path> - <why>
BOUNDARIES:
- <high-hotspot-path>::<changed signature/export>
callers:
- <path>:<line> | not checked - <why>
deps:
- <import/path>
WORKTREE:
clean: yes | no
staged:
- <path>
unstaged:
- <path>
RISK_SUMMARY: <1-2 sentences>
OPEN_UNKNOWNS:
- <path> - <unknown + exact next lookup>
READY: yes
NEXT_ACTIONS:
- ...
Hard rules
- Read-only: never edit files.
- Never silently assume the base branch.
- Prefer
origin/<base> after fetch; explicitly note fallback.
- Read PR title/body before deep diff reading when a PR exists.
- Always include risk-ranked hotspots and test-gap signals.
- Always read actual patches for
[high] hotspots.
- Stay fast: one pass plus at most one targeted follow-up for a high hotspot. Report remaining unknowns instead of looping.
- Always emit
answer, evidence, confidence, next_step, then BRANCH_CONTEXT_SUMMARY.
1---2name: prepare-branch-context3description: Build a fast, actionable branch/PR/commit context pack with scope, intent, changed files, hotspots, risks, and next actions. Use before handing work to another agent, reviewing a branch, resuming unfamiliar work, or preparing a PR/code-review prompt.4---56# Prepare Branch Context78Create a read-only handoff pack so the next agent can act without re-running basic discovery. Optimize for speed: gather shape first, read only the highest-signal patches, and state unknowns instead of exhaustively proving every edge.910**Execution mode:** run in a subagent. Default: `thrifty` unless the user explicitly asks for another agent.1112## Inputs1314- Preferred: `prepare-branch-context from <base-branch>`15- Also supports: omitted base branch, `commits <rev-range>`, or `files <path1,path2,...>`16- If no base is given: detect GitHub default branch; if that fails, fall back to `staging` and say so.1718## Fast workflow19201. **Resolve scope**21 - Determine current branch and `BASE_BRANCH`.22 - `git fetch origin "$BASE_BRANCH"`; use `origin/$BASE_BRANCH` when available, otherwise local `$BASE_BRANCH` with a note.23 - Respect explicit commit/file subset scopes.24 - If there is no diff from the compare ref, emit a minimal summary and stop.25262. **Collect cheap facts**27 - Run: branch, status, merge-base, PR lookup, diff stat, name-status, commit log.28 - If a PR exists, read title/body for intent, acceptance criteria, constraints, and known risks.29 - Keep committed, staged, and unstaged deltas separate.30313. **Read patches selectively**32 - Always read full patches for high-risk files.33 - For small diffs, reading the full patch is fine.34 - For medium/large diffs, skip low-signal tails: lockfiles, generated files, snapshots, vendored code, bulk formatting. List them as skipped.35 - For huge diffs, cap inline patch reads around the top 8-10 files. Do not delegate unless the missing context blocks a useful summary.36374. **Rank hotspots**38 - Risk signals: critical path, API/schema/contract boundary, shared library, large/complex control-flow change, concurrency/state, data migration, auth/access, payments, encryption, test gap.39 - Output every changed file as `[high|medium|low] <path> - <reason>`.40 - Treat behavior-changing source without related tests as a real hotspot signal.41425. **Map only necessary boundaries**43 - For `[high]` hotspots only, capture one-hop context when cheap: changed signatures/exports, obvious callers, and important internal imports/dependencies.44 - Do not build a full dependency graph.45 - If context is expensive, record the unknown and the exact next lookup.4647## Output4849Start with the standard handoff fields:5051```text52answer: <1-3 sentence branch intent/readiness summary>53evidence:54 - <command/output/path/PR section> - <what it proves>55confidence: <0.00-1.00>56next_step: <single best continuation>57```5859Then emit this block:6061```text62BRANCH_CONTEXT_SUMMARY6364SCOPE:65 current_branch: ...66 base_branch: ...67 compare_ref: ...68 mode: pr | branch | commits | files69 pr: #<number> | none7071INTENT:72 objective: ...73 acceptance_criteria:74 - ...75 open_questions:76 - ...7778CHANGESET:79 commits: <count>80 - <sha> <message>81 files_changed: <count>82 - <path> (<A|M|D>, +X/-Y)83 skipped_low_signal:84 - <path> - <why>8586HOTSPOTS:87 - [high] <path> - <why>88 - [medium] <path> - <why>89 - [low] <path> - <why>9091BOUNDARIES:92 - <high-hotspot-path>::<changed signature/export>93 callers:94 - <path>:<line> | not checked - <why>95 deps:96 - <import/path>9798WORKTREE:99 clean: yes | no100 staged:101 - <path>102 unstaged:103 - <path>104105RISK_SUMMARY: <1-2 sentences>106OPEN_UNKNOWNS:107 - <path> - <unknown + exact next lookup>108READY: yes109NEXT_ACTIONS:110 - ...111```112113## Hard rules114115- Read-only: never edit files.116- Never silently assume the base branch.117- Prefer `origin/<base>` after fetch; explicitly note fallback.118- Read PR title/body before deep diff reading when a PR exists.119- Always include risk-ranked hotspots and test-gap signals.120- Always read actual patches for `[high]` hotspots.121- Stay fast: one pass plus at most one targeted follow-up for a high hotspot. Report remaining unknowns instead of looping.122- Always emit `answer`, `evidence`, `confidence`, `next_step`, then `BRANCH_CONTEXT_SUMMARY`.