بنقرة واحدة
worktree-isolation
Conflict-safe git worktree workflow.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Conflict-safe git worktree workflow.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Iterative multi-round codebase audit with diminishing-returns detection. Run 5-20+ rounds, each focusing on one specific area. Built from 19 rounds of dogfooding pi-crew on itself.
Pi TUI crew widget data sources, display priority, and rendering performance.
Multi-phase orchestration for planners and executors.
Spawn 3 adversarial subagents (Skeptic, Pragmatist, Critic) to evaluate a decision, architecture choice, or plan. Anti-anchoring: each role receives ONLY the question, not conversation history. Aggregates votes into consensus recommendation with dissent tracking. Use when facing critical decisions, architecture choices, security tradeoffs, or plan reviews where single-perspective analysis is insufficient.
Background worker, heartbeat, stale-run, crash-recovery, and deadletter workflow. Use when debugging stuck/dead workers or changing async run reliability.
Child Pi worker spawning, lifecycle callbacks, and failure modes.
| name | worktree-isolation |
| description | Conflict-safe git worktree workflow. |
| origin | pi-crew |
| triggers | ["create worktree","parallel workers","isolate edits","cleanup worktree","branch freshness"] |
Use this skill for worktree-based execution or cleanup. Git worktrees create isolated working directories that allow parallel code-changing tasks without git conflicts.
A git worktree is a separate working directory linked to the same repository. It has its own:
But it shares:
.git/objects)This means creating a worktree is cheap (no clone needed) and fast.
Use worktree mode when:
Don't use worktree mode when:
Prerequisites:
git status empty)Creation flow:
team-runner.ts (workspaceMode: "worktree")
→ prepareTaskWorkspace(manifest, task)
→ assertCleanLeader(repoRoot)
→ git worktree add <path> <branch>
→ linkNodeModulesIfPresent(repoRoot, worktreePath)
→ return { cwd: worktreePath, worktreePath, branch }
Naming convention:
crew/<sanitized-runId>-<sanitized-taskId>.worktrees/<runId>/<taskId>/Example:
Run: team_20260514092752_218fe358085d7115
Task: 01_explore
Branch: crew/team-20260514092752-218fe358085d7115/01-explore
Path: .worktrees/team-20260514092752-218fe358085d7115/01-explore/
If a worktree with the same branch already exists, it is reused instead of recreated:
// Check if worktree already exists
const existing = git(cwd, ["worktree", "list", "--porcelain"]);
if (existing.includes(branch)) {
return { reused: true, worktreePath: parsePath(existing) };
}
Reuse is safe when the worktree's base branch hasn't diverged (checked via branch-freshness.ts).
Each task works in its own worktree directory:
cwd = worktree pathgit status shows only that task's changesOn task completion:
git worktree remove <path>On force cleanup:
git worktree remove <path> --forceSafety rules:
git status before cleanupWorktrees can become stale when:
Detection approach:
// Check if base branch has diverged
function isStaleWorktree(worktreePath: string, baseBranch: string): boolean {
const current = git(worktreePath, ["rev-parse", "--abbrev-ref", "HEAD"]);
const ahead = git(worktreePath, ["rev-list", "--count", `${baseBranch}..HEAD`]);
const behind = git(worktreePath, ["rev-list", "--count", `HEAD..${baseBranch}`]);
return Number(ahead) > 10 || Number(behind) > 0;
}
Cleanup stale worktrees:
# List all worktrees
git worktree list
# Remove stale worktree
git worktree remove .worktrees/stale-task --force
When worktrees complete and changes need to be merged back:
git status --porcelain shows conflicts.If conflicts occur:
git merge --no-commit <branch>
# Resolve conflicts manually
git add <resolved-files>
git commit -m "Merge branch and resolve conflicts"
Before reusing a worktree, verify the base branch hasn't diverged:
function checkBranchFreshness(worktreePath: string, baseBranch: string): {
fresh: boolean;
ahead: number;
behind: number;
} {
const status = git(worktreePath, ["status", "--porcelain"]);
if (status.trim()) return { fresh: false, ahead: 0, behind: 0 }; // dirty
const current = git(worktreePath, ["rev-parse", "--abbrev-ref", "HEAD"]).trim();
if (current !== baseBranch) return { fresh: false, ahead: 0, behind: 0 }; // different branch
// Check divergence
const ahead = Number(git(worktreePath, ["rev-list", "--count", `${baseBranch}..HEAD`]));
const behind = Number(git(worktreePath, ["rev-list", "--count", `HEAD..${baseBranch}`]));
return { fresh: ahead === 0 && behind === 0, ahead, behind };
}
If a task crashes mid-worktree:
git worktree list.crew/state/runs/Before creating or cleaning up worktrees, verify:
If ANY answer is NO → Stop. Verify worktree safety before proceeding.
branch-freshness.ts before reuse. If base branch moved, recreate instead.<repo-root>/.worktrees/. Never store outside.src/worktree/worktree-manager.ts — prepareTaskWorkspace, assertCleanLeader, linkNodeModulesIfPresent, sanitizeBranchPartsrc/worktree/cleanup.ts — worktree cleanup logic, dirty state detectionsrc/worktree/branch-freshness.ts — branch divergence detectionsrc/runtime/team-runner.ts — workspaceMode handling, worktree passed to tasksrc/runtime/task-runner.ts — worktreePath in task contextcd pi-crew
# List all worktrees
git worktree list
# Check leader repo is clean
git status --short
# Verify worktree creation
node --experimental-strip-types -e "
import { prepareTaskWorkspace } from './src/worktree/worktree-manager.ts';
// Requires clean repo and workspaceMode='worktree'
"
# TypeScript
npx tsc --noEmit
# Tests
node --experimental-strip-types --test test/unit/worktree-manager.test.ts test/integration/worktree-mode.test.ts
npm test