coddy-agent / rules
Cursor rule187 starsChanged 9 days agoMITView on GitHub
After a pull request merges, remove its worktree and delete its branch, locally and on origin
- Commits and pushes
We split this merged-branch-cleanup.mdc into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 31
Run them from the main checkout (the first line of git worktree list) with git -C: the worktree being removed may be the session's own …
- Distinctive: line 34
Make sure nothing is lost:
- Very specific: line 38
every commit of the branch reached the pull request: git -C <main checkout> fetch origin pull/<PR>/head, then git -C <main checkout> …
- Very specific: line 43
Remove the worktree: git -C <main checkout> worktree remove <worktree>, then git -C <main checkout> worktree prune.
- Very specific: line 45
Delete the local branch: git -C <main checkout> branch -D <branch>.
- Very specific: line 48
Delete the branch on origin.
- Very specific: line 55
Never delete main, the orphan screenshots branch or a tag, whatever the cleanup lists.
≈ “Common” is an estimate: at least 1 in 5 of the 6,350 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: After a pull request merges, remove its worktree and delete its branch, locally and on origin
alwaysApply: true
---
# Cleanup after a merge
A branch whose pull request has merged is finished, and its worktree and the branch itself are
removed in the same session, as the last step of the merge rather than later. A worktree left
behind keeps a checkout, a `node_modules` and a build cache on the disk; a branch left behind is
where the next agent commits a follow-up that no pull request will ever pick up.
## When it applies
As soon as you know that the pull request of a branch you worked on has merged: you merged it
(*Merging the pull request* in the **workflow rule**), the operator says so, or
`gh pr view <PR> --json state` reports `MERGED`. It covers a worktree a host made for the session
(`.claude/worktrees/`, `.coddy/worktrees/` and the like) as much as one made by hand, and the
isolated site-repository worktree once its commit is pushed.
A branch that reached `main` by a direct push, with no pull request, is finished the same way once
the push is confirmed. Step 1 then checks it against `main` instead of a pull request
(`git -C <main checkout> fetch origin`, then
`git -C <main checkout> merge-base --is-ancestor <branch> origin/main`), and step 4 has nothing to
delete unless the branch itself was pushed.
A merged branch is never reused: a follow-up starts a new branch from current `origin/main`.
## Steps
Run them from the main checkout (the first line of `git worktree list`) with `git -C`: the worktree
being removed may be the session's own working directory, which is gone after step 2.
1. Make sure nothing is lost:
- `git -C <worktree> status --porcelain` prints nothing. Uncommitted or untracked files stop the
cleanup: show them to the operator and wait, and never run `git worktree remove --force`
without the operator's word. Ignored files (build output, `node_modules`) go with the worktree;
- every commit of the branch reached the pull request:
`git -C <main checkout> fetch origin pull/<PR>/head`, then
`git -C <main checkout> merge-base --is-ancestor <branch> FETCH_HEAD` succeeds (`FETCH_HEAD`
belongs to the worktree that fetched, so both run in the same one). A commit made after the
merge stops the cleanup the same way: it goes to a new branch and a new pull request first.
2. Remove the worktree: `git -C <main checkout> worktree remove <worktree>`, then
`git -C <main checkout> worktree prune`.
3. Delete the local branch: `git -C <main checkout> branch -D <branch>`. It is `-D` and not `-d`
because a squash or rebase merge leaves the branch's own commits out of `main`, and `-d` refuses
such a branch; the ancestry check of step 1 is what makes `-D` safe.
4. Delete the branch on origin. GitHub deletes the head branch of a merged pull request by itself
(`delete_branch_on_merge` is on for this repository), so this step is usually a check that
`git ls-remote --exit-code --heads origin <branch>` finds nothing. When it finds the branch (the
setting was off, or the merge was a local push), run `git push origin --delete <branch>`. A pull
request from a fork has no branch on origin, and the fork's branch belongs to its author: leave it.
5. Drop the stale remote-tracking ref: `git -C <main checkout> fetch --prune origin`.
Never delete `main`, the orphan `screenshots` branch or a tag, whatever the cleanup lists.
## Report
The final answer names what was removed: the worktree path, the local branch, and the branch on
origin (deleted by you, or already gone). When a step stopped the cleanup, it names what stopped it
and what is left on the disk, so the operator decides.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 3,978 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository31 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .cursor/rules/acp-protocol.mdcCursor rule
- .cursor/rules/agent-model-choice.mdcCursor rule
- .cursor/rules/api-layer.mdcCursor rule
- .cursor/rules/architecture.mdcCursor rule
- .cursor/rules/build-tags.mdcCursor rule
- .cursor/rules/code-style.mdcCursor rule
- .cursor/rules/config-roundtrip.mdcCursor rule
- .cursor/rules/console-tui.mdcCursor rule
- .cursor/rules/core-modules.mdcCursor rule
- .cursor/rules/docs-translation.mdcCursor rule
- .cursor/rules/gateway.mdcCursor rule
- .cursor/rules/implementation-order.mdcCursor rule
- .cursor/rules/llm-streaming.mdcCursor rule
- .cursor/rules/logger-components.mdcCursor rule
- .cursor/rules/process-lifecycle.mdcCursor rule
- .cursor/rules/provider-auth.mdcCursor rule
- .cursor/rules/provider-devin.mdcCursor rule
- .cursor/rules/provider-proxy.mdcCursor rule
- .cursor/rules/russian-wording.mdcCursor rule
- .cursor/rules/session-storage.mdcCursor rule
- .cursor/rules/skills-delivery.mdcCursor rule
- .cursor/rules/testing.mdcCursor rule
- .cursor/rules/text-encoding.mdcCursor rule
- .cursor/rules/tool-images.mdcCursor rule
- .cursor/rules/turn-admission.mdcCursor rule
- .cursor/rules/ui-assets.mdcCursor rule
- .cursor/rules/ui-spa.mdcCursor rule
- .cursor/rules/ui-verification.mdcCursor rule
- .cursor/rules/workflow.mdcCursor rule
- .cursor/rules/workspace-identity.mdcCursor rule
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

