moai-worktree
关于
MoAI Worktree is a Git worktree management skill for developers working on parallel SPEC projects, creating isolated workspaces to prevent conflicts. It automatically registers new worktrees and integrates with the MoAI-ADK for seamless development. Use this skill when you need to develop multiple specifications concurrently without the overhead of context switching.
快速安装
Claude Code
推荐/plugin add https://github.com/modu-ai/moai-adkgit clone https://github.com/modu-ai/moai-adk.git ~/.claude/skills/moai-worktree在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
MoAI Worktree Management
Git 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.
Quick Reference (30 seconds)
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:
- Isolated Workspaces: Each SPEC gets its own worktree with independent Git state
- Automatic Registration: Worktree registry tracks all active workspaces
- Parallel Development: Multiple SPECs can be developed simultaneously
- Seamless Integration: Works with
/moai:1-plan,/moai:2-run,/moai:3-syncworkflow - Smart Synchronization: Automatic sync with base branch when needed
- Cleanup Automation: Automatic cleanup of merged worktrees
Quick Access:
- CLI commands → Worktree Commands Module
- Management patterns → Worktree Management Module
- Parallel workflow → Parallel Development Module
- Integration guide → Integration Patterns Module
- Troubleshooting → Troubleshooting Module
Use Cases:
- Multiple SPECs development in parallel
- Isolated testing environments
- Feature branch isolation
- Code review workflows
- Experimental feature development
Implementation Guide (5 minutes)
1. Core Architecture - Worktree Management System
Purpose: Create isolated Git worktrees for parallel SPEC development.
Key Components:
- Worktree Registry - Central registry tracking all worktrees
- Manager Layer - Core worktree operations (create, switch, remove, sync)
- CLI Interface - User-friendly command interface
- Models - Data structures for worktree metadata
- Integration Layer - MoAI-ADK workflow integration
Registry Structure:
{
"worktrees": {
"SPEC-001": {
"id": "SPEC-001",
"path": "/Users/goos/worktrees/MoAI-ADK/SPEC-001",
"branch": "feature/SPEC-001-user-auth",
"created_at": "2025-11-29T22:00:00Z",
"last_sync": "2025-11-29T22:30:00Z",
"status": "active",
"base_branch": "main"
}
},
"config": {
"worktree_root": "/Users/goos/worktrees/MoAI-ADK",
"auto_sync": true,
"cleanup_merged": true
}
}
File Structure:
~/worktrees/MoAI-ADK/
.moai-worktree-registry.json # Central registry
SPEC-001/ # Worktree directory
.git # Git worktree metadata
(project files) # Complete project copy
SPEC-002/ # Another worktree
.git
(project files)
Detailed Reference: Worktree Management Module
2. CLI Commands - Complete Command Interface
Purpose: Provide intuitive CLI commands for worktree management.
Core Commands:
# Create new worktree for SPEC
moai-worktree new SPEC-001 "User Authentication System"
# List all worktrees
moai-worktree list
# Switch to specific worktree
moai-worktree switch SPEC-001
# Get worktree path for shell integration
eval $(moai-worktree go SPEC-001)
# Sync worktree with base branch
moai-worktree sync SPEC-001
# Remove worktree
moai-worktree remove SPEC-001
# Clean up merged worktrees
moai-worktree clean
# Show worktree status
moai-worktree status
# Configuration management
moai-worktree config get
moai-worktree config set worktree_root ~/my-worktrees
Command Categories:
- Creation:
new- Create isolated worktree - Navigation:
list,switch,go- Browse and navigate - Management:
sync,remove,clean- Maintain worktrees - Status:
status- Check worktree state - Configuration:
config- Manage settings
Shell Integration:
# Direct switching
moai-worktree switch SPEC-001
# Shell eval pattern (recommended)
eval $(moai-worktree go SPEC-001)
# Output example:
# cd /Users/goos/worktrees/MoAI-ADK/SPEC-001
Detailed Reference: Worktree Commands Module
3. Parallel Development Workflow - Isolated SPEC Development
Purpose: Enable true parallel development without context switching.
Workflow Integration:
1. Plan Phase (/moai:1-plan):
SPEC creation
moai-worktree new SPEC-XXX
Automatic worktree setup
2. Development Phase:
Isolated worktree environment
Independent Git state
Zero context switching
3. Sync Phase (/moai:3-sync):
moai-worktree sync SPEC-XXX
Clean integration
Conflict resolution
4. Cleanup Phase:
moai-worktree clean
Automatic cleanup
Registry maintenance
Parallel Development Benefits:
- Context Isolation: Each SPEC has its own Git state, files, and environment
- Zero Switching Cost: Instant switching between worktrees
- Independent Development: Work on multiple SPECs simultaneously
- Safe Experimentation: Isolated environment for experimental features
- Clean Integration: Automatic sync and conflict resolution
Example Workflow:
# Create SPEC-001 worktree
moai-worktree new SPEC-001 "User Authentication"
cd $(moai-worktree go SPEC-001)
# Develop in isolation
/moai:2-run SPEC-001
# Create another worktree
cd /path/to/main/repo
moai-worktree new SPEC-002 "Payment Integration"
cd $(moai-worktree go SPEC-002)
# Parallel development on SPEC-002
/moai:2-run SPEC-002
# Switch back and continue
moai-worktree switch SPEC-001
# Continue development...
# Sync and integrate
moai-worktree sync SPEC-001
moai-worktree sync SPEC-002
Detailed Reference: Parallel Development Module
4. Integration Patterns - MoAI-ADK Workflow Integration
Purpose: Seamless integration with MoAI-ADK Plan-Run-Sync workflow.
Integration Points:
- Plan Phase Integration (
/moai:1-plan):
# After SPEC creation
moai-worktree new SPEC-{SPEC_ID}
# Output guidance
echo "1. Switch to worktree: moai-worktree switch SPEC-{SPEC_ID}"
echo "2. Or use shell eval: eval $(moai-worktree go SPEC-{SPEC_ID})"
- Development Phase (
/moai:2-run):
- Worktree isolation provides clean development environment
- Independent Git state prevents conflicts
- Automatic registry tracking
- Sync Phase (
/moai:3-sync):
# Before PR creation
moai-worktree sync SPEC-{SPEC_ID}
# After PR merge
moai-worktree clean --merged-only
Auto-Detection Patterns:
# Check if worktree environment
if [ -f "../.moai-worktree-registry.json" ]; then
SPEC_ID=$(basename $(pwd))
echo "Detected worktree environment: $SPEC_ID"
fi
# Auto-sync on status check
moai-worktree status
# Automatically syncs if out of date
Configuration Integration:
{
"moai": {
"worktree": {
"auto_create": true,
"auto_sync": true,
"cleanup_merged": true,
"worktree_root": "~/worktrees/{PROJECT_NAME}"
}
}
}
Detailed Reference: Integration Patterns Module
Advanced Implementation (10+ minutes)
Multi-Developer Worktree Coordination
Shared Worktree Registry:
# Team worktree configuration
moai-worktree config set registry_type team
moai-worktree config set shared_registry ~/team-worktrees/MoAI-ADK/
# Developer-specific worktrees
moai-worktree new SPEC-001 --developer alice
moai-worktree new SPEC-001 --developer bob
# Team coordination
moai-worktree list --all-developers
moai-worktree status --team-overview
Advanced Synchronization Strategies
Batch Synchronization: When developing multiple SPECs in parallel, use batch sync to keep all worktrees updated:
# Sync all worktrees with auto-resolve
moai-worktree sync --all --auto-resolve
# Daily best practice workflow
moai-worktree status # Check all worktree states
moai-worktree sync --all # Sync all (manual conflict resolution)
How batch sync works:
- Queries all active worktrees from the registry
- Performs git merge or git rebase from main branch for each worktree
- With
--auto-resolve: Automatically resolves simple conflicts (different regions of same file) - Complex conflicts: Skips that worktree and notifies user of manual intervention needed
Use cases: After large-scale refactoring, daily routine before work, weekly maintenance.
Selective Sync Patterns:
# Sync only specific files
moai-worktree sync SPEC-001 --include "src/"
# Exclude specific patterns
moai-worktree sync SPEC-001 --exclude "node_modules/"
# Auto-resolve conflicts
moai-worktree sync SPEC-001 --auto-resolve
# Interactive conflict resolution
moai-worktree sync SPEC-001 --resolve-interactive
Worktree Templates and Presets
Custom Worktree Templates:
# Create worktree with specific setup
moai-worktree new SPEC-001 --template frontend
# Includes: npm install, eslint setup, pre-commit hooks
moai-worktree new SPEC-002 --template backend
# Includes: virtual environment, test setup, database config
# Custom template configuration
moai-worktree config set templates.frontend.setup "npm install && npm run setup"
moai-worktree config set templates.backend.setup "python -m venv venv && source venv/bin/activate && pip install -r requirements.txt"
Performance Optimization
Optimized Worktree Operations:
# Fast worktree creation (shallow clone)
moai-worktree new SPEC-001 --shallow --depth 1
# Background sync
moai-worktree sync SPEC-001 --background
# Parallel operations
moai-worktree sync --all --parallel
# Caching for faster operations
moai-worktree config set enable_cache true
moai-worktree config set cache_ttl 3600
Works Well With
Commands:
- moai:1-plan - SPEC creation with automatic worktree setup
- moai:2-run - Development in isolated worktree environment
- moai:3-sync - Integration with automatic worktree sync
- moai:9-feedback - Worktree workflow improvements
Skills:
- moai-foundation-core - Parallel development patterns
- moai-workflow-project - Project management integration
- moai-workflow-spec - SPEC-driven development
- moai-git-strategy - Git workflow optimization
Tools:
- Git worktree - Native Git worktree functionality
- Rich CLI - Formatted terminal output
- Click framework - Command-line interface framework
Quick Decision Matrix
| Scenario | Primary Pattern | Supporting |
|---|---|---|
| New SPEC development | Worktree isolation + Auto-setup | Integration with /moai:1-plan |
| Parallel development | Multiple worktrees + Shell integration | Fast switching patterns |
| Team coordination | Shared registry + Developer prefixes | Conflict resolution |
| Code review | Isolated review worktrees | Clean sync patterns |
| Experimental features | Temporary worktrees + Auto-cleanup | Safe experimentation |
Module Deep Dives:
- Worktree Commands - Complete CLI reference
- Worktree Management - Core architecture
- Parallel Development - Workflow patterns
- Integration Patterns - MoAI-ADK integration
- Troubleshooting - Problem resolution
Full Examples: examples.md External Resources: reference.md
Version: 1.0.0 Last Updated: 2025-11-29 Status: Active (Complete modular architecture)
GitHub 仓库
相关推荐技能
network-security-setup
开发这个Skill帮助开发者配置Claude Code沙箱的网络隔离策略,特别适用于需要控制外部访问的企业安全场景。它支持设置可信域名白名单、自定义访问策略和安全环境变量管理。关键能力包括防止提示注入攻击、配置企业代理和内部注册表,确保代码执行环境的安全隔离。
swarm-advanced
其他该Skill提供高级群组协调模式,用于研究、开发和测试等复杂分布式工作流。它支持网状拓扑等协调策略,可通过MCP工具或CLI命令创建和管理多个智能体。开发者能快速初始化群组、生成专业化智能体并协调分布式任务执行。
swarm-advanced
其他该Skill为开发者提供高级群组协调模式,用于分布式研究、开发和测试工作流。它支持通过MCP工具和CLI命令初始化群组拓扑、生成专业代理并协调复杂任务。适用于需要并行处理和分布式协调的研发场景,可快速搭建多代理协作系统。
feature-dev-complete
元该Skill为开发者提供从需求分析到部署上线的完整功能开发生命周期支持,通过多模型协同实现架构设计、原型开发、测试和文档生成。它特别适用于需要快速启动新功能项目并确保最佳实践的开发场景。关键能力包括利用Gemini进行技术研究、Codex快速原型迭代以及自动生成部署就绪的代码和文档。
