Skip to main content
skill CX Codex

finishing-a-development-branch · ganyuanran — Claude Code skill: how to install

Safely completes task branches and worktrees: verifies test results, demands explicit approval for mutations, and cleans up task resources in Git.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add GanyuanRan/Aegis --skill finishing-a-development-branch -a claude-code
Open on GitHub

What finishing-a-development-branch does

This skill governs how AI agents wrap up development branches and temporary worktrees. First, it inspects TaskStartSnapshot and checks git worktree list --porcelain. If verification tests fail or unexplained untracked files exist, execution halts immediately. The skill never triggers auto-stash, forced pushes, or rebases without instruction.

Once tests pass, the agent presents allowed integration paths: merge locally into the recorded base, push to create a PR, keep the branch, or discard it. Remote updates and discards require typed confirmation specifying the branch name and worktree path. Without it, deletion stops.

Cleanup follows a strict sequence to prevent workspace corruption. The skill switches to a safe checkout, unregisters the worktree with git worktree remove <exact-path>, verifies the directory is gone, and only then deletes the branch ref. Finally, it outputs a Git receipt showing Task clean and Repository clean statuses.

What it helps with

  • integrate a finished feature branch locally without silent pulls
  • clean up task-created Git worktrees in safe dependency order
  • prevent accidental branch deletion before merge or PR confirmation
  • verify test evidence before marking a development branch complete

Example prompts for the agent

  • Verify tests and merge this task branch into our base branch
  • Push the finished feature branch, open a PR, and clean up the worktree
  • Discard the current task branch and remove its temporary worktree

How to install finishing-a-development-branch

1Skills CLI (Vercel)

npx skills add GanyuanRan/Aegis --skill finishing-a-development-branch -a claude-code

2Manually: put the files in place

~/.claude/skills/finishing-a-development-branch/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/finishing-a-development-branch/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about finishing-a-development-branch

How to install finishing-a-development-branch in Claude Code?

Run npx skills add GanyuanRan/Aegis --skill finishing-a-development-branch -a claude-code. The skill file will be saved at ~/.claude/skills/finishing-a-development-branch/SKILL.md.

What does finishing-a-development-branch do?

It enforces a safe workflow for finalizing task branches and worktrees. The skill prevents silent code loss by requiring passing tests and typed confirmations before merging, pushing, or deleting.

Does the skill automatically delete the branch after creating a PR?

No. Submitting a pull request does not confirm that code is merged. The skill removes clean temporary worktrees by default, but it keeps the branch until you confirm deletion or the commits land in the base.

Source text

SKILL.md · MIT
---
name: finishing-a-development-branch
description: "Use when verified work needs integration or cleanup of an existing task-created branch/worktree, or the user explicitly requests merge, PR, or branch lifecycle handling."
---

# Finishing a Development Branch

## Overview

Integration choice and checkout lifetime are separate. Verify first, mutate only
task-owned resources, then prove what was removed or retained.

**Core principle:** fresh evidence -> authorized integration -> ownership-aware
cleanup -> Git/path readback.

**Announce at start:** explain which branch/worktree lifecycle is being closed.

## Step 1: Environment and Ownership Detection

Read the task's `TaskStartSnapshot` and current repository state. Record:

- root, `HEAD`, branch/detached state, upstream divergence, and active Git ops;
- staged/unstaged/untracked paths and the task-owned delta;
- `git worktree list --porcelain`;
- branch/worktree creator, task ownership, base branch, and cleanup trigger.

Stop on conflicts, unexplained detached state, failed verification, dirty/untracked state in
a cleanup target, or unknown ownership. Do not infer the base from the names
`main` or `master`; use task records, repository authority, or explicit user
direction. Never auto-stash, reset, clean, pull, rebase, amend, force-push, or
bypass hooks.

For a trusted host-managed detached checkout, follow the repository's approved
managed-workspace contract: verify host binding, default cwd, root, and HEAD;
then use its scoped local-commit and native handoff path. Report detached HEAD
in the receipt. This exception does not authorize automatic deletion of the
detached checkout or bypass unknown ownership/binding.

If no task-created branch/worktree exists and integration was not requested,
skip this workflow: report the local task commit plus `Task clean` and
`Repository clean`; do not invent merge/PR ceremony.

## Step 2: Fresh Verification

Run the smallest current-authority test set that proves the completed task. If
it fails, preserve all work and return to diagnosis. Do not present the branch
as ready.

## Step 3: Choose the Authorized Outcome

When a task branch actually needs disposition, present only applicable choices:

