agentleFS
KylianmgtKylianmgt/spec-first-skills/skills/worktree-story/SKILL.md

worktree-story

Skill0 starsChanged 36 days agoMITView on GitHub

Create an isolated git worktree and branch for the current task before changing any files. Use at the start of implementation work in a git repository, features, fixes, refactors, especially when the main checkout must stay clean or other work may run in parallel. Not needed for read-only tasks.

  • Reads credentials

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 5 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before changing anything, move the work into a dedicated git worktree on its own branch.

    line 8
  2. Distinctive:

    If the main checkout has uncommitted changes, do not drag them into the feature, tell the user and ask how to proceed.

    line 19
  3. Distinctive:

    Run git worktree list, then either continue there or choose a new branch name.

    line 40
  4. Very specific:

    If git worktree remove refuses because of modified files, show the user what is dirty instead of reaching for --force.

    line 58
  5. Distinctive:

    Never modify files, commit, or switch branches in the main checkout while a feature worktree exists for this task.

    line 75
  6. Very specific:

    Never use --force variants of worktree or branch commands to bypass an error you have not explained to the user.

    line 77
  7. Distinctive:

    Never delete a worktree or branch containing unmerged work without explicit confirmation.

    line 79

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill 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.

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

Worktree Per Feature (User Story): One Task, One Isolated Checkout

Before changing anything, move the work into a dedicated git worktree on its own branch. The main checkout stays untouched, and parallel work stays possible.

Workflow

  1. Confirm the repo and check its state.

    git rev-parse --show-toplevel
    git status --porcelain

    If the main checkout has uncommitted changes, do not drag them into the feature, tell the user and ask how to proceed.

  2. Name the branch after the feature: feature/<slug> (e.g. feature/rate-limit-login). If a spec exists (see the spec-first skill), reuse its slug so branch, spec, and PR line up.
  3. Create the worktree as a sibling folder, never nested inside the repo:

    git worktree add ../<repo-name>-<slug> -b feature/<slug>

    Example, repo shop, feature rate-limit-login:

    git worktree add ../shop-rate-limit-login -b feature/rate-limit-login
  4. Handle errors, never force through them.
    • "branch already exists": attach to it without -b: git worktree add ../<dir> feature/<slug>, or pick a new slug if that branch belongs to other work. Never -B (force-reset) an existing branch.
    • "already checked out in another worktree": that feature is live elsewhere. Run git worktree list, then either continue there or choose a new branch name.
    • Target directory already exists: choose another path. Never delete a directory you did not create.
  5. Work only inside the worktree. cd into it and stay there: every edit, build, and test run happens under the worktree path. Commit to the feature branch as you go. The main checkout is read-only for you from now on.
  6. Report the path. Tell the user the absolute worktree path and branch name as soon as they exist, and repeat both in your final summary.

Cleanup (after the branch is merged, not before)

git worktree remove ../<repo-name>-<slug>
git branch -d feature/<slug>     # -d refuses unmerged work; that is the point
git worktree prune

If git worktree remove refuses because of modified files, show the user what is dirty instead of reaching for --force.

Edge cases

  • Not a git repo: say so and ask whether to git init or proceed without isolation, never pretend the isolation exists.
  • Dependencies do not follow: node_modules, virtualenvs, and ignored .env* files are not copied into a new worktree. Re-run the installer (npm install, uv sync, ...) and copy env files only with the user's consent.
  • Shared state is still shared: databases, dev-server ports, and global caches are not isolated between worktrees. Flag collisions (two servers on one port) instead of silently debugging them.

Boundaries

  • Never modify files, commit, or switch branches in the main checkout while a feature worktree exists for this task.
  • Never use --force variants of worktree or branch commands to bypass an error you have not explained to the user.
  • Never delete a worktree or branch containing unmerged work without explicit confirmation.

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.