worktree-lifecycle
Skill0 starsChanged 4 months agoMITView on GitHub
Use when Git worktree isolation is being proposed for a Claude Code task, when parallel writers might need filesystem isolation, when a task already owns an auxiliary checkout, or when a task-created worktree must be integrated, preserved, or removed before finishing. Keeps worktree use finite, root-owned, and reconciled inside the task.
6 other projects use a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- rafaelob/pragmatic-agent-skillstheir own version, first seen Nov 1, 2026
- nanosite-ai/nanoflowtheir own version, first seen Oct 9, 2026
- martinappberg/chimaeratheir own version, first seen Sep 28, 2026
- YoniChechik/claude-code-configtheir own version, first seen Sep 18, 2026
- ArcanEdge-AI/coding-agent-playbook-codexedited, first seen Aug 17, 2026
- psw7205/skillstheir own version, first seen May 26, 2026
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 1
- ArcanEdge-AI/coding-agent-playbook-codex★ 313% same
Wrote their own version · 5
- rafaelob/pragmatic-agent-skills★ 24same name
- nanosite-ai/nanoflow★ 15same name
- martinappberg/chimaera★ 7same name
- psw7205/skills★ 1same name
- YoniChechik/claude-code-config★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository28 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- aws-local-preflightSkill
- feature-branch-lifecycleSkill
- handoffSkill
- legacy-path-retirementSkill
- local-ci-preflightSkill
- multi-role-repo-reviewSkill
- multi-session-coordinationSkill
- platform-documentationSkill
- production-api-integrationSkill
- production-architecture-reviewSkill
- production-code-qualitySkill
- production-database-integritySkill
- production-devops-releaseSkill
- production-documentation-onboardingSkill
- production-pass-orchestratorSkill
- production-performance-reviewSkill
- production-readiness-reportSkill
- production-reliability-observabilitySkill
- production-security-reviewSkill
- production-testing-qaSkill
- production-ux-accessibilitySkill
- reference-doc-routingSkill
- senior-code-reviewSkill
- session-cleanupSkill
- subagent-orchestrationSkill
- task-graph-orchestrationSkill
- technical-debt-auditorSkill
The file
We split this skill into the rules it gives an agent
12 rules. 0 are common, 8 are distinctive, and 4 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
8
Distinctive
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Keep the budget at zero unless a specific writer needs branch or filesystem isolation that sharing or serializing cannot provide safely.
- Distinctive: line 25
Only the root raises the budget and issues a permit.
- Very specific: line 30
Before your final response, set every task-created auxiliary to removed under verified gates, or preserved with an exact blocker.
- Distinctive: line 34
Create one only when all of these hold:
- Very specific: line 44
No bundled agent sets isolation: worktree, and none carries EnterWorktree or ExitWorktree.
- Distinctive: line 46
Not reasons to create one: another subagent exists.
- Distinctive: line 50
Remove a task-created auxiliary only after verifying:
- Distinctive: line 55
no running process, terminal, server, or watcher depends on the checkout
- Very specific: line 59
Prefer the supported Claude Code cleanup path when the host owns the auxiliary.
- Very specific: line 61
Never: use force removal, reset, clean, stash, or broad recursive deletion as a cleanup shortcut.
- Distinctive: line 63
If any gate fails, preserve it and report the canonical path, owner, branch or detached HEAD, exact blocker, and next action.
- Distinctive: line 69
Do not defer task-owned cleanup to scheduled automation, and leave the active host-managed worktree to the host's lifecycle.
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Worktree Lifecycle
The default is the current workspace with an auxiliary-worktree budget of zero, and most tasks should end there. A subagent is never a reason to create a worktree.
Full rules: references/worktrees.md. Durable ledger: references/templates/worktree-manifest.md.
The thing that bites people
A subagent with
isolation: worktreegets a worktree branched from your repository's default branch, not from the current session'sHEAD— unlessworktree.baseRefis set to"head".
So an isolated subagent can start without the changes you just made, do good work against the wrong base, and hand back something that looks correct and integrates wrong.
Record the expected base ref and exact SHA before dispatch. Verify the actual checkout after creation. Never treat the host default as proof your changes are present.
Workflow
- Inspect the current checkout:
git worktree list --porcelain, the common Git directory, branch or detached HEAD, exact HEAD, dirty state, and any known session ownership. - Classify it — host-managed primary, user-managed existing, or task-created auxiliary. The class determines what you may do with it.
- Keep the budget at zero unless a specific writer needs branch or filesystem isolation that sharing or serializing cannot provide safely.
- Only the root raises the budget and issues a permit. One active auxiliary needs no extra approval; two or more require the user's approval for the exact count and reasons.
- Record the base ref and exact SHA, and account for
worktree.baseRef. - Reuse a compatible task-owned worktree before creating another. A new subagent or a retry is not a reason to create one.
- Give every worker an exact workspace and write scope. Descendants never request isolation or create, adopt, repurpose, move, or remove worktrees.
- Integrate accepted work through the declared target, and validate the combined result in the integration workspace.
- Before your final response, set every task-created auxiliary to
removedunder verified gates, orpreservedwith an exact blocker.
Creation gate
Create one only when all of these hold:
- repository and common Git directory verified
- base ref and exact SHA recorded
- path and branch explicit or host-assigned, and collision-free
- a concrete write or mutable-state isolation need exists
- sharing, reuse, and serialization are all insufficient
- the budget has capacity and a root permit exists
- ownership, integration target, and cleanup condition recorded
No bundled agent sets isolation: worktree, and none carries EnterWorktree or ExitWorktree. Use isolation only on a root-authorized dispatch.
Not reasons to create one: another subagent exists; work could run in parallel; a node is read-only; a previous attempt failed; a checkout looks old or clean.
Completion gate
Remove a task-created auxiliary only after verifying:
- exact permit, canonical path, repository identity, owner, branch or HEAD
- accepted work is integrated, or abandonment is explicitly authorized
- tracked, untracked, submodule, and valuable ignored artifacts are accounted for
- no running process, terminal, server, or watcher depends on the checkout
- the work is recoverable through its integration or backup target
- it is not the active checkout and not owned by another session or user
Prefer the supported Claude Code cleanup path when the host owns the auxiliary. Otherwise use non-force git worktree remove <exact-path>, then verify both that the path is gone and that it no longer appears in git worktree list --porcelain.
Never use force removal, reset, clean, stash, or broad recursive deletion as a cleanup shortcut. Age, inactivity, or a clean status alone does not establish permission or safety to remove a worktree.
If any gate fails, preserve it and report the canonical path, owner, branch or detached HEAD, exact blocker, and next action. Preserving something you cannot verify is the correct outcome.
Report
Return a compact ledger: starting worktrees, auxiliary budget, permits issued, workspaces created or reused, integration evidence, final disposition for each (removed, preserved, reused, host-managed), and any preserved blocker.
Do not defer task-owned cleanup to scheduled automation, and leave the active host-managed worktree to the host's lifecycle.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
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.

