worktree-isolation
Skill0 starsChanged 8 months agoMITView on GitHub
Use when executing tasks that require filesystem isolation from the current working tree. Covers parallel multi-agent work, subagent tasks that must not disrupt the operator's workspace, and one-off isolated operations. Provides git worktree lifecycle management including creation, branch naming, agent execution, commit strategy, merge/PR workflow, and cleanup.
- Commits and pushes
8 other projects use a version of this.
Adopted by
Most recently taken up by
- 0SxD/agent-skills-plugin-v01their own version, first seen Nov 15, 2026
- niksavis/handilytheir own version, first seen Nov 8, 2026
- ccoalm/ccl-skillstheir own version, first seen Nov 8, 2026
- niksavis/basiclytheir own version, first seen Nov 7, 2026
- cill-i-am/skillstheir own version, first seen Oct 20, 2026
- aditya-deokar/software-factorytheir own version, first seen Sep 29, 2026
Other versions8 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 8
- ccoalm/ccl-skills★ 6same name
- alex-voloshin-dev/ai-skills★ 2same name
- niksavis/basicly★ 2same name
- niksavis/handily★ 2same name
- cill-i-am/skills★ 1same name
- orkait/hyperstack★ 1same name
- 0SxD/agent-skills-plugin-v01★ 0same name
- aditya-deokar/software-factory★ 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 repository23 other files it gives its agents.
- AGENTS.mdAGENTS.md
- adr-generationSkill
- bash-scriptingSkill
- browser-controlSkill
- github-actionsSkill
- gitignore-standardsSkill
- git-operationsSkill
- html-reportSkill
- java-developmentSkill
- mermaid-diagramsSkill
- meta-workspaceSkill
- powershell-scriptingSkill
- project-backlogSkill
- project-documentationSkill
- project-setupSkill
- python-developmentSkill
- refinement-tribunalSkill
- skill-cli-developmentSkill
- technical-writingSkill
- testing-standardsSkill
- typescript-developmentSkill
- web-auth-bridgeSkill
- writing-ai-instructionsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
34 rules. 0 are common, 33 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 7 edited versions we read keep these.
33
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
- Distinctive: line 41
Do NOT use this skill when:
- Distinctive: line 51
Place worktrees in a persistent, user-invisible location that is not subject to OS-level temporary-file cleanup.
- Distinctive: line 55
All platforms use the same path under the user's home directory:
- Very specific: line 61
If XDG_DATA_HOME is set, replace ~/.local/share with its value.
- Distinctive: line 63
Create the base directory on first use if it does not exist.
- Distinctive: line 89
All worktree branches use a consistent prefix to distinguish them from human-created branches.
- Distinctive: line 119
Every worktree follows a five-phase lifecycle: Create → Execute → Commit → Apply → Clean up.
- Distinctive: line 123
Create the worktree from the current HEAD of the active branch.
- Distinctive: line 157
After creation, confirm the worktree exists:
- Distinctive: line 167
Run the agent (or subagent) with its working directory set to the worktree path.
- Distinctive: line 171
All file operations MUST use the worktree path, never the main repository path.
- Distinctive: line 173
If the agent needs to run build/test commands, run them from the worktree directory.
- Distinctive: line 178
When dispatching a subagent via the task tool, include these instructions in the prompt:
- Distinctive: line 186
After the agent completes its work, commit all changes on the worktree branch.
- Distinctive: line 196
Follow the repository's commit message conventions
- Distinctive: line 200
If the agent is a subagent, it SHOULD commit its own work before reporting completion.
- Distinctive: line 204
After all worktree branches are committed, determine the appropriate strategy for integrating the work.
- Distinctive: line 232
When merging multiple worktree branches that may overlap:
- Distinctive: line 237
Do NOT auto-resolve conflicts.
- Distinctive: line 238
After resolution, continue with remaining branches.
- Distinctive: line 242
After any merge, verify the working tree is clean:
- Distinctive: line 248
If additional isolated work (tests, linting, validation) should run on the merged result before it is considered final, create a new …
- Distinctive: line 252
Remove the worktree directory and optionally delete the branch.
- Distinctive: line 280
MUST NOT delete a branch that has been pushed to a remote and has an open PR.
- Distinctive: line 281
MUST NOT delete a branch whose changes have not been merged or explicitly discarded by the operator.
- Distinctive: line 282
SHOULD delete the worktree directory even if the branch is kept (the branch persists in the git object store independent of the worktree).
- Distinctive: line 283
SHOULD run git worktree prune after removing worktrees to keep metadata clean.
- Distinctive: line 297
Verify: Check that each agent committed its work.
- Distinctive: line 299
Clean up: Remove all worktrees and delete merged branches.
- Distinctive: line 329
When the operator wants to keep working while an agent runs in the background:
- Distinctive: line 331
Create a worktree for the agent task.
- Distinctive: line 334
When the agent completes, the orchestrator reports the branch name.
- Distinctive: line 349
All changes committed on the worktree branch before cleanup
- Distinctive: line 353
No orphaned worktree metadata remains after cleanup
“Common” is measured: kept by at least 6 in 10 of the 7 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 Isolation
Objective
Execute agent work in isolated git worktrees so that parallel tasks, subagent operations, and background work never modify the operator's working tree. Each worktree gets its own branch, its own filesystem snapshot, and a deterministic lifecycle from creation through merge or discard.
Scope
In-scope:
- Creating and configuring git worktrees for agent use
- Branch naming and worktree directory placement
- Running agents (main or sub) inside a worktree
- Committing, merging, pushing, and creating PRs from worktree branches
- Worktree cleanup and orphan prevention
- Parallel execution patterns for multi-agent workflows
- Operator-concurrent workflows (agent works while human edits the main tree)
Out-of-scope:
- Git worktree internals or low-level plumbing commands
- Non-git version control systems
- Container-based or VM-based isolation
- CI/CD pipeline design
When to Use This Skill
Activate this skill when any of the following apply:
- The harness is dispatching parallel subagents that may touch overlapping files
- A subagent needs to perform work without risk of corrupting the operator's staging area or uncommitted changes
- The operator wants to continue editing the working tree while an agent works in the background
- A task involves exploratory or speculative changes that should be easy to discard
- Multiple agents must each produce independent changesets for later review or merge
Do NOT use this skill when:
- The task modifies only a single file with no risk of conflict
- The operator explicitly requests in-place changes
- The repository is not a git repository
Worktree Directory Placement
Place worktrees in a persistent, user-invisible location that is not subject to OS-level temporary-file cleanup. The base directory depends on the platform.
Base Directory
All platforms use the same path under the user's home directory:
~/.local/share/agent-worktrees/If XDG_DATA_HOME is set, replace ~/.local/share with its value.
Create the base directory on first use if it does not exist.
Worktree Path Format
<base-directory>/<repo-name>--<branch-suffix>/Example (Windows):
%USERPROFILE%\.local\share\agent-worktrees\my-project--agent-alpha\Example (Linux/macOS):
/home/user/.local/share/agent-worktrees/my-project--agent-alpha/The <repo-name> component is the basename of the git repository root directory. The <branch-suffix> matches the final segment of the branch name (see below).
Branch Naming
All worktree branches use a consistent prefix to distinguish them from human-created branches.
Convention
worktree/<purpose>-<unique>Rules:
<purpose>is a lowercase, hyphen-separated slug describing the task<unique>is a 6-character random hex suffix to prevent collisions (e.g.,a3f1b2). Generate with:$(git rev-parse --short=6 HEAD)$(date +%s | tail -c 3)(Bash) or(-join ((48..57)+(97..102) | Get-Random -Count 6 | ForEach-Object {[char]$_}))(PowerShell)- For parallel agents, incorporate the agent identity before the suffix:
worktree/agent-alpha-a3f1b2 - For single-agent isolation, describe the task:
worktree/refactor-auth-d8e4c1 - Maximum total branch name length: 100 characters
- The suffix is mandatory. Even sequential single-agent worktrees risk collision with leftover branches from previous runs.
Examples:
| Scenario | Branch name |
| Parallel agent "Alpha" | worktree/agent-alpha-a3f1b2 |
| Parallel agent "Beta" | worktree/agent-beta-7c9e01 |
| Isolated refactor task | worktree/refactor-auth-module-d8e4c1 |
| Background test generation | worktree/generate-api-tests-f0b3a9 |
Lifecycle
Every worktree follows a five-phase lifecycle: Create → Execute → Commit → Apply → Clean up.
Phase 1: Create
Create the worktree from the current HEAD of the active branch. Always create a new branch — never check out an existing branch into a worktree.
PowerShell (Windows)
$RepoRoot = git rev-parse --show-toplevel
$RepoName = Split-Path $RepoRoot -Leaf
$BranchName = "worktree/agent-alpha-$(-join ((48..57)+(97..102) | Get-Random -Count 6 | ForEach-Object {[char]$_}))"
$Suffix = ($BranchName -split '/')[-1]
$WtBase = Join-Path $HOME ".local/share/agent-worktrees"
$WtPath = Join-Path $WtBase "$RepoName--$Suffix"
if (-not (Test-Path $WtBase)) { New-Item -Path $WtBase -ItemType Directory -Force | Out-Null }
git worktree add $WtPath -b $BranchNameBash (macOS/Linux)
repo_root=$(git rev-parse --show-toplevel)
repo_name=$(basename "$repo_root")
branch_name="worktree/agent-alpha-$(head -c3 /dev/urandom | xxd -p | cut -c1-6)"
suffix="${branch_name##*/}"
wt_base="${XDG_DATA_HOME:-$HOME/.local/share}/agent-worktrees"
wt_path="$wt_base/${repo_name}--${suffix}"
mkdir -p "$wt_base"
git worktree add "$wt_path" -b "$branch_name"Verification
After creation, confirm the worktree exists:
git worktree listExpected output includes a line for the new worktree with the correct branch.
Phase 2: Execute
Run the agent (or subagent) with its working directory set to the worktree path. The agent operates exclusively within that directory.
Rules for agents executing in a worktree:
- All file operations MUST use the worktree path, never the main repository path.
- The agent MUST NOT
cdto or modify files in the main working tree. - If the agent needs to run build/test commands, run them from the worktree directory.
- The agent SHOULD treat the worktree as its entire world — it has full read/write access within it.
Dispatching a subagent to a worktree:
When dispatching a subagent via the task tool, include these instructions in the prompt:
- State the worktree path explicitly: "Your working directory is
<wt_path>. All file operations use this path." - State the boundary: "Do NOT read or write files under
<main_repo_path>." - Include the branch name so the agent can verify it is on the correct branch.
Phase 3: Commit
After the agent completes its work, commit all changes on the worktree branch.
cd <wt_path>
git add -A
git commit -m "<conventional-commit-message>"Commit message rules:
- Follow the repository's commit message conventions
- Include a clear description of what the agent accomplished
- For parallel agents, prefix the scope with the agent identity:
feat(alpha): add test.txt to all skills
If the agent is a subagent, it SHOULD commit its own work before reporting completion. The orchestrator MUST verify the commit exists.
Phase 4: Apply
After all worktree branches are committed, determine the appropriate strategy for integrating the work. Evaluate the criteria below in order — use the first matching strategy.
Decision Criteria
| Condition | Strategy | Action |
| Operator requested a PR | Push + PR | Push the branch to the remote and create a pull request |
| Changes need human review before integration | Push + share | Push the branch and report the branch name to the operator |
| Multiple worktree branches modify overlapping files | Sequential merge with conflict check | Merge branches one at a time, stopping on conflict for operator resolution |
| Changes are independent and low-risk | Direct merge | Merge the worktree branch into the active branch |
| Changes are speculative or experimental | Share only | Report the branch name to the operator without merging or pushing |
Push + PR
git push origin <branch-name>
# Then use the GitHub MCP server or gh CLI to create a PRDirect Merge (from the main working tree)
cd <main_repo_path>
git merge --no-ff <branch-name> -m "merge: <description>"Sequential Merge (multiple branches)
When merging multiple worktree branches that may overlap:
- Merge the first branch. If clean, continue.
- Merge the next branch. If conflicts arise, STOP.
- Report the conflict to the operator with the conflicting file list and branch names.
- Do NOT auto-resolve conflicts. The operator decides the resolution.
- After resolution, continue with remaining branches.
Post-Merge Verification
After any merge, verify the working tree is clean:
git status --shortIf additional isolated work (tests, linting, validation) should run on the merged result before it is considered final, create a new worktree for that verification step rather than running it in the main tree.
Phase 5: Clean Up
Remove the worktree directory and optionally delete the branch.
Who Cleans Up
| Context | Responsible party | Rationale |
| Subagent completed and merged | Orchestrator | Orchestrator owns the lifecycle and has merge context |
| Single-agent isolation (no orchestrator) | Main agent | Same agent that created the worktree |
| Branch was pushed/shared for review | Operator | Human decides when the branch is no longer needed |
| Parallel execution with orchestrator | Orchestrator after all merges | Batch cleanup after all agents finish |
Cleanup Commands
# Remove the worktree
git worktree remove <wt_path> --force
# Delete the branch (only if merged or no longer needed)
git branch -d <branch-name>
# Use -D if the branch was never merged and should be discarded
git branch -D <branch-name>
# Prune stale worktree metadata (in case of unclean removal)
git worktree pruneCleanup Rules
- MUST NOT delete a branch that has been pushed to a remote and has an open PR.
- MUST NOT delete a branch whose changes have not been merged or explicitly discarded by the operator.
- SHOULD delete the worktree directory even if the branch is kept (the branch persists in the git object store independent of the worktree).
- SHOULD run
git worktree pruneafter removing worktrees to keep metadata clean.
Parallel Execution Pattern
This is the standard pattern for multi-agent parallel work.
Orchestrator Workflow
- Plan: Decompose the task into independent subtasks. Assign each subtask a unique agent name.
- Create: For each agent, create a worktree (Phase 1) with a unique branch name.
- Dispatch: Launch all agents in parallel. Each agent prompt includes its worktree path and branch name.
- Wait: Monitor agent completion.
- Verify: Check that each agent committed its work. Inspect commit logs on each branch.
- Merge: Apply changes using the decision criteria from Phase 4. Merge sequentially if branches may overlap.
- Clean up: Remove all worktrees and delete merged branches.
Example: Three Parallel Agents
Orchestrator creates (each branch gets a unique suffix):
worktree/agent-alpha-a3f1b2 → <base>/my-project--agent-alpha-a3f1b2/
worktree/agent-beta-7c9e01 → <base>/my-project--agent-beta-7c9e01/
worktree/agent-gamma-d8e4c1 → <base>/my-project--agent-gamma-d8e4c1/
Orchestrator dispatches agents in parallel:
Agent Alpha → works in agent-alpha-a3f1b2 worktree
Agent Beta → works in agent-beta-7c9e01 worktree
Agent Gamma → works in agent-gamma-d8e4c1 worktree
Orchestrator merges (sequentially):
merge worktree/agent-alpha-a3f1b2 → clean
merge worktree/agent-beta-7c9e01 → conflict detected → report to operator
(operator resolves)
merge worktree/agent-gamma-d8e4c1 → clean
Orchestrator cleans up:
remove all 3 worktrees
delete all 3 branchesOperator-Concurrent Workflow
When the operator wants to keep working while an agent runs in the background:
- Create a worktree for the agent task.
- Dispatch the agent to the worktree.
- The operator continues editing the main working tree freely.
- When the agent completes, the orchestrator reports the branch name.
- The operator decides when and how to integrate (merge, cherry-pick, or discard).
This pattern is useful for long-running tasks like test generation, documentation updates, or exploratory refactors.
Validation
Pass conditions:
- Worktree created in the correct base directory, not adjacent to the repository
- Branch name follows the
worktree/<purpose>convention - Agent operated exclusively within its worktree directory
- Main working tree was not modified during agent execution
- All changes committed on the worktree branch before cleanup
- Merge strategy matches the decision criteria
- Worktree directory removed after merge or discard
- Branch deleted only when safe (merged or explicitly discarded)
- No orphaned worktree metadata remains after cleanup
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.

