git worktreeとClaude Codeを組み合わせた並列開発の始め方
2025/9/15
git worktree Claude Code
AnthropicのClaude Codeワークフローのドキュメントに、git worktreeを使ってClaude Codeセッションを並列に実行する例があったため、git worktreeの勉強がてらClaude Codeによる並列開発のやり方を学んでいく。
git worktree
まずはgit worktreeについて軽くインプットする。
https://git-scm.com/docs/git-worktree
git worktreeを使うと、同じリポジトリ内で複数のworking treeを管理できる。working tree同士は互いに干渉しないため、それぞれで開発を進められる。
add - working treeの追加
git worktreeに続いてaddコマンドを使用すると、新しいworking treeを作成できる。
git worktree add <path> [<commit-ish>]
<path>
: 新しいworking treeを作成する場所
<commit-ish>
: コミットやブランチをチェックアウト
動きとしては、指定した<path>
に新しいworking treeを作成し、<commit-ish>
のブランチやコミットをチェックアウトする。
-b オプションでブランチを指定するとそのブランチを新しく作成してそこにチェックアウトする。
list - working treeの表示
現在のworking treeを表示する。
git worktree list
/sandbox/git-worktree-sample e6a2183 [main]
/sandbox/feature-a e6a2183 [feature-a]
remove - working treeの削除
指定したworking treeを削除する。
git worktree remove ../feature-a
git worktreeとClaude Codeを組み合わせて使う
やり方は簡単で以下の2ステップ
- git worktree add コマンドを使ってworking treeを追加する
- working treeがあるディレクトリに移動してClaudeコマンドを実行
例えば、feature-aの開発とfeature-bの開発を並列で行いたい場合 以下のようにしてworking treeを追加
# feature-aのworking treeを作成
git worktree add ../feature-a -b feature-a
# feature-bのworking treeを作成
git worktree add ../feature-b -b feature-b
それぞれのディレクトリでClaudeコマンドを実行
cd ../feature-a && claude
# 別のターミナルを起動
cd ../feature-b && claude