agentleFS
rafaelobrafaelob/pragmatic-agent-skills/skills/worktree-lifecycle/SKILL.md

worktree-lifecycle

Skill23 starsChanged 56 days agoApache-2.0View on GitHub

Use when a second concurrent writer needs an isolated tree, or a git worktree needs census, ownership check or disposal. One owner per tree. Not merge conflicts. Whole-repo cleanup -> exhaustive-repo-cleanup-audit.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do not create a worktree, dependency environment and service stack per micro-task.

    line 37
  2. Distinctive:

    Never remove, move or reset a tree another writer owns, or whose owner you cannot establish.

    line 42
  3. Very specific:

    Never force: no worktree remove --force, branch -D, reset --hard, clean -fd, checkout -- <path>, restore or stash on a shared tree.

    line 43
  4. Distinctive:

    Never discard uncommitted work.

    line 44
  5. Distinctive:

    When the integration itself conflicts, use a merge-conflict skill if one is installed.

    line 47

“Common” is measured: kept by at least 6 in 10 of the 3 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

Isolate only the work that needs it

Read the project's concurrency policy (its AGENTS.md or README) and run git worktree list before creating a tree. Use the harness's native isolation and the worktree tooling the repository declares; with none, plain git worktree. A second persistent writer may need a separate tree; do not generalize one project's rule to every harness or native child session.

Confirm owner, branch, base and intended write scope. A directory without a current owner is not disposable. Preserve unknown ownership and pending staged/unstaged work. Do not edit trunk and a slice concurrently as if they were the same workspace.

Integrate with appropriate evidence

Run fast affected checks within the working slice, then commit through the project's declared commit path (plain git commit of explicit paths if none). A merge that changes relevant behavior can invalidate local results; an unrelated new read does not. Do not repeat a check that the same approved evidence already covers.

Do not create a worktree, dependency environment and service stack per micro-task. Do not build a new lifecycle daemon or lock registry. If git or native tooling refuses, investigate the specific owner/state conflict rather than bypassing it.

After integration or explicit abandonment, remove only resources whose ownership and preservation are established: commit what is yours, git worktree remove <path> without --force, then git branch -d <branch>. A tree that holds a junction or symlink (a linked node_modules, a shared venv) goes through the repository's reaping verb, which unlinks links first: a raw git worktree remove can descend through a junction and delete its target. Age or absence of a visible process is not deletion authority. Stop after the requested lifecycle transition is complete and its readback is confirmed, not after a cleanup sweep across the machine.

Hard rules

  • Never remove, move or reset a tree another writer owns, or whose owner you cannot establish.
  • Never force: no worktree remove --force, branch -D, reset --hard, clean -fd, checkout -- <path>, restore or stash on a shared tree. Git refuses an unmerged branch or a dirty tree on purpose.
  • Never discard uncommitted work; commit or preserve it first.
  • With no supported tool for a leftover, delete it file by file, naming each path. If a guard refuses a command, do not bypass it (env var, flag, wrapper): use the supported path, or ask the user for explicit approval of that exact deletion. Approval never lifts a guard, and never hand a refused command to the user to paste and run.

When the integration itself conflicts, use a merge-conflict skill if one is installed.

Price the tree before you open it

A linked worktree shares the object store and costs the checkout alone. A CLONE costs the checkout plus a full copy of .git — and a runtime's isolation flag may write a clone while calling it a worktree, so read what it produced rather than what it is named. Measure .git, multiply by the number of trees you are about to open, and compare against free disk: five children on a repository with a 13 GB .git wrote 81 GB of standalone clones and took the disk from 20 GB free to 1.9 GB (measured 2026-09-18). When the product does not fit, serialize the writes in one tree instead — do not open them and plan to clean up after, because a full disk fails writes silently, including the commit that would have preserved the work.

Creating a tree also costs time: minutes in a large repository on Windows (about 4 min for 21k files, measured 2026-10-04). Reuse your own clean tree before opening another. Run the creation in the background with a deadline above its measured duration and never kill it midway: a half-created tree is left locked. If it was interrupted, confirm the original process has stopped, then rerun the same command of the repository's tooling instead of repairing the tree by hand.

When a second tree is justified at all

Never open one for a task that merely feels big. Close it the ordinary way: commit, remove unforced, delete the merged branch. A repository's census or reaping tool is for the tree that will NOT come out clean, not the first thing to reach for.

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.