1. merge into the recorded base locally;
2. push and create/update a PR;
3. keep the branch for later integration;
4. discard the exact task-owned branch/worktree.

Push, PR, remote deletion, release, and force operations require explicit user
authorization. Discard requires a fresh, exact typed confirmation naming branch,
worktree path, and commits/delta to lose. Generic agreement is insufficient.

## Step 4: Execute Without Hidden Mutation

### Local merge

Verify the target checkout is safe, switch to the recorded base, merge without an implicit pull,
and rerun verification on the merged result. If integration
or verification fails, preserve both histories and stop.

### Push or PR

Push only the authorized task branch and create/update the PR with summary and
fresh test evidence. PR creation does not itself prove merge and does not
require the temporary worktree to remain.

### Keep branch

Retain the branch. Remove a clean task-created temporary worktree by default;
retain it only for an explicit ongoing-checkout need and report why.

### Discard

After exact confirmation, remove only the named clean task-owned worktree, then
the named branch. If either differs from the confirmation, stop and ask again.

## Step 5: Prove Integration Before Branch Deletion

Use evidence matching the merge strategy:

- merge/fast-forward: prove the task tip is an ancestor of the recorded base;
- squash/rebase: use fresh PR merge metadata plus strategy-appropriate patch
  equivalence (`git cherry` for rebased commits; stable patch-id or bounded
  changed-path/tree comparison for squashes), not an ancestor-only test;
- unmerged/open PR: keep the branch unless discard was exactly confirmed.

Never delete a branch merely because a PR was opened or a similarly named
commit exists.

## Step 6: Cleanup in Dependency Order

For a clean task-owned resource:

1. move to another safe registered checkout; never remove the current working directory;
2. remove/unregister the worktree first with `git worktree remove <exact-path>`;
3. read back `git worktree list --porcelain`;
4. verify the exact path no longer exists;
5. only then delete an integrated or exactly confirmed branch;
6. read back branch refs, `HEAD`, and repository status.

Do not use routine `--force`, global `git worktree prune`, wildcard deletion, or
cleanup of resources absent from the task ownership record. On Windows, Git may
unregister a worktree while its directory remains locked: re-check registration
and the exact resolved path, remove only a proven task-owned clean residual when
safe, otherwise retain it and report the lock/path. Never widen deletion scope.

## Final Git Receipt

Report:

- current branch and commit SHA/message, or the reason no commit exists;
- `Task clean: yes|no` and `Repository clean: yes|no` independently;
- branch/worktree created, removed, or retained, with evidence/reason;
- integration evidence and any remaining user action.

`Task clean` means no uncommitted task-owned delta remains. `Repository clean`
means no staged, unstaged, or untracked repository state remains.

This is a local Git receipt, not authoritative completion or merge truth beyond
the evidence read back.

## Integration

Called only when branch/worktree integration or explicit lifecycle handling is
in scope. Pairs with `using-git-worktrees` and
`verification-before-completion`.

© GanyuanRan · MIT · GanyuanRan/Aegis

Similar skills

All skills for Git and GitHub →

finishing-a-development-branch by other authors comes first.

From the same set21

recording-architecture-decisions This skill decides when an architecture decision belongs in an ADR and checks whether the current-state baseline still matches the change. CX Codex +1 ★ 1,388repo stars long-task-continuation Maintains checkpoints, evidence records, and drift tracking across context resets or multi-agent workflows. Keeps state intact during multi-step coding tasks. CX Codex +1 ★ 1,388repo stars goal-framing This skill defines a task goal, evidence of success, and boundaries before work begins. Use it when the agent needs a clear stop condition and a route for the task. CX Codex +1 ★ 1,388repo stars first-principles-review A short first-principles and Occam's-razor pass before your agent locks in a direction. Ordinary bug fixes skip it. CX Codex +1 ★ 1,388repo stars executing-plans This skill guides an agent through a written implementation plan, tracking checkpoints and progress so work can continue across sessions. CX Codex +1 ★ 1,388repo stars establishing-project-context Keeps domain terms in CONTEXT.md so people and agents call the same things by the same names. Useful when a term gets renamed, deprecated or overloaded. CX Codex +1 ★ 1,388repo stars dispatching-parallel-agents Provides clear gating rules to run concurrent subagents on ad-hoc, decoupled tasks. Prevents file collisions and coordination waste when working without a written plan. CX Codex +1 ★ 1,388repo stars communicating-concisely This skill makes agent replies more compact when asked, while preserving technical details. The style stays active until the user turns it off. CX Codex +1 ★ 1,388repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor