2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Claude Codeで並列開発を実現する!git worktreeの活用術

Last updated at Posted at 2025-08-12

こんにちは!Rimoでバックエンド開発をしています。

最近Claude Code(Anthropic公式のCLIツール)を使い始めたのですが、複数のブランチで並列開発したい時に困ったことがありました。今回はその解決策として採用したgit worktreeの活用方法を紹介します。

これを活用することで、以下のように並列開発が可能になり、統合役がそれぞれの状況も含め確認できるようになります。

image.png

🤔 背景:Claude Codeの制約

Claude Codeは素晴らしいツールなのですが、セキュリティの観点から親ディレクトリ(..)にアクセスできないという制約があります。

通常、git worktreeを使う場合はこんな感じで親ディレクトリに作成しますよね:

# 通常のworktreeの使い方(Claude Codeでは使えない)
cd ~/projects/my-app
git worktree add ../my-app-feature-x feature-x

でも、Claude Codeでは ../ にアクセスできないので、この方法は使えません。

💡 解決策:サブディレクトリとして作成する

そこで、メインリポジトリのサブディレクトリとしてworktreeを作成することにしました!

# Claude Code対応版
git worktree add wt-feature-x feature-x

これなら Claude Code でも問題なくアクセスできます。

📝 実装方法

1. .gitignoreに追加

まず、worktreeディレクトリがgitに認識されないよう、.gitignoreに追加します:

# Git worktree directories
/wt-*

2. 命名規則を決める

チームで混乱しないよう、worktreeディレクトリは必ず wt- プレフィックスを付けることにしました。

ブランチ名に / が含まれる場合は、そのままディレクトリ構造として保持します:

# ブランチ名: awakia/speaker_hint
git worktree add wt-awakia/speaker_hint awakia/speaker_hint

# ブランチ名: feat/8838-add-keep-filler-option  
git worktree add wt-feat/8838-add-keep-filler-option feat/8838-add-keep-filler-option

3. ドキュメント化

CLAUDE.md(Claude Code用の設定ファイル)に使用方法を記載:

## Git Worktree Usage

For parallel development with Claude Code, use git worktree with the following naming convention.

**Note**: Normally, git worktrees are created in a parent directory (e.g., `../repository-name-feature-name`), 
but due to Claude Code's restriction of not being able to access parent directories (`..`), 
we create worktrees as subdirectories within the main repository instead.

# Example:
git worktree add wt-awakia/speaker_hint awakia/speaker_hint
git worktree add wt-feat/8838-add-keep-filler-option feat/8838-add-keep-filler-option

# Remove a worktree
git worktree remove wt-awakia/speaker_hint

🎯 メリット

  1. Claude Codeで複数ブランチの並列開発が可能に

    • コンテキストスイッチなしで複数の作業を進められる
  2. タブ補完が使いやすい

    • wt-awakia/ まで打てば、その人のブランチ一覧が出てくる
  3. gitの管理から除外される

    • .gitignoreで無視されるので、メインリポジトリに影響なし

🚀 使ってみよう!

実際の使用例:

# 新機能の開発
git worktree add wt-awakia/new-feature awakia/new-feature
cd wt-awakia/new-feature
# Claude Codeで開発...

# バグ修正を並行して行う必要が出てきた
cd ../..  # メインリポジトリに戻る
git worktree add wt-awakia/urgent-bugfix awakia/urgent-bugfix
cd wt-awakia/urgent-bugfix
# バグ修正...

# 作業が終わったら削除
git worktree remove wt-awakia/urgent-bugfix

📌 注意点

  • worktreeディレクトリは必ず wt- で始める
  • 作業が終わったら git worktree remove で削除する
  • .gitignoreへの追加を忘れずに!

まとめ

Claude Codeの制約を回避しつつ、git worktreeの利便性を活かす方法を紹介しました。この方法なら、AIアシスタントと一緒に効率的な並列開発ができます!

皆さんの開発環境でも、ツールの制約に合わせた工夫があれば、ぜひ教えてください!


関連リンク

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?