agentleFS
hnikoloskihnikoloski/imlazy/skills/imlazy-worktrees/SKILL.md

worktrees

Skill3 starsChanged 4 months agoMITView on GitHub

Use when starting feature work that needs isolation from current workspace or before executing implementation plans — ensures an isolated workspace exists via native tools or git worktree fallback

  • Installs packages

12 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use reflect.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Microsoft AzureSkill

    reflect

    Learning capture system that extracts HIGH/MED/LOW confidence patterns from conversations to prevent repeating mistakes. Use after user corrections ("no", "wrong"), praise ("perfect", "exactly"), or when discovering edge cases. Complements .squad/agents/{agent}/history.md and .squad/decisions.md.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

10 rules. 0 are common, 7 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 12 edited versions we read keep these.

  • 7

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Ensure work happens in an isolated workspace.

    line 10
  2. Distinctive:

    If that returns a path, you are in a submodule — treat as normal repo.

    line 28
  3. Very specific:

    Check if your harness provides a native worktree tool (names like EnterWorktree, WorktreeCreate, /worktree, or a --worktree flag).

    line 40
  4. Very specific:

    Default: .worktrees/ at project root

    line 48
  5. Very specific:

    If NOT ignored: add to .gitignore, commit, then proceed.

    line 54
  6. Distinctive:

    If git worktree add fails with a permission error (sandbox denial), tell the user and work in the current directory instead.

    line 63
  7. Distinctive:

    Run the project test suite.

    line 78
  8. Distinctive:

    Create a worktree when Step 0 detects existing isolation

    line 96
  9. Distinctive:

    Use git worktree add when you have a native worktree tool

    line 97
  10. Distinctive:

    Create project-local worktree without verifying it is gitignored

    line 98

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

worktrees

Overview

Ensure work happens in an isolated workspace. Prefer your platform's native worktree tools. Fall back to manual git worktrees only when no native tool is available.

Core principle: Detect existing isolation first. Then use native tools. Then fall back to git. Never fight the harness.

Step 0: Detect existing isolation

Before creating anything, check if you are already in an isolated workspace.

GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)

Submodule guard: GIT_DIR != GIT_COMMON is also true inside git submodules. Verify you're not in one:

git rev-parse --show-superproject-working-tree 2>/dev/null

If that returns a path, you are in a submodule — treat as normal repo.

If GIT_DIR != GIT_COMMON (and not a submodule): Already in a linked worktree. Skip to Step 3 (Project Setup). Do NOT create another worktree.

If GIT_DIR == GIT_COMMON: Normal repo checkout. Ask for consent before creating a worktree: "Would you like me to set up an isolated worktree? It protects your current branch from changes." If declined, work in place.

Step 1: Create isolated workspace

Try in this order:

1a. Native worktree tools (preferred)

Check if your harness provides a native worktree tool (names like EnterWorktree, WorktreeCreate, /worktree, or a --worktree flag). If yes, use it and skip to Step 3. Native tools handle directory placement, branch creation, and cleanup automatically.

1b. Git worktree fallback (only if 1a does not apply)

Directory selection (priority order):

  1. Declared user preference in your instructions
  2. Existing project-local .worktrees/ or worktrees/ directory
  3. Existing global ~/.config/imlazy/worktrees/<project>/
  4. Default: .worktrees/ at project root

Safety verification (project-local directories only):

git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null

If NOT ignored: add to .gitignore, commit, then proceed.

Create the worktree:

project=$(basename "$(git rev-parse --show-toplevel)")
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"

If git worktree add fails with a permission error (sandbox denial), tell the user and work in the current directory instead.

Step 3: Project setup

Auto-detect and run appropriate setup:

if [ -f package.json ]; then npm install; fi
if [ -f Cargo.toml ]; then cargo build; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then poetry install; fi
if [ -f go.mod ]; then go mod download; fi

Step 4: Verify clean baseline

Run the project test suite. If tests fail, report failures and ask whether to proceed or investigate. If tests pass, report ready.

Quick reference

SituationAction
Already in linked worktreeSkip creation (Step 0)
In a submoduleTreat as normal repo
Native worktree tool availableUse it (Step 1a)
No native toolGit worktree fallback (Step 1b)
.worktrees/ existsUse it (verify ignored)
Neither existsDefault .worktrees/ at project root
Directory not ignoredAdd to .gitignore + commit
Permission error on createWork in place, tell user
Tests fail on baselineReport + ask before proceeding

Red flags — never

  • Create a worktree when Step 0 detects existing isolation
  • Use git worktree add when you have a native worktree tool
  • Create project-local worktree without verifying it is gitignored
  • Skip baseline test verification
  • Proceed with failing tests without asking

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.