sc-worktree について
並行したエージェント開発向けに、Git worktreeを独立した作業場所として管理するスキルです。作成、状態確認、変更の提案、削除を支援し、自動マージは行わず人によるレビューに委ねます。
主な機能
- 01独立したworktreeとブランチの作成
- 02状態確認と競合検出
- 03サブエージェントのworktreeへの割り当て
- 04人によるレビューに向けた変更提案
- 05古いworktreeの削除
活用シーン
- 01複数のエージェントで別々のタスクを並行実行
- 02プルリクエストレビュー用のブランチ準備
- 03直接コミットせずにパッチを作成
MCP 対応
提案前の検証、コードレビュー、競合対応の助言にはPAL MCPツールを利用できます。Rube MCPツールによるプルリクエスト作成やチーム通知も説明されています。
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ tony363/ superclaude --skill sc-worktreeインストール後、Claude Code で/sc-worktreeを入力して読み込まれたか確認します。
詳細
Worktree 管理スキル
並行エージェント開発のための Git worktree 分離と、シンプルで安全なワークフローです。
クイックスタート
# Create isolated worktree for a task
/sc:worktree create feature-auth
# List all active worktrees
/sc:worktree list
# Propose changes for human review
/sc:worktree propose feature-auth
# Clean up stale worktrees
/sc:worktree cleanup
動作フロー
- 作成 - 一意の名前を付けて分離された worktree を初期化します
- 検証 - 事前チェックを行います(リポジトリがクリーンであること、競合がないこと)
- 割り当て - CWD を worktree に設定してサブエージェントを起動します
- 作業 - エージェントは分離環境で作業し、ブランチにコミットします
- 提案 - ブランチをプッシュし、人間によるレビュー用の PR を作成します
- クリーンアップ - マージ済みまたは古い worktree を削除します
コマンド
| コマンド | 目的 | Git 操作 |
|---|---|---|
create <task-id> | 分離された worktree を作成 | git worktree add -b wt/<task> |
list | すべてのアクティブな worktree を表示 | git worktree list |
status <task-id> | worktree の状態を確認 | git status、git log |
cleanup [--all] | 古い worktree を削除 | git worktree remove、prune |
propose <task-id> | 人間によるレビュー用の PR を作成 | git push、gh pr create |
フラグ
| フラグ | 型 | デフォルト | 説明 |
|---|---|---|---|
--commits | bool | true | エージェントがブランチに直接コミットします |
--patches | bool | false | エージェントはパッチファイルのみを生成します |
--run-tests | bool | false | 提案前にテストを実行します |
--force | bool | false | 既存の worktree/ブランチを上書きします |
--base | string | main | worktree のベースブランチ |
証拠要件
このスキルでは、厳密な証拠は必要ありません。worktree 操作は次の内容から自動的に記録されます。
- Git worktree の一覧出力
- ブランチの履歴
- PR 作成の確認
命名規則
競合を防ぐため、worktree には決定的な命名規則を使用します。
Path: .worktrees/<task-id>/
Branch: wt/<task-id>
例:
Path: .worktrees/feature-auth/
Branch: wt/feature-auth
操作
Worktree の作成
/sc:worktree create feature-auth
# Executes:
# 1. mkdir -p .worktrees
# 2. git worktree add -b wt/feature-auth .worktrees/feature-auth
# 3. Returns worktree path for subagent CWD
Worktree の一覧表示
/sc:worktree list
# Shows:
# - Active worktrees
# - Associated branches
# - Last commit info
ステータスの確認
/sc:worktree status feature-auth
# Shows:
# - Uncommitted changes
# - Commits ahead of base branch
# - Conflict warnings
変更の提案
/sc:worktree propose feature-auth
# Executes:
# 1. git push -u origin wt/feature-auth
# 2. gh pr create --title "feat: feature-auth" --body "..."
# 3. Returns PR URL for human review
Worktree のクリーンアップ
/sc:worktree cleanup # Remove merged worktrees
/sc:worktree cleanup --all # Remove ALL worktrees
/sc:worktree cleanup feature-auth # Remove specific worktree
# Executes:
# 1. git worktree remove .worktrees/<task-id>
# 2. git branch -d wt/<task-id>
# 3. git worktree prune
サブエージェントとの連携
worktree で作業するサブエージェントを起動する場合:
# 1. Create worktree
/sc:worktree create feature-auth
# 2. Spawn subagent with CWD
Task(
prompt="Implement JWT authentication",
subagent_type="general-purpose",
# CWD implicitly set to .worktrees/feature-auth/
)
# 3. Agent works in isolation
# - All file operations scoped to worktree
# - Commits go to wt/feature-auth branch
# 4. Propose for review
/sc:worktree propose feature-auth
事前チェック
worktree を作成する前に、このスキルは次の項目を検証します。
-
リポジトリの状態
- リポジトリがクリーンであるか、
--forceフラグが指定されている - メインブランチが最新である
- リポジトリがクリーンであるか、
-
ブランチの利用可否
wt/<task-id>ブランチが存在しないか、明示的に再利用する- 競合するリモートブランチがない
-
パスの利用可否
.worktrees/<task-id>が存在しないか、--forceフラグが指定されている
競合の検出
提案する前に、このスキルは競合を確認します。
# Fetch latest changes
git fetch origin main
# Check if worktree is behind
git merge-base --is-ancestor origin/main HEAD
# Warn but don't block if behind
# Human reviewer handles merge strategy
例
単一エージェントのワークフロー
# Create worktree
/sc:worktree create add-logging
# Work in worktree (agent operates here)
# ... agent makes changes, commits ...
# Propose changes
/sc:worktree propose add-logging
# Human reviews PR, merges
# Cleanup
/sc:worktree cleanup add-logging
複数エージェントの並行ワークフロー
# Orchestrator creates multiple worktrees
/sc:worktree create feature-auth
/sc:worktree create feature-logging
/sc:worktree create feature-metrics
# Spawn agents in parallel (each with own worktree)
# Agent A -> .worktrees/feature-auth/
# Agent B -> .worktrees/feature-logging/
# Agent C -> .worktrees/feature-metrics/
# Propose all changes
/sc:worktree propose feature-auth
/sc:worktree propose feature-logging
/sc:worktree propose feature-metrics
# Human reviews 3 PRs, merges sequentially
# Cleanup all
/sc:worktree cleanup --all
パッチモード(直接コミットしない場合)
/sc:worktree create refactor-api --patches
# Agent produces .patch files instead of commits
# Orchestrator reviews patches before applying
/sc:worktree propose refactor-api # Creates PR from patches
MCP 連携
PAL MCP(検証とレビュー)
| ツール | 使用するタイミング | 目的 |
|---|---|---|
mcp__pal__precommit | 提案前 | worktree 内の変更を検証 |
mcp__pal__codereview | 提案前 | worktree の変更をレビュー |
mcp__pal__consensus | 競合の解決 | 複数モデルによるマージ戦略 |
PAL の使用パターン
# Validate worktree changes before proposing
mcp__pal__precommit(
path=".worktrees/feature-auth",
step="Validating worktree changes",
findings="Security, test coverage, completeness",
compare_to="main"
)
# Review worktree branch
mcp__pal__codereview(
review_type="full",
step="Reviewing feature-auth worktree",
relevant_files=[".worktrees/feature-auth/src/auth.py"]
)
Rube MCP(自動化と通知)
| ツール | 使用するタイミング | 目的 |
|---|---|---|
mcp__rube__RUBE_SEARCH_TOOLS | GitHub 連携 | PR ツールを検索 |
mcp__rube__RUBE_MULTI_EXECUTE_TOOL | 提案コマンド | PR を作成し、チームに通知 |
Rube の使用パターン
# Create PR and notify team
mcp__rube__RUBE_MULTI_EXECUTE_TOOL(tools=[
{"tool_slug": "GITHUB_CREATE_PULL_REQUEST", "arguments": {
"repo": "myapp",
"title": "feat: feature-auth from worktree",
"body": "## Worktree: feature-auth\nCreated via /sc:worktree",
"base": "main",
"head": "wt/feature-auth"
}},
{"tool_slug": "SLACK_SEND_MESSAGE", "arguments": {
"channel": "#pull-requests",
"text": "New PR from worktree: wt/feature-auth"
}}
])
フラグ(拡張)
| フラグ | 型 | デフォルト | 説明 |
|---|---|---|---|
--pal-review | bool | false | 提案前に PAL codereview を使用 |
--create-pr | bool | true | Rube 経由で GitHub PR を作成 |
--notify | string | - | Rube 経由で通知(slack、teams) |
--draft | bool | false | ドラフト PR を作成 |
ツールの連携
- Bash - Git worktree コマンド、ディレクトリ操作
- Read - worktree のステータスとログを確認
- Task - worktree の CWD を設定してサブエージェントを起動
- PAL MCP - 提案前の検証、コードレビュー
- Rube MCP - PR の作成、チームへの通知
安全性の保証
- 分離 - 各 worktree には個別の作業ディレクトリがあります
- 自動マージなし - すべてのマージで人間によるレビューが必要です
- 一意の命名 - 決定論的なパスにより衝突を防ぎます
- クラッシュセーフ -
cleanup --allですべての古い worktree を削除します - 警告のみの競合 - 競合が発生しても警告するだけで、処理はブロックされません
制限事項
- 品質の自動スコアリングには対応していません(CI/テストを使用してください)
- リースの追跡には対応していません(代わりに定期的にクリーンアップします)
- 高度な競合解決には対応していません(人間によるレビューが必要です)
- main への自動マージには対応していません(PR ベースのワークフローです)
コメント
Markdown 対応