一键导入
forge-worktree-gate
WHEN: About to start any implementation task. HARD-GATE: Every task gets fresh worktree (D30). No shared state, no cross-contamination.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
WHEN: About to start any implementation task. HARD-GATE: Every task gets fresh worktree (D30). No shared state, no cross-contamination.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
WHEN: You need to detect performance regressions before merge — TTFB, response time, bundle size. Run as part of forge-eval-gate or standalone before raising a PR.
WHEN: A decision is being superseded, deprecated, or has aged out. Archive it without deletion — marks as warm→cold→archived with full audit trail.
WHEN: You are writing a new decision, superseding an old one, or querying relationships across decisions. Create semantic edges between decisions and link concepts across products/projects/time.
WHEN: You are about to make a decision and need to check if prior art or past learnings exist. Recall decisions, patterns, and gotchas from the brain before proceeding.
WHEN: You need to trace the full provenance of a specific decision — who made it, when, why, and what alternatives were considered. Shows why, when, by whom, evidence, alternatives, outcome.
WHEN: You need to record a decision, lock a spec, log an eval run, or document learnings in the brain.
| name | forge-worktree-gate |
| description | WHEN: About to start any implementation task. HARD-GATE: Every task gets fresh worktree (D30). No shared state, no cross-contamination. |
| type | rigid |
| version | 1.0.0 |
| preamble-tier | 3 |
| triggers | ["worktree gate","start work in worktree","check worktree before starting"] |
| allowed-tools | ["Bash"] |
Rule: Every single task gets a fresh git worktree. No exceptions.
| Rationalization | The Truth |
|---|---|
| "My change is small, I can work in main without isolation" | Small changes have large blast radius. Untracked dependencies, implicit assumptions, forgotten cleanup all hide in main. Isolation is never optional. |
| "Creating worktrees adds complexity and overhead" | Worktree creation is 2 commands. Debugging cross-contamination from main is 4 hours. The math is clear. |
| "I'll be careful not to break anything, I don't need worktrees" | Vigilance is not isolation. You can't be careful about things you don't know you're doing. Worktrees prevent accidental contamination. |
| "We already have feature branches, that's sufficient isolation" | Feature branches in main still share node_modules, build artifacts, environment state. Worktrees isolate the entire filesystem context. |
| "This task doesn't touch other projects, worktree seems unnecessary" | Tasks are not isolated to single projects. Dependency chains are invisible until isolation reveals them. Always isolate. |
| "Setting up a fresh worktree takes time we don't have" | Fresh worktree: 2 min. Debugging why test passes in main but fails in isolation: 2 hours. Time calculation is backwards. |
| "The test suite passes in my working directory, we're good to go" | Your working directory has 6 months of accumulated build artifacts. Fresh worktree has none. Tests pass there? Then it's real. |
| "We can do worktree isolation retrospectively if needed" | Retrospective isolation is impossible. Once merged, the bug is live. Isolation is pre-merge, always. |
| "One task can reuse the worktree from the previous task" | Worktree reuse means state leakage. Previous task's dependency modifications, config changes, cleanup gaps all infect next task. Fresh only. |
| "Worktrees are overkill for infrastructure or config changes" | Config changes have the most subtle bugs. Fresh environment catches config mistakes that shared main never will. |
EVERY TASK RUNS IN ITS OWN FRESH WORKTREE. THERE IS NO EXCEPTION. A SHARED WORKTREE IS A SHARED FAILURE MODE.
If you notice any of these, STOP and do not proceed:
[P4.1-WORKTREE-FAIL] when this gate fails — forge-worktree-gate is a hard prerequisite for conductor-orchestrate State 4.1. If worktree validation fails here, conductor writes [P4.1-WORKTREE-FAIL] task_id=<id> repos_affected=<list> reason=<msg> to conductor.log and blocks all implementation dispatch. The pipeline cannot proceed until this gate passes. See docs/conductor-log-format.md for the full marker format.node_modules/ or dist/ directory — Worktree isolation has been broken. Both tasks are compromised. Recreate both worktrees fresh from main.For each task:
Create worktree (invoke /worktree-per-project-per-task)
Creates isolated worktree:
- Branch name: feature/TASKID (e.g., feature/D123-backend-auth)
- Based on: main (always, not on other tasks' branches)
- Directory: .claude/worktrees/TASKID/
- Environment: clean slate (node_modules, build artifacts, cache all fresh)
Verify isolation:
Document task context in brain (decision ID: WKRK-YYYY-MM-DD-HH)
If feature requires multiple tasks working together:
/pr-set-coordinate to raise coordinated PRs (in merge order)
/worktree-per-project-per-task with action=cleanup/worktree-per-project-per-task with multi_project=truerm -rf .claude/worktrees/OLD_TASKID/Before implementing, verify:
During implementation:
After task complete:
Situation: Cannot create fresh worktree because disk is full or storage quota exceeded. Previous worktrees were not cleaned up.
Example: .claude/worktrees/ directory is 500GB; 30 old worktrees with node_modules accumulated. Disk has <10GB free.
Do NOT: Work in main branch to save space. Space shortage is a real problem that must be fixed.
Action:
du -sh .claude/worktrees/*/
rm -rf .claude/worktrees/OLD_TASKID/
Situation: Parent repository is corrupt or in bad state. Worktree creation fails because git cannot work with the repo.
Example: "fatal: not a git repository" or "corrupted object file" or "git index lock exists"
Do NOT: Skip worktree, work in main. Git corruption must be fixed.
Action:
git fsck --full
git status
rm .git/index.lock
git status # should work now
git fetch --unshallow # convert to full clone
git fsck --full # should pass with no errors
git log -1 # should show recent commit
Situation: Worktree exists but cannot be deleted. Files are in use, permissions prevent deletion, or git locks remain.
Example: "Permission denied: .claude/worktrees/TASKID/" or "Cannot delete, files in use by another process" or ".git/HEAD is locked"
Do NOT: Leave dirty worktrees around. Accumulation of dirty worktrees blocks future work.
Action:
lsof +D .claude/worktrees/TASKID/kill <PID>rm -rf .claude/worktrees/TASKID/ls -la .claude/worktrees/TASKID/chown -R $USER .claude/worktrees/TASKID/rm .claude/worktrees/TASKID/.git/HEAD.lockrm -rf --force .claude/worktrees/TASKID/Output: WORKTREE CREATED (ready to implement) or BLOCKED (disk space full after cleanup, git repo corrupted, worktree cleanup failed)
Symptom: Task was started in a worktree 3 days ago. Meanwhile, 12 commits landed on main (a security hotfix, an API change). The worktree branch is now 12 commits behind main, and the task's code touches files modified by those commits.
Do NOT: Ignore the divergence and continue working — the merge conflict will be larger and more complex the longer it's ignored.
Action:
git log --oneline HEAD..origin/mainSymptom: A cross-repo task requires synchronized changes to backend/ and web/. Two separate worktrees are created — one in each repo. But the changes must land together (atomic across repos) to not break the running product.
Do NOT: Merge one repo's worktree before the other is ready — partial cross-repo merges break integration.
Action:
Merge Order field — typically backend first, then frontendBefore starting implementation in worktree:
git worktree list confirms this worktree is separate from main.