agentleFS
ArcanEdge-AIArcanEdge-AI/coding-agent-playbook-claude-code/skills/worktree-lifecycle/SKILL.md

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

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
  1. Distinctive:

    Keep the budget at zero unless a specific writer needs branch or filesystem isolation that sharing or serializing cannot provide safely.

    line 24
  2. Distinctive:

    Only the root raises the budget and issues a permit.

    line 25
  3. Very specific:

    Before your final response, set every task-created auxiliary to removed under verified gates, or preserved with an exact blocker.

    line 30
  4. Distinctive:

    Create one only when all of these hold:

    line 34
  5. Very specific:

    No bundled agent sets isolation: worktree, and none carries EnterWorktree or ExitWorktree.

    line 44
  6. Distinctive:

    Not reasons to create one: another subagent exists.

    line 46
  7. Distinctive:

    Remove a task-created auxiliary only after verifying:

    line 50
  8. Distinctive:

    no running process, terminal, server, or watcher depends on the checkout

    line 55
  9. Very specific:

    Prefer the supported Claude Code cleanup path when the host owns the auxiliary.

    line 59
  10. Very specific:

    Never: use force removal, reset, clean, stash, or broad recursive deletion as a cleanup shortcut.

    line 61
  11. Distinctive:

    If any gate fails, preserve it and report the canonical path, owner, branch or detached HEAD, exact blocker, and next action.

    line 63
  12. Distinctive:

    Do not defer task-owned cleanup to scheduled automation, and leave the active host-managed worktree to the host's lifecycle.

    line 69

“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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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: worktree gets a worktree branched from your repository's default branch, not from the current session's HEAD — unless worktree.baseRef is 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

  1. 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.
  2. Classify it — host-managed primary, user-managed existing, or task-created auxiliary. The class determines what you may do with it.
  3. Keep the budget at zero unless a specific writer needs branch or filesystem isolation that sharing or serializing cannot provide safely.
  4. 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.
  5. Record the base ref and exact SHA, and account for worktree.baseRef.
  6. Reuse a compatible task-owned worktree before creating another. A new subagent or a retry is not a reason to create one.
  7. Give every worker an exact workspace and write scope. Descendants never request isolation or create, adopt, repurpose, move, or remove worktrees.
  8. Integrate accepted work through the declared target, and validate the combined result in the integration workspace.
  9. Before your final response, set every task-created auxiliary to removed under verified gates, or preserved with 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.