Merged Worktree Cleanup

    2

    Remove a story's worktree and local branch only after the exact pull request is confirmed merged. No force, no guesses, no remote deletion.

    Free

    1 install5.0 (1 review)

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+22 more

    Merged Worktree Cleanup

    Example session with this skill installed

    PR merged, clean up the CAN-001 worktree. PR: https://github.com/<owner>/<repo>/pull/1

    • Read your context and instructions
    • Compiled the merged worktree cleanup

    Summary

    The CAN-001 worktree and local branch are cleaned up. The merge was confirmed on GitHub before anything was removed.

    Real run from our install test, translated and lightly trimmed.

    TargetResult
    PR #1Merged into main at 2026-10-15T16:47:43Z, checked with gh pr view before any removal
    Worktree .claude/worktrees/CAN-001Clean, removed without --force. git worktree list now shows only the primary worktree.
    Local branch worktree-CAN-001 (cb9cea7)Deleted with git branch -d after the script confirmed the commit is in the updated origin/main
    Remote branch origin/worktree-CAN-001Kept, because you did not ask to delete it

    Note. Git printed "not yet merged to HEAD" while deleting the branch. Nothing was lost: the warning appears only because local main is behind origin/main. Run git pull on main to bring in the CAN-001 change.

    Same request, before the merge. An earlier run of this exact prompt found state: OPEN, mergedAt: null on PR #1, changed nothing, and left the worktree and branch intact with a note to come back once GitHub shows the PR as merged.

    Next steps

    • git pull on main
    • Delete the remote branch yourself if you no longer need it

    Connects securely to your tools. The creator never sees your data.

    About this skill

    What it does

    The problem. Worktrees and story branches pile up after merges, and cleaning them by hand invites --force, branch -D, or deleting the wrong branch while a PR is still open.

    What the skill does. It confirms mergedAt on the exact PR with gh, requires the worktree to be clean, fetches the base, checks the branch tip is in it, previews the targets, then removes the worktree and deletes the local branch with safe Git commands.

    Why not just prompt for it. The bundled script verifies merge state in both preview and apply mode and refuses to continue when anything is ambiguous. If the PR is still open, nothing changes.

    Use it when a story PR has been merged and you want the worktree and branch gone.

    Known limits.

    • After a squash merge the branch tip is not in the base, so the skill stops and asks rather than deleting.
    • GitHub only, through an authenticated gh.

    Where it fits

    1. Project Setup, once per repository: plan, backlog, verifier
    2. Story Flow or Codex Dual-Session Story Flow, once per story: build, verify, independent review
    3. You: read the diff, push, open the PR, merge
    4. Merged Worktree Cleanup (this skill), after the merge: remove the worktree and branch

    Project Setup is optional but recommended: without it the story flows fall back to auto-detected checks, with no backlog or project-owned verifier.

    How to use

    1. Unzip into your Claude Code or Codex skills folder.
    2. After merging, say PR merged, clean up the worktree with the story ID or branch.

    Requirements

    git and gh authenticated against the repository.

    Works best with: Story Flow and Codex Dual-Session Story Flow, which create the worktrees this skill removes.

    How to use

    Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.

    Reviews

    5.0
    1 review
    5
    1
    4
    0
    3
    0
    2
    0
    1
    0

    1 people have installed this skill.

    Trust & safety

    Security scanned

    Verified clean 4 days ago

    • Free to download with an account

    Requires

    Git
    GitHub CLI (gh)

    Listed4 days ago

    What's inside

    Frequently Asked Questions