Git worktree management for parallel SPEC development with isolated workspaces, automatic branch registration, and seamless MoAI-ADK integration. Use when setting up parallel development environments.
63%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./.claude/skills/moai-workflow-worktree/SKILL.mdGit worktree management system for parallel SPEC development with isolated workspaces, automatic registration, and seamless MoAI-ADK integration.
Core Philosophy: Each SPEC deserves its own isolated workspace to enable true parallel development without context switching overhead.
What is MoAI Worktree Management? A specialized Git worktree system that creates isolated development environments for each SPEC, enabling parallel development without conflicts.
Key Features:
Quick Access:
Use Cases:
Purpose: Create isolated Git worktrees for parallel SPEC development.
Key Components:
Registry Structure:
The registry file stores worktree metadata in JSON format. Each worktree entry contains an identifier, file path, branch name, creation timestamp, last sync time, status (active or merged), and base branch reference. The config section defines the worktree root directory, auto-sync preference, and cleanup behavior for merged branches.
File Structure:
The worktree system creates a dedicated directory structure in the user's global home directory. Trees created by moai worktree new <name> live under the home projects root (/worktrees/projects///); the L2 persistent registry remains at the worktree root (~/.moai/worktrees/{ProjectName}/), where you will find the central registry JSON file and individual directories for each SPEC. Each SPEC directory contains a .git file for worktree metadata and a complete copy of all project files.
Detailed Reference: Refer to Worktree Management Module at modules/worktree-management.md
Purpose: Map each worktree task to the command that actually performs it.
Entering a worktree is the launcher's job — moai worktree has no creation verb:
moai cc -w <name> — work inside the worktreemoai cc -w <name> --spawn — open it in a new tmux window, keeping this sessionFor inspection, use git directly: git worktree list.
Management commands, as moai worktree --help lists them:
| Command | Purpose |
|---|---|
sync [branch-name] | Sync worktree with base branch |
remove [path] | Remove a worktree |
clean | Clean stale worktree references |
recover | Repair worktree registry |
done [branch-name] | Complete worktree and cleanup |
snapshot | Capture working tree state snapshot for guard verification |
verify | Verify working tree state against snapshot + check agent response |
restore | Restore working tree to a snapshot's HEAD state |
This table is a copy of the help output. moai worktree --help is the authoritative list; where the two differ, the help output wins.
Detailed Reference: Refer to Worktree Commands Module at modules/worktree-commands.md. Its command examples predate the current command set; where they differ from the table above, the table and moai worktree --help win.
Purpose: Enable true parallel development without context switching.
Workflow Integration:
During the Plan Phase using /moai plan, the SPEC is created, and the launcher (moai cc -w <name>) enters an isolated worktree for it.
During the Development Phase, the isolated worktree environment provides independent Git state with zero context switching overhead.
During the Sync Phase using /moai sync, the worktree sync command ensures clean integration with conflict resolution support.
During the Cleanup Phase, the worktree clean command provides automatic cleanup with registry maintenance.
Parallel Development Benefits:
Example Workflow:
First, create a worktree for SPEC-001 with a description like "User Authentication" and switch to that directory. Then run /moai run SPEC-001 to develop in isolation. Next, navigate back to the main repository and create another worktree for SPEC-002 with description "Payment Integration". Switch to that worktree and run /moai run SPEC-002 for parallel development. When needed, switch between worktrees and continue development. Finally, sync both worktrees when ready for integration.
Detailed Reference: Refer to Parallel Development Module at modules/parallel-development.md
Purpose: Seamless integration with MoAI-ADK Plan-Run-Sync workflow.
Integration Points:
During Plan Phase Integration with /moai plan, after SPEC creation, enter the worktree through the launcher: moai cc -w <name> works inside it, and moai cc -w <name> --spawn opens it in a new tmux window.
During Development Phase with /moai run, worktree isolation provides a clean development environment with independent Git state preventing conflicts and automatic registry tracking.
During Sync Phase with /moai sync, before PR creation run the sync command for the SPEC. After PR merge, run the clean command with the merged-only flag to remove completed worktrees.
Auto-Detection Patterns:
The system detects worktree environments by checking for the registry file in the parent directory. When detected, the SPEC ID is extracted from the current directory name.
Configuration Integration:
The MoAI configuration supports worktree settings including auto_create for automatic worktree creation, auto_sync for automatic synchronization, cleanup_merged for automatic cleanup of merged branches, and worktree_root for specifying the worktree directory location with project name substitution.
Detailed Reference: Refer to Integration Patterns Module at modules/integration-patterns.md
--spawn — Launch a Teammate Session in a New tmux WindowPurpose: start a Claude or GLM session in a worktree without giving up the session you are in.
The launch commands (moai cc, moai glm) normally replace the running shell, which is right for "work here now" but cannot express "keep going and start a teammate alongside me". --spawn re-issues the same command in a new tmux window instead, then returns so the caller keeps working.
Combined with -w <name>, one command opens a teammate in an isolated worktree:
moai glm -w feat-auth --spawn # Explicit all-GLM session in .claude/worktrees/feat-auth
moai cc -w feat-auth --spawn # Claude teammate, same worktree
moai glm -w feat-auth --spawn # all-GLM teammateBehavior:
%7) is the handle for switching to it.-w <name> value resolves against .claude/worktrees/<name>/ (an existing tree of the same name under <MoaiHome>/worktrees/projects/<project-key> is re-entered).--spawn is consumed by MoAI and never reaches Claude Code. Tokens after the -- pass-through marker are left untouched.Requirements — each is refused with a clear error rather than a silent fallback, because falling back would replace the caller's session, the exact outcome --spawn exists to avoid:
| Missing | Message |
|---|---|
$TMUX (not inside a session) | tmux session required for --spawn |
tmux binary | --spawn requires the tmux binary |
moai binary in PATH | --spawn needs the moai binary in PATH |
No settings are mutated before these checks run, so a refusal leaves the environment untouched. The spawned command performs its own backend setup inside the new window.
Platform note: tmux is POSIX-only, so --spawn is unavailable on Windows and reports the missing binary. Entering a worktree in place with -w works on every platform.
Detailed Reference: the launcher's spawn entry point — flag stripping, command reconstruction with shell quoting, and the tmux window invocation.
moai worktree sync merges the base branch into the worktree by default; --strategy rebase rebases the worktree onto the base instead, and --base selects the base branch. When a sync stops on a conflict, resolve it with ordinary git inside the worktree and rerun the sync.
moai worktree has no shared or team registry mode, no per-developer prefixing, no selective sync patterns, no conflict auto-resolution or interactive mode, no worktree templates, and no shallow, background, parallel, or cache options. Prepare a worktree after entering it, and see modules/worktree-commands.md for the flags that exist.
Commands:
Skills:
Tools:
For new SPEC development, use the worktree isolation pattern with auto-setup. The primary approach is worktree isolation and the supporting pattern is integration with /moai plan.
For parallel development across multiple SPECs, use one worktree and one session per SPEC. The primary approach is maintaining multiple worktrees and the supporting pattern is opening each in its own tmux window with moai cc -w <name> --spawn.
For team coordination, give each developer their own worktrees and branches. The primary approach is per-developer isolation and the supporting pattern is integrating through the base branch and pull requests.
For code review workflows, use isolated review worktrees. The primary approach is worktree isolation for reviews and the supporting pattern is clean sync after review completion.
For experimental features, use temporary worktrees with auto-cleanup. The primary approach is creating temporary worktrees and the supporting pattern is safe experimentation with automatic removal.
Module Deep Dives:
Full Examples: Refer to references/examples.md External Resources: Refer to references/reference.md
| Rationalization | Reality |
|---|---|
| "Worktree isolation is overkill for this small change" | Small changes on main cause merge conflicts when parallel work is in progress. Worktrees prevent this. |
| "I will just work on the main branch, it is faster" | Working on main blocks other agents from writing. Worktrees enable parallelism. |
| "Read-only agents need worktree isolation too, for safety" | Isolation is unnecessary only for an agent whose tools list holds no tool that can write. The spawn-time mode parameter is deprecated and ignored, so it blocks nothing. Omitting Write, Edit, and NotebookEdit is not enough: Bash writes through the shell, and so can any other file-mutating tool (another shell, an MCP tool, or an Agent that spawns a writer). While any such tool is present, read-only is not guaranteed and isolation is not wasted. |
| "I can skip worktree cleanup, git handles it" | Stale worktree branches accumulate and confuse git worktree list. Always prune after use. |
| "Absolute paths in agent prompts are fine since the worktree has the same structure" | Absolute paths to the main repo bypass worktree isolation entirely. Use relative paths. |
git worktree list shows no stale worktrees after session endsmodu-ai/moai-adk
c4784db
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.