tags : git, Claude Code

概要

Git worktree 管理用 CLI(Rust製、作者: max-sixty)。 AI エージェント(Claude Code等)の並列実行ワークフローに最適化されている。 git worktree の UX を改善するラッパーで、作成・一覧・削除・状態表示を簡単にする。

設定

~/.config/worktrunk/config.toml で管理(dotfiles で stow 管理)。

worktree-path

worktree-path = " repo_path }}/.worktrees/{{ branch | sanitize "
  • ghq 環境向け: リポジトリ内の .worktrees/ に隠すことで ghq の階層構造を汚さない
  • branch | sanitize/- に変換(feature/auth → feature-auth)
  • ブランチ名自体は feature/auth のまま git に保存される

post-create hook

[post-create]
mise = "mise trust"

worktree は物理的に別ディレクトリなので、元リポジトリで mise trust 済みでも未信頼扱いになる。 worktree 作成時に自動で mise trust を実行して解消する。

merge 設定

PR ベース運用なら不要(GitHub/GitLab 側でマージ戦略制御)。 git-flow 流にする場合は squash = false, ff = false を設定する。

gitignore

.worktrees/ は git worktree の中身は無視するが、ディレクトリ自体は untracked に出る。

  • グローバル gitignore(=~/.config/git/ignore=)に .worktrees/ を追加して対処
  • core.excludesFile は未設定にして git デフォルトの ~/.config/git/ignore を使う

ripgrep 除外

~/.config/ripgrep/config--glob!.worktrees/= を設定。 RIPGREP_CONFIG_PATH”$HOME/.config/ripgrep/config”= を .zshrc に設定。

Claude Code 連携

プラグイン

wt config plugins claude install

提供機能:

  1. Configuration Skill: worktrunk 関連の質問に自動対応
  2. Worktree Isolation: EnterWorktree が wt switch --create を使うようになる
  3. Activity Tracking: wt list に 🤖(処理中)💬(入力待ち)を表示

Claude Code での worktree フロー

ユーザーが「worktree で feature/xxx を作って作業して」と指示すると、 Claude Code が EnterWorktree → 作業 → ExitWorktree まで実行する。 プラグインにより裏で worktrunk が使われ .worktrees/ に作成される。 プラグインなしの場合は .claude/worktrees/ に作成(フォールバック)。

CLAUDE.md への記述

  • 「worktree で作成し、そこに移動する」を第一選択に
  • 「worktree が使えない場合は =git switch -c=」をフォールバックに
  • wt や特定のパスには言及しない(プラグインの有無に依存しないように)

マージフロー

  • PR ベース: push → PR/MR 作成 → マージ → wt remove
  • ローカル: wt switch developgit merge --no-ff feature/xxxwt remove
  • Claude Code には「worktree を develop にマージして」と指示

主要コマンド

やることコマンド
worktree 作成+移動wt switch -c feature/xxx
既存 worktree に移動wt switch feature/xxx
一覧(CI/差分/Claude状態)wt list --full
worktree+ブランチ削除wt remove feature/xxx
マージ済み一括削除wt step prune
PR ブランチにジャンプwt switch pr:123

インストール

brew install worktrunk
wt config shell install          # シェル補完・初期化
wt config plugins claude install # Claude Code プラグイン