mk:worktree
Internal skill that creates, merges, lists, cleans and prunes git worktrees so parallel agents work in isolation.
| Source | .claude/skills/worktree/SKILL.md |
| Owner | git |
| Runtime | claude-code |
| Risk | medium |
What it does
mk:worktree manages git worktrees through scripts/worktree.cjs. Each parallel agent gets its own worktree so file edits do not collide. The orchestrator (mk:cook, mk:workflow-orchestrator) calls it when a complex task splits. It is not user-invocable. references/commands.md has the full option and JSON reference.
When not to use it
To plan a whole parallel team with ownership map and task queue, use mk:team-config, which calls this skill.
Actions
Run the commands as node ${CLAUDE_SKILL_DIR}/scripts/worktree.cjs <action> ... --json.
| Action | What it does |
|---|---|
info | Reports repository state. Run it before create. |
create "{agent-name}" --orchestrated | Creates .worktrees/{agent-name} on branch parallel/{agent-name}-{timestamp}. |
merge | git merge --no-ff {branch} into the feature branch. On conflict it stops and reports to the orchestrator, with no auto-resolve. After a clean merge, run the full test suite, then delegate a status report to project-manager in the background unless MEOWKIT_PM_AUTO=off. |
remove "{agent-name}" (cleanup) | Removes the worktree. Release the agent's mk:task-queue ownership first, and commit or stash uncommitted changes. |
list | Lists worktrees. |
status | Shows ahead and behind divergence and dirty state, and the count of active worktrees. |
prune --dry-run, then prune | Cleans stale worktree metadata. Dry run first. |
review-pr --pr N --remote <name> --session <id> | Creates a detached worktree pinned to a PR head for assured review. Add --dry-run to validate only. |
review-pr-cleanup --manifest <path> | Removes a review worktree. --sweep --dry-run finds stale sessions, and --apply executes. |
Before the first parallel worktree, make sure .worktrees/ is in .gitignore.
review-pr fetches pull/N/head from the PR's base remote, never a fork. It writes tasks/reviews/<session>/manifest.json and a .mewkit-review.json back-reference inside the worktree. Cleanup runs only when the manifest's nonce matches that back-reference and the target is a detached .worktrees/review-pr-* worktree, so it can never remove the main checkout or a feature worktree. Force is allowed, since review worktrees are dirty after builds.
Safety rules
- Create worktrees only on feature branches, never on
mainormaster. - Keep at most 3 active worktrees.
- Remove worktrees after the merge. Stale ones keep their branches checked out.
- Never force-push from a worktree. It shares
.gitwith the main checkout.
Gotchas
- Creation fails with
BRANCH_CHECKED_OUTif the branch exists. Timestamps in orchestrated branch names prevent collisions. git worktree removefails silently when the directory was already deleted by hand. The script checks existence first.- Merge conflicts on
SKILL.mdandCLAUDE.mdare common in parallel runs. Stop and report them. - On macOS, quote paths that contain
:from skill names.