Git branches prune
Process one batch per turn. Dispatch a fast subagent to build the list. Require user approval before you delete any branch. Report holds the active branch list at the top and skipped branches below.
The only git the parent runs is delete-and-prune after the gate.
1. Roster
Report path:
tmp/git-branches-prune-report.md
, or
{temp-docs-dir}/git-branches-prune-report.md
when AGENTS.md names a temp-docs directory.
Read the report if it exists. Load its roster and keep names.
Read
,
,
,
, and a parent-repo
if present. Build file-derived patterns:
- Protected — long-lived / env / release trains named there
- Temporary — feature, hotfix, merge, buffer, revert, or ticket branches
Cite a source for each pattern. Merge oracles default to
and
; use the pair AGENTS.md names if it differs.
Host (GitHub / remote extras: open PRs): use the git/GitHub tool those files name. If none, probe
, then GitHub MCP. If neither works: host is
local git. Tell the user once: only local git access; open-PR checks skipped. GitHub access is
, MCP, or local git.
Merge with the report: refresh file-derived rows from this scan; user rows stay. User wins on conflict. Ambiguous names are protected.
Write the working roster at the top of the report (keeps table unchanged). Show it. Done when the header is that roster (including host), every long-lived branch named in those files is on the protected list, temporary patterns cover feature/hotfix/merge/buffer/ticket, and keep names are in hand.
When the user states a pattern rule, add it to the roster as source
and write the header before the next dispatch.
markdown
# Git branches prune
## Roster
Oracles: `origin/main`, `origin/staging`
Host: gh | github MCP | local git
### Protected
|---|---|
| `envs/*` | AGENTS.md |
| `release/*` | user 2026-08-13 |
### Temporary
|---|---|
| `JIRA-` | AGENTS.md |
| `feature/` `hotfix/` `merge` `buffer` `revert-` | user 2026-08-13 |
## Keeps
| Branch | Author | Latest Commit Date | Reason | Analysis Date |
|---|---|---|---|---|
2. Dispatch
Launch one cheap subagent that can run git (this env's shell / bash / general runner). Pick a cheap fast family this env actually offers — no version pins, inherit only if none exist:
Haiku, Composer, Gemini Flash, GPT mini, DeepSeek, Qwen Coder, Llama 8B, Codestral, Yi-Coder
Point it at chunk.md. Give it:
- the roster (protected + temporary + oracles + host)
- exclude: every branch already in Keeps
- year: oldest unfinished, or the year in progress
Done when the return has a year, a candidate table of ≤20 rows, and a skipped list. Every candidate row has main, staging, and propose. Keep names do not appear.
If the return is incomplete, dispatch again naming the gap. Parent does not inventory, classify, or merge-check.
3. Gate
Show proposed delete, keep, and skipped. Stop. Done when the user names the branches to delete, or approves the proposed-delete set. Pattern rules stated here go to the roster (step 1).
4. Record
Append a row for every skipped branch from this batch: user keep, not merged, open PR, current checkout, or other can't-delete. Reason on the row. Keeps is keep-only.
Done when every keep/can't-delete from this batch has a row and no pruned name was added.
5. Delete
Only user-approved names. Strip
once (
→
). Current checkout stays. Local
unless the roster host names a different delete tool.
bash
git push origin --delete <name> [<name> ...]
git branch -d <name> # only if a local branch exists; never -D
git fetch origin --prune
Done when
has none of the deleted names.
6. Next batch
Re-read the report. Same year if temporary candidates remain; otherwise the next year. Dispatch again. Stop when years are exhausted or the user ends the pass.
Rationalizations
| Excuse | Reality |
|---|
| "I know the env branches" | Roster from files + report header this run. |
| "User said the pattern, I'll remember" | User rows go in the roster header. |
| "I'll open GitHub in a browser" | Host is gh, MCP, or local git. Tell the user. |
| "Pin composer-2.5-fast" | Cheap family this env offers. No version pins. |
| "Faster to run the git myself" | Dispatch. Parent presents, gates, records, deletes. |
| "Skip the report" | Write roster and keeps before the next dispatch. |
| "Merged everywhere, just delete" | Gate first. The list is a proposal. |
| " because refused" | Stop. Tell the user. User must say force. |