/scaffolding:worktree-managementfrom scaffolding
Manages git worktree lifecycle including creation, diagnostics, recovery, and cleanup. Useful when debugging worktree isolation, recovering stuck worktrees, or managing task isolation in parallel agent workflows.
Ships in scaffolding. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Scaffolding.tool-specific worktree lifecycle management, diagnostics, and recovery procedures.
Live worktrees:
!git worktree list 2>/dev/null || true
Other agents (developer, architect) do NOT commit. The worktree flow is:
If a worktree has no new commits after an agent finishes, the changes are uncommitted — gitops must commit them BEFORE merge.
When Agent Teams is enabled (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1, see
docs/agent-teams.md), multiple writer teammates may run concurrently. The
worktree model makes this safe ONLY if both hold:
.scaffolding/worktrees/{task_id[:12]} AND its OWN unique SCAFFOLDING_TASK_ID.
No two writers share a working tree or a /tmp/scaffolding-mtime-${TASK_ID}.json
staleness store — sharing would trip file-staleness-check.sh between them and
produce unattributable interleaved changes.merging→merged states below.
Parallel work is allowed; parallel committing/merging is not — only one merge
is ever in flight.create_worktree() --> agent executes (no commit) --> gitops: commit
--> gitops: merge_to_main() --> gitops: push --> gitops: cleanup
| Status | Meaning |
|---|---|
ready | Created, waiting for task execution |
merging | Merge in progress |
merged | Successfully merged to main |
conflict | Merge conflict detected |
cleanup | Being removed |
removed | Fully cleaned up |
| Resource | Path |
|---|---|
| Worktrees directory | .scaffolding/worktrees/ (local real dir, never on NFS) |
| Task worktree | .scaffolding/worktrees/{task_id[:12]}/ — branch scaffolding/{task_id[:12]} |
| Worktree metadata | .scaffolding/worktrees/{task_id[:12]}/worktree.json |
| Thread worktree | .scaffolding/worktrees/threads/{id8}/ |
| Named worktree | .scaffolding/worktrees/<name>/ — plugin WorktreeCreate hook, branch worktree-<name> (/ in the name becomes +) |
.claude/worktrees/ is no longer used.
Inside a worktree, .scaffolding/conversations is a symlink to the same share
target as the main checkout (readlink -f of the main link). A spec written from
a worktree therefore lands on the share and survives worktree removal. The
WorktreeCreate hook creates this link; the WorktreeRemove hook deletes only
the link, never the target. Do not copy conversation files into a worktree, and
do not rm -rf through the link.
The WorktreeRemove hook only removes registered worktrees under the main
checkout's .scaffolding/worktrees/. Dirs without worktree.json are not
platform-made; the platform sweep must leave them alone.
git worktree list
ls -la .scaffolding/worktrees/
for d in .scaffolding/worktrees/*/; do
changes=$(cd "$d" && git status --porcelain 2>/dev/null | wc -l)
if [ "$changes" -gt 0 ]; then
echo "UNCOMMITTED: $d ($changes files)"
fi
done
git worktree remove --force .scaffolding/worktrees/{task_id[:12]}
git branch -D scaffolding/{task_id[:12]}
rm -rf .scaffolding/worktrees/{task_id[:12]}
git worktree prune
cd .scaffolding/worktrees/{task_id[:12]}
git add -A && git stash
cd /project/root && git stash pop
Cleanup is the final step of every merge, for ANY worktree gitops worked in (.scaffolding/worktrees/..., ~/.cache/worktrees/..., anywhere). Do it for squash-merged PRs too.
# from the main checkout, never from inside the worktree
git -C <worktree> status --porcelain --untracked-files=no # must be empty
git worktree remove <worktree> # --force only for untracked build output (node_modules)
git branch -D <branch>
git worktree prune
Note: Only merge and discard clean up. PR-open and keep actions leave the worktree intact (clean up after the PR is merged).
/worktree-gcWorktreeRemove only sees worktrees made by worktree-create.sh. Plain git worktree add ones (e.g. ~/.cache/worktrees/<name>) and squash-merged branches are caught by scripts/worktree-gc.sh:
bash "${CLAUDE_PLUGIN_ROOT}/scripts/worktree-gc.sh" # dry run
bash "${CLAUDE_PLUGIN_ROOT}/scripts/worktree-gc.sh" --apply # remove
bash "${CLAUDE_PLUGIN_ROOT}/scripts/worktree-gc.sh" --all-repos ~/repos # every repo under a dir
REMOVE only if no uncommitted tracked changes AND the work is in origin/<default> (no commits ahead, patch-equivalent, or squash-merged: remote ref gone + commit subjects in origin/<default>). Unsure -> KEEP.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
39 skills in this plugin
/agent-commsSendMessage recipient validation and worktreePath safety (CWE-59). TRIGGER when: validating a SendMessage `to:` recipient against the agent whitelist, or a worktreePath from another agent before acting on it. SKIP: routing topology (agent Comms Protocol); git ops (use git-operations); worktree recovery (use worktree-management)./agent-memoryRepo-local file memory under .scaffolding/ (shared/agent/conversation tiers). TRIGGER when: reading or writing .scaffolding/ memory files, or choosing which file tier an insight belongs in. SKIP: vector memory / MCP search and store (use semantic-memory-mcp); distilling conversations (use distill)./api-designRESTful API design standards: resource naming, HTTP methods, status codes, pagination, versioning. TRIGGER when: designing new API endpoints, defining error response shapes, or adding pagination/filtering. SKIP: implementing FastAPI route code (use python-patterns); error-handling internals (use error-handling)./context-engineeringOptimize Claude Code context-window usage for accuracy and cost. TRIGGER when: hitting context limits, structuring prompts for an agent, or trimming what gets injected into a task. SKIP: persisting knowledge across sessions (use agent-memory); semantic recall tuning (use semantic-memory-mcp)./database-optimizationSchema design, index strategy, migration safety, and query analysis. TRIGGER when: designing tables or indexes, writing a migration, or diagnosing a slow query. SKIP: writing ORM model code (use python-patterns); generic backend patterns (use python-patterns)./distillKnowledge distillation: candidate extraction, confidence scoring, tier routing. Invoked by /learn and the memory-ingest Stop hook, not loaded proactively by agents. TRIGGER when: /learn or the Stop hook asks to distill, or scoring a candidate. SKIP: file memory writes (use agent-memory); vector store (use semantic-memory-mcp).npx claudepluginhub komluk/scaffolding --plugin scaffoldingOther plugins' skills for the same job