<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">
  <channel>
    <title>Parallel Development · 仁才徳</title>
    <link>https://jared.lynskey.co.nz/ja/tags/parallel-development/</link>
    <description>ソフトウェアエンジニアリングと開発組織のリーダーシップについて。評価、採用とチームの拡大、CI/CD、DevOps モニタリング、エージェンティック AI。ソウルより。</description>
    <generator>Hugo</generator>
    <language>ja</language>
    <copyright>© 2026 仁才徳</copyright>
    <lastBuildDate>Thu, 19 Nov 2026 00:00:00 +1300</lastBuildDate>
    <atom:link href="https://jared.lynskey.co.nz/ja/tags/parallel-development/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Claude Codeのworktreeの使い方：並列エージェントを衝突させずに動かす</title>
      <link>https://jared.lynskey.co.nz/ja/posts/2026/claude-code-git-worktrees/</link>
      <guid isPermaLink="true">https://jared.lynskey.co.nz/ja/posts/2026/claude-code-git-worktrees/</guid>
      <pubDate>Thu, 19 Nov 2026 00:00:00 +1300</pubDate>
      <dc:creator>Jared Lynskey</dc:creator>
      <category>Claude Code</category>
      <category>AI Agents</category>
      <category>Git</category>
      <category>Git Worktree</category>
      <category>tmux</category>
      <category>Developer Tools</category>
      <category>Parallel Development</category>
      <description>Claude Codeのworktreeの使い方。claude -w の動き、.worktreeincludeで.envを持ち込む方法、node_modulesの扱い、base ref、後片付け、tmuxで複数のエージェントを並列に動かすコツまで。</description>
      <content:encoded><![CDATA[<p>Claude Codeをgitのworktreeで動かすには、<code>claude -w &lt;名前&gt;</code>（長い形は<code>--worktree</code>）で起動します。Claude Codeはリポジトリのルートに<code>.claude/worktrees/&lt;名前&gt;/</code>を作り、リモートのデフォルトブランチから切った<code>worktree-&lt;名前&gt;</code>という新しいブランチをそこにチェックアウトします。以後、そのセッションが編集できるのはこのフォルダの中だけです。別のターミナルで名前を変えて同じコマンドを打てば、お互いのファイルに手を出せないエージェントが2つ並びます。ただし落とし穴があって、worktreeは真っさらなチェックアウトです。<code>.env</code>も<code>node_modules</code>も、gitが無視しているものは、自分でコピーかインストールをするまで存在しません。私がworktreeでつまずいたのは、ほぼ全部これが原因でした。</p>
<p>私はふだんから多くのエージェントを並列で動かしていて、worktreeには痛い目を見てからたどり着きました。この記事では、<code>claude -w</code>の動き（バージョン2.1.328で確認）、<code>.worktreeinclude</code>の役割、<code>node_modules</code>をどうするか、tmuxでのセッションの並べ方、そして今でも素の<code>git worktree add</code>を使う場面をまとめます。</p>
<figure><div class="film-pair">
  <div class="mc-film film-dark">
  <video
    class="my-0 rounded-md"
    controls playsinline preload="none"
    poster="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film-poster.jpg" style="background:url('data:image/webp;base64,UklGRoQAAABXRUJQVlA4IHgAAABwBQCdASogABIAPw1wq0omIyGYDAQAYxDE9IBn0BuOmrQv+whr1JowkP2GvdEWiylHGHsAAP7r1B494gmKZxYarGSLJSBCQLucUwJnafSMMs2DcN8Xi7b7w/dBQJDESVxNVTjZ96FIOv3VtbbF3xp3++/ULAEhgAA=') center/cover no-repeat"
    width="1280"
    height="720"
    aria-label="この記事を語りで紹介する短い映像">
    <source src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film.webm" type="video/webm">
    <track kind="subtitles" src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film_en.vtt" srclang="en" label="English">
    <track kind="subtitles" src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film_ja.vtt" srclang="ja" label="日本語" default>
    <track kind="subtitles" src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film_ko.vtt" srclang="ko" label="한국어">
    <track kind="subtitles" src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film_vi.vtt" srclang="vi" label="Tiếng Việt">
    <track kind="subtitles" src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film_zh-cn.vtt" srclang="zh-cn" label="简体中文">
  </video>
  </div>
  <div class="mc-film film-light">
  <video
    class="my-0 rounded-md"
    controls playsinline preload="none"
    poster="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film-light-poster.jpg" style="background:url('data:image/webp;base64,UklGRoIAAABXRUJQVlA4IHYAAADQBACdASogABIAPw1uqUemIyIYBABjEMT0gAc4DbW6V3D/YCrZgv8AsVgfEQtYAAD+77ncv/xfKWHnvcUR0S+hsPg7hFdUPAZo9hZKq5p8p/3q6SK+cmbz04KNDvyW45u0Ws/43dQYB5jO2XsnWh2nnV30wAAA') center/cover no-repeat"
    width="1280"
    height="720"
    aria-label="この記事を語りで紹介する短い映像">
    <source src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film-light.webm" type="video/webm">
    <track kind="subtitles" src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film_en.vtt" srclang="en" label="English">
    <track kind="subtitles" src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film_ja.vtt" srclang="ja" label="日本語" default>
    <track kind="subtitles" src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film_ko.vtt" srclang="ko" label="한국어">
    <track kind="subtitles" src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film_vi.vtt" srclang="vi" label="Tiếng Việt">
    <track kind="subtitles" src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktrees-film_zh-cn.vtt" srclang="zh-cn" label="简体中文">
  </video>
  </div>
  <script>(function(){if(window.mcFilm)return window.mcFilm();var a={play:'<path d="M8 5.6v12.8a1 1 0 0 0 1.52.85l10.2-6.4a1 1 0 0 0 0-1.7L9.52 4.75A1 1 0 0 0 8 5.6z"/>',pause:'<rect x="6.5" y="5" width="4" height="14" rx="1.2"/><rect x="13.5" y="5" width="4" height="14" rx="1.2"/>',volume:'<path d="M4 9.5v5a1 1 0 0 0 1 1h3l4.4 3.6a.6.6 0 0 0 1-.47V5.37a.6.6 0 0 0-1-.47L8 8.5H5a1 1 0 0 0-1 1z"/><path d="M16.5 8.5a5 5 0 0 1 0 7M19 6a8.5 8.5 0 0 1 0 12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>',muted:'<path d="M4 9.5v5a1 1 0 0 0 1 1h3l4.4 3.6a.6.6 0 0 0 1-.47V5.37a.6.6 0 0 0-1-.47L8 8.5H5a1 1 0 0 0-1 1z"/><path d="M16.5 9.5l5 5m0-5l-5 5" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>',cc:'<rect x="3" y="5.5" width="18" height="13" rx="3" fill="none" stroke="currentColor" stroke-width="1.8"/><path d="M10.5 10.3a2.2 2.2 0 1 0 0 3.4M17 10.3a2.2 2.2 0 1 0 0 3.4" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/>',full:'<path d="M4.5 9V5.5a1 1 0 0 1 1-1H9M15 4.5h3.5a1 1 0 0 1 1 1V9M19.5 15v3.5a1 1 0 0 1-1 1H15M9 19.5H5.5a1 1 0 0 1-1-1V15" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/>',exit:'<path d="M9 4.5V8a1 1 0 0 1-1 1H4.5M19.5 9H16a1 1 0 0 1-1-1V4.5M15 19.5V16a1 1 0 0 1 1-1h3.5M4.5 15H8a1 1 0 0 1 1 1v3.5" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/>'},s={en:["Play","Pause","Mute","Unmute","Subtitles","Off","Full screen","Exit full screen","Seek"],ko:["재생","일시정지","음소거","음소거 해제","자막","끄기","전체 화면","전체 화면 종료","탐색"],ja:["再生","一時停止","ミュート","ミュート解除","字幕","オフ","全画面","全画面を終了","シーク"],zh:["播放","暂停","静音","取消静音","字幕","关闭","全屏","退出全屏","进度"],vi:["Phát","Tạm dừng","Tắt tiếng","Bật tiếng","Phụ đề","Tắt","Toàn màn hình","Thoát toàn màn hình","Tua"]},r=(document.documentElement.lang||"en").toLowerCase().slice(0,2),e=s[r]||s.en,t=function(e){return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">'+a[e]+"</svg>"},o={},i=function(e,t){if(o[e]||typeof window.gtag!="function")return;o[e]=!0;var n=(t.currentSrc||(t.querySelector("source")||{}).src||"").split("/").pop();window.gtag("event",e,{film:n.replace(/-light(?=\.)/,"")})},n=function(e){(!isFinite(e)||e<0)&&(e=0),e=Math.floor(e);var t=Math.floor(e/3600),n=Math.floor(e%3600/60),s=String(e%60).padStart(2,"0");return t?t+":"+String(n).padStart(2,"0")+":"+s:n+":"+s};function c(s){var a,r,c,d,u,m,p,g,v,b,j,_,w,O,C,E,k,A,o=s.querySelector("video");if(!o)return;s.classList.add("is-ready"),o.controls=!1,o.removeAttribute("controls"),s.insertAdjacentHTML("beforeend",'<button type="button" class="mc-film__big" aria-label="'+e[0]+'">'+t("play")+'</button><div class="mc-film__bar"><button type="button" class="mc-film__btn" data-act="play" aria-label="'+e[0]+'">'+t("play")+'</button><span class="mc-film__time"><span data-cur>0:00</span><span class="mc-film__of"> / </span><span data-dur>0:00</span></span><input class="mc-film__seek" type="range" min="0" max="1000" step="1" value="0" aria-label="'+e[8]+'"><span class="mc-film__cc"><button type="button" class="mc-film__btn" data-act="cc" aria-label="'+e[4]+'" aria-haspopup="true" aria-expanded="false">'+t("cc")+'</button><span class="mc-film__menu" role="menu" hidden></span></span><button type="button" class="mc-film__btn" data-act="mute" aria-label="'+e[2]+'">'+t("volume")+'</button><button type="button" class="mc-film__btn" data-act="full" aria-label="'+e[6]+'">'+t("full")+"</button></div>"),A=s.querySelector(".mc-film__big"),a=s.querySelector(".mc-film__bar"),j=a.querySelector('[data-act="play"]'),p=a.querySelector('[data-act="mute"]'),u=a.querySelector('[data-act="full"]'),d=a.querySelector('[data-act="cc"]'),r=a.querySelector(".mc-film__menu"),c=a.querySelector(".mc-film__seek"),w=a.querySelector("[data-cur]"),O=a.querySelector("[data-dur]"),g=!1,v=0,b=function(){return Array.prototype.filter.call(o.textTracks,function(e){return e.kind==="subtitles"||e.kind==="captions"})},b().length||(d.parentNode.hidden=!0),_=null;function f(e){var n,i,t=!s.classList.contains("is-idle")&&s.classList.contains("is-started");if(e!==!0&&t===_)return;_=t,n=o.clientHeight,i=n?Math.max(40,100-(a.offsetHeight+22)/n*100):85,b().forEach(function(e){if(e.mode!=="showing"||!e.cues)return;for(var n,s=0;s<e.cues.length;s++)n=e.cues[s],t?(n.snapToLines=!1,n.line=i,n.lineAlign="end"):(n.snapToLines=!0,n.line="auto",n.lineAlign="start")})}m=function(){f(!0)},window.addEventListener("resize",m),Array.prototype.forEach.call(o.querySelectorAll("track"),function(e){e.addEventListener("load",m)});function y(){o.paused||o.ended?o.play().catch(function(){}):o.pause()}function l(){s.classList.remove("is-idle"),f(),clearTimeout(v),v=setTimeout(function(){!o.paused&&r.hidden&&!a.querySelector(":focus-visible")&&(s.classList.add("is-idle"),f())},2600)}function M(){clearTimeout(v),h(),s.classList.add("is-idle"),f()}function h(){r.hidden=!0,d.setAttribute("aria-expanded","false")}function F(){var t=b(),n=t.filter(function(e){return e.mode==="showing"})[0];r.innerHTML="",[null].concat(t).forEach(function(s){var o=document.createElement("button");o.type="button",o.setAttribute("role","menuitemradio"),o.setAttribute("aria-checked",String(s?s===n:!n)),o.textContent=s?s.label||s.language:e[5],o.addEventListener("click",function(){t.forEach(function(e){e.mode=e===s?"showing":"disabled"}),h(),setTimeout(m,0),l()}),r.appendChild(o)}),r.hidden=!1,d.setAttribute("aria-expanded","true")}function x(){var n=!o.paused&&!o.ended;s.classList.toggle("is-playing",n),j.innerHTML=t(n?"pause":"play"),j.setAttribute("aria-label",n?e[1]:e[0]),n||l()}function S(){if(w.textContent=n(o.currentTime),!g&&o.duration){var e=o.currentTime/o.duration*1e3;c.value=e,c.style.setProperty("--p",e/10+"%")}}A.addEventListener("click",function(){o.play().catch(function(){})}),C="mouse",s.addEventListener("pointerdown",function(e){C=e.pointerType}),o.addEventListener("click",function(){if(!s.classList.contains("is-started"))return o.play().catch(function(){});if(C==="mouse")return y();s.classList.contains("is-idle")?l():M()}),j.addEventListener("click",y),o.addEventListener("play",function(){s.classList.contains("is-started")||i("film_play",o),s.classList.add("is-started"),x(),l()}),"IntersectionObserver"in window&&(E=new IntersectionObserver(function(e){if(!e.some(function(e){return e.isIntersecting}))return;E.disconnect(),i("film_view",o)},{threshold:.5}),E.observe(s)),o.addEventListener("pause",x),o.addEventListener("ended",x),o.addEventListener("timeupdate",S),o.addEventListener("durationchange",function(){O.textContent=n(o.duration),S()}),o.addEventListener("loadedmetadata",function(){O.textContent=n(o.duration)}),o.addEventListener("volumechange",function(){p.innerHTML=t(o.muted?"muted":"volume"),p.setAttribute("aria-label",o.muted?e[3]:e[2])}),p.addEventListener("click",function(){o.muted=!o.muted}),c.addEventListener("input",function(){g=!0,c.style.setProperty("--p",c.value/10+"%"),o.duration&&(o.currentTime=c.value/1e3*o.duration,w.textContent=n(o.currentTime))}),c.addEventListener("change",function(){g=!1}),d.addEventListener("click",function(e){e.stopPropagation(),r.hidden?F():h()}),document.addEventListener("click",function(e){!r.hidden&&!r.contains(e.target)&&h()}),u.addEventListener("click",function(){document.fullscreenElement||document.webkitFullscreenElement?(document.exitFullscreen||document.webkitExitFullscreen).call(document):s.requestFullscreen?s.requestFullscreen().catch(function(){}):s.webkitRequestFullscreen?s.webkitRequestFullscreen():o.webkitEnterFullscreen&&o.webkitEnterFullscreen()}),k=function(){var n=(document.fullscreenElement||document.webkitFullscreenElement)===s;s.classList.toggle("is-fullscreen",n),u.innerHTML=t(n?"exit":"full"),u.setAttribute("aria-label",n?e[7]:e[6])},document.addEventListener("fullscreenchange",k),document.addEventListener("webkitfullscreenchange",k),s.addEventListener("pointermove",function(e){e.pointerType==="mouse"&&l()}),s.addEventListener("focusin",l),s.addEventListener("keydown",function(e){if(e.target===c&&/^Arrow/.test(e.key))return;var t=e.key.toLowerCase();if(t==="k"||t===" "&&e.target===o)y();else if(t==="arrowleft")o.currentTime=Math.max(0,o.currentTime-5);else if(t==="arrowright")o.currentTime=Math.min(o.duration||0,o.currentTime+5);else if(t==="m")o.muted=!o.muted;else if(t==="f")u.click();else if(t==="escape"&&!r.hidden)h();else return;e.preventDefault(),l()}),o.tabIndex=0}window.mcFilm=function(){document.querySelectorAll(".mc-film:not(.is-ready)").forEach(c)},window.mcFilm()})()</script></div>
  <script>
  new MutationObserver(() => {
    const dark = document.documentElement.classList.contains("dark");
    document.querySelectorAll(".film-pair").forEach((pair) => {
      const from = pair.querySelector(dark ? ".film-light video" : ".film-dark video");
      const to = pair.querySelector(dark ? ".film-dark video" : ".film-light video");
      if (!from || !to || !from.currentTime) return;
      const playing = !from.paused;
      from.pause();
      to.currentTime = from.currentTime;
      [...from.textTracks].forEach((track, i) => { if (to.textTracks[i]) to.textTracks[i].mode = track.mode; });
      if (playing) to.play().catch(() => {});
    });
  }).observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
  </script><figcaption>この記事を8分の映像にしました。ナレーションは英語で、日本語字幕が付きます。映像素材の一部はCoverrのものです。</figcaption>
</figure>


<h2 class="relative group">なぜ1つのチェックアウトでは並列エージェントがうまくいかないのか
    <div id="なぜ1つのチェックアウトでは並列エージェントがうまくいかないのか" class="anchor"></div>
    
    <span
        class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none">
        <a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#%e3%81%aa%e3%81%9c1%e3%81%a4%e3%81%ae%e3%83%81%e3%82%a7%e3%83%83%e3%82%af%e3%82%a2%e3%82%a6%e3%83%88%e3%81%a7%e3%81%af%e4%b8%a6%e5%88%97%e3%82%a8%e3%83%bc%e3%82%b8%e3%82%a7%e3%83%b3%e3%83%88%e3%81%8c%e3%81%86%e3%81%be%e3%81%8f%e3%81%84%e3%81%8b%e3%81%aa%e3%81%84%e3%81%ae%e3%81%8b" aria-label="アンカー">#</a>
    </span>
    
</h2>
<p>9月のある日、私が作っているマーケットプレイスアプリの同じチェックアウトで、Claude Codeのセッションが5つ同時に動いていました。その日、2つのことが起きました。テスト設定ファイルへの1行の修正が、4回のビルド失敗を生き延びたのに、いざコミットしようとしたら消えていたのです。<code>git commit</code>は「working tree clean」と言い、ファイルには別のセッションの内容が入っていました。こういう更新の消失は、gitのどこにも記録が残りません。reflogにもstashにも何もなく、更新日時もごく普通です。同じ日には、作業ツリーからビルドするデプロイスクリプトが、別のセッションの書きかけの変更を本番に出しかけました。</p>
<p>10月には3つ目が起きました。あるセッションが、別のセッションのステージされていない変更の横で自分のファイルをコミットしたところ、pre-commitフックがフックの実行中、ステージされていない変更を<em>すべて</em>stashしました。もう一方のセッションの編集はその間ディスクから消え、型チェッカーはそのセッションの新しいファイルでエラーになり、コミットは中止されました。しかも、どのセッションも私の名前でコミットするので、<code>git log</code>を見ても誰が何をしたのか分かりません。</p>
<p>worktreeを使う理由は一言で言えます。書き手が複数いる作業ツリーは競合状態で、負けた側はそれに気づけません。エージェントごとに作業ツリーを分ければ、競合そのものがなくなります。</p>
<figure class="diagram">
  <div role="img" aria-label="図：コミット、ブランチ、設定、worktreeごとの小さな専用フォルダを持つ共有の.gitディレクトリが、3つの作業ディレクトリにつながっている。mainブランチのメインのチェックアウト（.envとnode_modulesあり）、git worktree addで作ったfix-loginブランチのチェックアウト（どちらもなし）、claude -wで作ったworktree-add-searchブランチのチェックアウト（.worktreeincludeが.envをコピー、セッション中はロック）"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 700 906" aria-hidden="true" focusable="false">
<path class="d-group" d="M30,267 V735 M30,435.5 H62 M30,578.5 H62 M30,735 H62"></path>
<text class="d-title d-mono" x="2" y="30" font-size="28">.git</text>
<text class="d-sub" x="2" y="57" font-size="18">すべてのworktreeで共有</text>
<rect class="d-panel" x="2" y="75" width="696" height="192" rx="22"></rect>
<rect class="d-head" x="25" y="105" width="8" height="8" rx="2"></rect>
<text class="d-label" x="46" y="115.8" font-size="19">コミットとオブジェクト</text>
<rect class="d-head" x="25" y="137" width="8" height="8" rx="2"></rect>
<text class="d-label" x="46" y="147.8" font-size="19">ブランチとタグ（refs/）</text>
<rect class="d-head" x="25" y="169" width="8" height="8" rx="2"></rect>
<text class="d-label" x="46" y="179.8" font-size="19">設定、リモート、フック</text>
<rect class="d-head" x="25" y="201" width="8" height="8" rx="2"></rect>
<text class="d-label" x="46" y="211.8" font-size="19">worktrees/：worktreeごとの小さな専用フォルダ（それぞれのHEAD</text>
<text class="d-label" x="46" y="239.8" font-size="19">とindex）</text>
<text class="d-title" x="62" y="327" font-size="26">3つの作業ディレクトリ</text>
<text class="d-sub" x="62" y="354" font-size="18">ファイル、HEAD、indexはそれぞれ別</text>
<rect class="d-box" x="62" y="372" width="636" height="127" rx="14"></rect>
<text class="d-label d-mono" x="82" y="409.2" font-size="20">~/code/myapp</text>
<rect class="d-panel" x="82" y="424" width="60.1" height="28" rx="14"></rect>
<text class="d-label d-mono" x="94" y="443.4" font-size="15">main</text>
<text class="d-sub" x="154.1" y="444.1" font-size="17">メインのチェックアウト</text>
<path class="d-badge" style="fill:none;stroke-width:2.6" d="M83,474 l4.5,4.5 l9.5,-10"></path>
<text class="d-label" x="107" y="479.6" font-size="17">.env あり</text>
<path class="d-badge" style="fill:none;stroke-width:2.6" d="M205.8,474 l4.5,4.5 l9.5,-10"></path>
<text class="d-label" x="229.8" y="479.6" font-size="17">node_modules 45 MB</text>
<rect class="d-box" x="62" y="515" width="636" height="127" rx="14"></rect>
<text class="d-label d-mono" x="82" y="552.2" font-size="20">~/code/myapp-fix-login</text>
<rect class="d-panel" x="82" y="567" width="105.3" height="28" rx="14"></rect>
<text class="d-label d-mono" x="94" y="586.4" font-size="15">fix-login</text>
<text class="d-sub" x="199.3" y="587.1" font-size="17">git worktree add で作成</text>
<path class="d-line" style="fill:none;stroke-width:2.2" d="M85,611.5 l10,10 M95,611.5 l-10,10"></path>
<text class="d-sub" x="107" y="622.6" font-size="17">.env なし</text>
<path class="d-line" style="fill:none;stroke-width:2.2" d="M206.9,611.5 l10,10 M216.9,611.5 l-10,10"></path>
<text class="d-sub" x="228.9" y="622.6" font-size="17">node_modules なし（npm install までは 84 KB）</text>
<rect class="d-box" x="62" y="658" width="636" height="154" rx="14"></rect>
<text class="d-label d-mono" x="82" y="695.2" font-size="20">~/code/myapp/.claude/worktrees/add-search</text>
<rect class="d-panel" x="82" y="710" width="195.6" height="28" rx="14"></rect>
<text class="d-label d-mono" x="94" y="729.4" font-size="15">worktree-add-search</text>
<text class="d-sub" x="289.6" y="730.1" font-size="17">claude -w add-search で作成</text>
<path class="d-badge" style="fill:none;stroke-width:2.6" d="M83,760 l4.5,4.5 l9.5,-10"></path>
<text class="d-label" x="107" y="765.6" font-size="17">.env（.worktreeinclude がコピー）</text>
<path class="d-line" style="fill:none;stroke-width:2.2" d="M411.6,754.5 l10,10 M421.6,754.5 l-10,10"></path>
<text class="d-sub" x="433.6" y="765.6" font-size="17">node_modules なし</text>
<rect class="d-line" style="fill:none;stroke-width:2" x="84" y="785.5" width="12" height="9" rx="2"></rect>
<path class="d-line" style="fill:none;stroke-width:2" d="M86.5,785.5 v-2.5 a3.5,3.5 0 0 1 7,0 v2.5"></path>
<text class="d-sub" x="107" y="792.6" font-size="17">セッション中はロックされる</text>
<text class="d-sub" x="2" y="850" font-size="16">Claude Codeは、同じリポジトリのworktree間でさらに2つを共有します。「don't ask</text>
<text class="d-sub" x="2" y="874" font-size="16">again」の承認（メインのチェックアウトの .claude/settings.local.json に保存）と、プロ</text>
<text class="d-sub" x="2" y="898" font-size="16">ジェクトスコープのプラグインです。</text>
</svg>
</div><figcaption>1つのリポジトリに3つの作業ディレクトリ。履歴は1か所に保存され、ファイルとHEADとindexはworktreeごとに持ちます。</figcaption>
</figure>


<h2 class="relative group">claude -w の使い方と動き
    <div id="claude--w-の使い方と動き" class="anchor"></div>
    
    <span
        class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none">
        <a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#claude--w-%e3%81%ae%e4%bd%bf%e3%81%84%e6%96%b9%e3%81%a8%e5%8b%95%e3%81%8d" aria-label="アンカー">#</a>
    </span>
    
</h2>
<figure><video
    class="my-0 rounded-md"
    autoplay loop muted playsinline preload="metadata"
    poster="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/claude-worktree.jpg" style="background:url('data:image/webp;base64,UklGRkoAAABXRUJQVlA4ID4AAACQAwCdASogABIAPw16sU+mI6IhKAgAxiGJ6QDC+BPdNCPmtcKAAP7ozOlPLz658ebe527EEQOHuoyZaAAAAA==') center/cover no-repeat"
    width="1280"
    height="720"
    aria-label="ターミナル：cat .worktreeinclude が .env を表示し、claude -w add-search が worktree-add-search ブランチにいると答える。git worktree list では新しいworktreeが locked と表示され、ls では .env はコピーされているが node_modules はない。git worktree remove は、すでに終了したclaudeセッションのロックを理由に削除を拒否し、unlockしてからremoveすると成功する">
    <source src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/claude-worktree.mp4" type="video/mp4">
  </video><figcaption>使い捨てのリポジトリで実際に動かしたところ。セッションが終わった後もロックが残っている点に注目してください。</figcaption>
</figure>

<p><a href="https://code.claude.com/docs/en/worktrees"  target="_blank" rel="noreferrer">公式ドキュメントのworktreesのページ</a>に書いてあることと、実際に試して確認したことです。</p>
<ul>
<li><strong>場所とブランチ。</strong> <code>claude -w add-search</code>は、<code>.claude/worktrees/add-search/</code>を<code>worktree-add-search</code>という新しいブランチで作ります。名前を省略すると、<code>bright-running-fox</code>のような名前が自動で付きます。<code>.claude/worktrees/</code>は<code>.gitignore</code>に入れておきましょう。入れないと、メインのチェックアウトで全部が未追跡ファイルとして表示されます。</li>
<li><strong>どこから切るか（base ref）。</strong> <code>worktree.baseRef</code>の既定値は<code>&quot;fresh&quot;</code>で、リモートのデフォルトブランチ（たいていは<code>origin/main</code>）から切ります。直近24時間fetchしていなければ、最大5秒でfetchしてくれます。<code>&quot;head&quot;</code>にすると、手元の今の<code>HEAD</code>から切るので、まだpushしていないコミットも引き継がれます。ブランチ名は指定できないので、特定のブランチから作りたいときは自分で<code>git worktree add</code>を使います。</li>
<li><strong>プルリクエスト。</strong> <code>claude --worktree &quot;#1234&quot;</code>は、そのPRのheadをfetchして<code>.claude/worktrees/pr-1234</code>を作ります。引用符を忘れると、シェルが<code>#</code>以降をコメントとして扱ってしまいます。</li>
<li><strong>信頼の確認。</strong> 一度もClaudeを開いたことのないフォルダで、対話モードの<code>claude -w</code>を最初に打つと「Workspace trust not yet accepted」で失敗します。そこで一度だけ普通に<code>claude</code>を起動して、信頼のダイアログを承認してください。<code>claude -p -w</code>はこの確認を飛ばします。</li>
<li><strong>囲い。</strong> worktreeの中にいる間、Claude Codeはメインのチェックアウトにあるファイルの編集、メインのチェックアウトを作業ディレクトリにしたコマンド、<code>git -C</code>や<code>--git-dir</code>、<code>GIT_DIR</code>でメイン側を指したgitを拒否します。逆に何を防がないかも、ドキュメントにはっきり書いてあります。メインのチェックアウトに書き込む<code>cp</code>やシェルのリダイレクトは、このチェックでは止まりません。</li>
</ul>
<p>worktreeがメインのチェックアウトと何を共有するかも、何を共有しないかと同じくらい大事です。すべてのworktreeが同じ<code>.git</code>に書き込むので、どれかで作ったコミットやブランチは全部から見えます。プロジェクトスコープのプラグインはどこでも読み込まれます。そして、worktreeの中で「Yes, and don&rsquo;t ask again」と答えた承認は、<em>メインの</em>チェックアウトの<code>.claude/settings.local.json</code>に保存されます。つまりその承認はすべてのworktreeに効き、承認したworktreeを消した後も残ります。便利ですが、承認するコマンドに秘密情報を入れない理由がまた1つ増えたとも言えます。</p>

<h2 class="relative group">後片付けと、残るロック
    <div id="後片付けと残るロック" class="anchor"></div>
    
    <span
        class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none">
        <a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#%e5%be%8c%e7%89%87%e4%bb%98%e3%81%91%e3%81%a8%e6%ae%8b%e3%82%8b%e3%83%ad%e3%83%83%e3%82%af" aria-label="アンカー">#</a>
    </span>
    
</h2>
<p>対話モードのworktreeセッションを終了するとき、Claude Codeは削除で失われるものがないかを確認します。名前のないセッションでworktreeに変更がなければ、ブランチごと自動で削除されます。名前付きのセッションは先に確認してきます。作業が残っていれば、残すかどうかを聞かれ、表示される<code>claude --worktree &lt;名前&gt; --resume</code>で後から戻れます。</p>
<p>非対話モードは事情が違い、試していて引っかかったのはここだけでした。<code>claude -p</code>には終了時の確認がないので、後片付けをしません。さらにClaude Codeはセッション中、worktreeに<code>git worktree lock</code>をかけていて、<code>-p</code>の実行が終わった後も、もう存在しないプロセスIDのままロックが残ります。上の録画でも、<code>git worktree remove</code>が「cannot remove a locked working tree, lock reason: claude session add-search」と拒否しています。ドキュメントにもまさにこう書いてあり、後のセッションの古いロックの掃除で外れるか、先に<code>git worktree unlock</code>を実行すれば消せます。分かってしまえば無害ですが、最初は少しぎょっとします。</p>

<h2 class="relative group">.worktreeinclude：真っさらなチェックアウトにないファイル
    <div id="worktreeinclude真っさらなチェックアウトにないファイル" class="anchor"></div>
    
    <span
        class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none">
        <a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#worktreeinclude%e7%9c%9f%e3%81%a3%e3%81%95%e3%82%89%e3%81%aa%e3%83%81%e3%82%a7%e3%83%83%e3%82%af%e3%82%a2%e3%82%a6%e3%83%88%e3%81%ab%e3%81%aa%e3%81%84%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab" aria-label="アンカー">#</a>
    </span>
    
</h2>
<p>worktreeに入っているのは、追跡されているファイルだけです。gitが無視しているファイルも持ち込みたいときは、リポジトリのルートに<code>.worktreeinclude</code>を置きます。書き方は<code>.gitignore</code>と同じで、Claude Codeがコピーするのは、パターンに一致し、<em>かつ</em>gitに無視されているファイルだけです。追跡済みのファイルが二重になることはありません。</p>
<div class="highlight-wrapper"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl"># .worktreeinclude
</span></span><span class="line"><span class="cl">.env
</span></span><span class="line"><span class="cl">.env.local
</span></span><span class="line"><span class="cl">config/secrets.json</span></span></code></pre></div></div>
<p>これはClaude Codeがgitで作るworktreeすべてに効きます。<code>claude -w</code>、サブエージェントのworktree、デスクトップアプリの並列セッションです。<code>git worktree add</code>で自分で作ったworktreeには効かず、<code>WorktreeCreate</code>フックで作成処理を置き換えた場合も丸ごと無視されます。</p>
<p><code>.env</code>だけでなく、もっと入れておくことをおすすめします。忘れがちなgitignore対象のファイルほど、派手には壊れてくれないからです。私のアプリでは、ほかのセッションのコミット前の編集が絶対に本番に出ないよう、デプロイスクリプトをクリーンなworktreeからビルドする形に変えました。ところがそのクリーンな作業ツリーには、ある機能が使うgitignore対象の署名用証明書がありませんでした。イメージはそのままビルドされ、その機能は本番で13日間失敗し続け、スクリプトを証明書をコピーし、足りなければ警告する形に直すまで止まりませんでした。worktreeからの別のデプロイでは、gitignore対象のテーマフォルダがなく、2分かかるエクスポートで作業ツリーを汚した<em>後で</em>ビルドが失敗しました。出荷に関わる作業をworktreeに任せる前に、メインのチェックアウトで<code>git status --short --ignored</code>を実行し、そのうちどれをビルドが読むのか確かめておきましょう。</p>

<h2 class="relative group">node_modules：いちばん重いところ
    <div id="node_modulesいちばん重いところ" class="anchor"></div>
    
    <span
        class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none">
        <a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#node_modules%e3%81%84%e3%81%a1%e3%81%b0%e3%82%93%e9%87%8d%e3%81%84%e3%81%a8%e3%81%93%e3%82%8d" aria-label="アンカー">#</a>
    </span>
    
</h2>
<p><code>.worktreeinclude</code>は小さなファイル向けです。<code>node_modules</code>には役立ちませんし、Claude Codeにもworktree間で共有する仕組みはありません。コードを動かす必要があるworktreeは、それぞれ自分の<code>node_modules</code>が要ります。</p>
<figure><video
    class="my-0 rounded-md"
    autoplay loop muted playsinline preload="metadata"
    poster="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktree-basics.jpg" style="background:url('data:image/webp;base64,UklGRkgAAABXRUJQVlA4IDwAAADQAwCdASogABIAPw18sk+mI6IhKAgAxiGJ6QC/OBPdOMkqQtYu1AAA/ujR5WBjJmvERft5/vglvvCMAAA=') center/cover no-repeat"
    width="1280"
    height="720"
    aria-label="ターミナル：git worktree add で新しいブランチの myapp-fix-login と、origin/main で detached の myapp-hotfix を作る。git worktree list に3つが並び、新しいworktreeには .env も node_modules もない。du ではメインのチェックアウトが45M、worktreeが84K、npm install の後は両方とも45M">
    <source src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/worktree-basics.mp4" type="video/mp4">
  </video><figcaption>デモ用リポジトリでの素のgit worktree。インストールするまでは84 KB、した後はまた45 MBまるごと。</figcaption>
</figure>

<p>実際のプロジェクトでは数字が深刻になります。私のモバイルアプリのリポジトリには、メインのチェックアウトの横に19個のworktreeがあります。そのうち12個を測ると194 MBから12 GBまであり、大きい4つは、どれも自分の<code>node_modules</code>を持っていた4つでした。今週はノートPCのディスクが96%埋まっているので、掃除するならまずここからです。</p>
<p>選択肢を、単純なものから順に並べます。</p>
<ol>
<li><strong>worktreeごとにインストールする。</strong> 最初にエージェントに<code>npm install</code>を実行させるか、自分でやります。遅くてディスクも食いますが、驚かされることはありません。</li>
<li><strong>ロックファイルが同じチェックアウトからクローンする。</strong> macOSなら、<code>cp -c -R ../myapp/node_modules .</code>でAPFSのクローンが使えます。クローンは、どちらかが変更されるまでデータブロックを共有します。デモの45 MBは0.8秒でした。私は実際のworktreeからのデプロイでもこれを使っています。クローンしていいのはロックファイルが一致するときだけで、ネイティブのビルドフォルダには注意してください。私の場合、メインのチェックアウトのiOSのPodsはworktreeのブランチより古いSDK向けにビルドされていたので、そこだけは入れ直す必要がありました。</li>
<li><strong>pnpmを使う。</strong> パッケージは1つのストアに置かれ、macOSのpnpmは<a href="https://pnpm.io/settings/node-modules#packageimportmethod"  target="_blank" rel="noreferrer">ハードリンクより先にクローンを試します</a>（LinuxとWindowsではハードリンクが先）。デモでは、2つ目のworktreeのインストールが約5秒で終わりました。</li>
<li><strong><code>WorktreeCreate</code>フックでインストールする。</strong> フックはClaude Code標準のgit処理を置き換えるので、<code>git worktree add</code>の後にインストールまで走らせることもできます。これはまだ試していません。やるなら、<code>.worktreeinclude</code>が処理されなくなるので、<code>.env</code>のコピーもフックの中でやる必要があります。</li>
</ol>

<h2 class="relative group">tmuxで並列エージェントを動かす
    <div id="tmuxで並列エージェントを動かす" class="anchor"></div>
    
    <span
        class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none">
        <a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#tmux%e3%81%a7%e4%b8%a6%e5%88%97%e3%82%a8%e3%83%bc%e3%82%b8%e3%82%a7%e3%83%b3%e3%83%88%e3%82%92%e5%8b%95%e3%81%8b%e3%81%99" aria-label="アンカー">#</a>
    </span>
    
</h2>
<p>私はもともとtmuxの中で暮らしているので（レイアウトは<a href="https://jared.lynskey.co.nz/ja/posts/2026/2026-10-22-claude-code-day-to-day/" >日々の使い方の記事</a>に書きました）、worktreeはそのまま収まります。worktreeごとにウィンドウかペインを1つずつ。下は、同じファイルを変更するよう指示した3つのエージェントを同時に起動したところです。</p>
<figure><video
    class="my-0 rounded-md"
    autoplay loop muted playsinline preload="metadata"
    poster="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/parallel-agents-tmux.jpg" style="background:url('data:image/webp;base64,UklGRlQAAABXRUJQVlA4IEgAAACQBACdASogABIAPw10rE0mIyIhKAqoxiGJ6QDImBPdLsmKk7T7Naw9bcwBsAAA/ui+5wOzf0YXxkY1UgYA04COTxtokeJAAAA=') center/cover no-repeat"
    width="1280"
    height="720"
    aria-label="3つのペインに分けたtmux：claude -w add-bye、add-greet、add-tests が同時に動き、実行中はペインのタイトルがworktreeの名前に変わる。2つは src/index.js の変更を、1つは新しいテストフォルダを報告し、最後に上のペインでメインのチェックアウトがクリーンなことと、ロックされた3つのworktreeを確認する">
    <source src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/parallel-agents-tmux.mp4" type="video/mp4">
  </video><figcaption>エージェント3つ、ファイル1つ、衝突なし。メインのチェックアウトはクリーンなままで、それぞれの変更は自分のブランチで待っています。</figcaption>
</figure>

<p>2つのエージェントが同時に<code>src/index.js</code>を編集し、どちらも相手に気づきませんでした。それぞれの<code>src/index.js</code>は、ディスク上では別のファイルだからです。メインのチェックアウトもクリーンなままでした。最後に残るのは、レビューしてマージする3つのブランチで、ここはworktreeが代わりにやってくれない仕事です。2つのエージェントが同じ行を変えれば、やはりマージコンフリクトになります。ただし、黙って上書きされるのではなく、目に見えるマージの場面で出てきます。</p>
<p>VS Codeでは、worktreeはただのフォルダです。<code>code .claude/worktrees/add-search</code>で、そのブランチの別ウィンドウとして開けます。</p>

<h2 class="relative group">worktreeはスナップショット
    <div id="worktreeはスナップショット" class="anchor"></div>
    
    <span
        class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none">
        <a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#worktree%e3%81%af%e3%82%b9%e3%83%8a%e3%83%83%e3%83%97%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88" aria-label="アンカー">#</a>
    </span>
    
</h2>
<p>worktreeは古くなります。11月19日、2〜3日前から用意されていたworktreeからOTAアップデートが出たところ、その間に別の場所から出ていた2つの修正を黙って巻き戻してしまいました。その日のうちに気づいて差し替えましたが、worktreeは完璧に隔離されていて、それが問題でした。その修正を一度も見ていなかったのです。gitのコマンド1行で、リリース前に気づけたはずでした。</p>
<figure><video
    class="my-0 rounded-md"
    autoplay loop muted playsinline preload="metadata"
    poster="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/stale-worktree-check.jpg" style="background:url('data:image/webp;base64,UklGRkgAAABXRUJQVlA4IDwAAACwAwCdASogABIAPw16sk+mI6IhKAgAxiGJ6QDEJBPdNJGDbpnawAD+6TSngiBlgQG6+gLgAZ5HH8TQAAA=') center/cover no-repeat"
    width="1280"
    height="720"
    aria-label="ターミナル：mainには新しいコミット「Fix sign-in token handling」があり、古いworktreeは最初のコミットのまま。git merge-base --is-ancestor main HEAD は「missing the fix: rebase before you ship」と表示し、git rebase main の後は同じチェックが「has the fix」と表示する">
    <source src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/stale-worktree-check.mp4" type="video/mp4">
  </video><figcaption>作りたてではないworktreeから出荷する前に実行したいチェックです。</figcaption>
</figure>

<p><code>baseRef: &quot;fresh&quot;</code>は新しいworktreeを最新に保ってくれます。古いworktreeを最新に保ってくれるものはないので、そこからリリースする前に確かめましょう。</p>

<h2 class="relative group">サブエージェントとフック
    <div id="サブエージェントとフック" class="anchor"></div>
    
    <span
        class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none">
        <a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#%e3%82%b5%e3%83%96%e3%82%a8%e3%83%bc%e3%82%b8%e3%82%a7%e3%83%b3%e3%83%88%e3%81%a8%e3%83%95%e3%83%83%e3%82%af" aria-label="アンカー">#</a>
    </span>
    
</h2>
<p>この隔離を得るのに、エージェントごとにターミナルを開く必要はありません。フロントマターに<code>isolation: worktree</code>と書いたカスタムサブエージェントは、毎回専用の一時worktreeで動きます。</p>
<div class="highlight-wrapper"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-markdown" data-lang="markdown"><span class="line"><span class="cl"><span class="nn">---</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">refactorer</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">description</span><span class="p">:</span><span class="w"> </span><span class="l">Applies mechanical refactors across many files</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">isolation</span><span class="p">:</span><span class="w"> </span><span class="l">worktree</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nn">---</span><span class="w">
</span></span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Apply the requested refactor across every affected file, then run the tests
</span></span><span class="line"><span class="cl">and report the results.</span></span></code></pre></div></div>
<p>これは<a href="https://code.claude.com/docs/en/worktrees#isolate-subagents-with-worktrees"  target="_blank" rel="noreferrer">ドキュメント</a>の例です。サブエージェントが変更なしで終われば、そのworktreeは削除されます。変更があるものは、作業を失わずに消せるようになるまで、定期的な掃除で消されずに残ります。細かい点を1つ。<code>.claude/worktrees/</code>の下のworktreeで動くサブエージェントは、指示をメインの会話から引き継ぎ、worktreeのルートにある<code>CLAUDE.md</code>は読み込みません。</p>
<p><code>WorktreeCreate</code>と<code>WorktreeRemove</code>のフックは、git処理を丸ごと置き換えます。git以外のバージョン管理システムや、worktreeを<code>.claude/worktrees/</code>以外に置きたいとき向けですが、上のインストールのような準備処理を入れる場所にもなります。</p>

<h2 class="relative group">素のgit worktree addのほうが向いている場面
    <div id="素のgit-worktree-addのほうが向いている場面" class="anchor"></div>
    
    <span
        class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none">
        <a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#%e7%b4%a0%e3%81%aegit-worktree-add%e3%81%ae%e3%81%bb%e3%81%86%e3%81%8c%e5%90%91%e3%81%84%e3%81%a6%e3%81%84%e3%82%8b%e5%a0%b4%e9%9d%a2" aria-label="アンカー">#</a>
    </span>
    
</h2>
<p>白状すると、私のアプリのリポジトリの<code>.claude/worktrees</code>フォルダは空です。19個のworktreeはすべて素の<code>git worktree add</code>で、すべてこの1か月の間に作られたもので、半分はdetached HEADです。ノートPCのほかのリポジトリにも、40、40、18、10、3、2、2個あります。しかも作っているのはたいてい私ではありません。このノートPCにあるClaude Codeの会話記録638件のうち85件で、エージェントが<code>git worktree add</code>を実行していて、その回数は合わせて336回です。</p>
<p>素のgitのほうが向いているのは、次のようなときです。</p>
<ul>
<li><strong>既存の特定のブランチが必要なとき。</strong> たとえば、ホットフィックス用に残しているリリースブランチです。<code>baseRef</code>ではできません。</li>
<li><strong>修正を1つだけ出したいとき。</strong> ほかのセッションがまだデプロイしていない変更を<code>main</code>にコミットしていたので、本番で動いているコミットにdetachedのworktreeを作り、自分の修正だけをcherry-pickしてそこからデプロイしました。こうすれば、出ていくのはその修正だけです。</li>
<li><strong>自分でエージェントに指示を書くとき。</strong> 1つのリポジトリで複数のエージェントを動かすとき、私はそれぞれへの指示に、<code>git worktree add --detach &quot;$TMPDIR/&lt;task&gt;-wt&quot; refs/remotes/origin/main</code>で自分専用のworktreeを作り、<code>git push origin HEAD:main</code>でpushし、コンフリクトしたらrebaseするように書いています。</li>
<li><strong>消されたくないとき。</strong> Claude Codeの掃除は、<code>git worktree add</code>で自分で作ったworktreeを決して削除しません。</li>
</ul>
<p><code>claude -w</code>が向いているのは、手でセッションを始めるときに、ブランチ作成、<code>.env</code>のコピー、メインのチェックアウトへの囲い、後片付けを任せたい場合です。両者は問題なく混ぜて使えます。どちらで作っても、Claude Codeは同じようにworktreeとして扱い、上で書いたメインのチェックアウトとの共有も同じです。</p>

<h2 class="relative group">まとめ
    <div id="まとめ" class="anchor"></div>
    
    <span
        class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none">
        <a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#%e3%81%be%e3%81%a8%e3%82%81" aria-label="アンカー">#</a>
    </span>
    
</h2>
<p>並列で動かすセッションごとに<code>claude -w &lt;名前&gt;</code>を使い、<code>.claude/worktrees/</code>を<code>.gitignore</code>に入れましょう。<code>.worktreeinclude</code>には<code>.env</code>だけでなく、ビルドが必要とするgitignore対象のファイルをすべて書いておきます。<code>node_modules</code>は、worktreeごとのインストール、クローン、pnpmのどれでいくか決めておきます。<code>-p</code>で動かした後は、<code>git worktree unlock</code>が必要なロックが残っているかもしれません。作りたてではないworktreeから出荷する前には、すでに本番に出ているものが入っているか確かめます。worktreeは、エージェント同士がファイルを上書きし合うのは防いでくれますが、意見が食い違うのまでは防いでくれません。最後に3つのブランチをレビューするのは、やはりあなたです。</p>

<h2 class="relative group">参考リンク
    <div id="参考リンク" class="anchor"></div>
    
    <span
        class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none">
        <a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#%e5%8f%82%e8%80%83%e3%83%aa%e3%83%b3%e3%82%af" aria-label="アンカー">#</a>
    </span>
    
</h2>
<p><strong>このサイト内：</strong></p>
<ul>
<li><a href="https://jared.lynskey.co.nz/ja/posts/2026/2026-10-22-claude-code-day-to-day/" >Claude Codeを日々どう使っているか</a>：tmux、パーミッションモード、スマホからの操作について</li>
</ul>
<p><strong>外部：</strong></p>
<ul>
<li>Claude Codeドキュメントの<a href="https://code.claude.com/docs/en/worktrees"  target="_blank" rel="noreferrer">Run parallel sessions with worktrees</a>：たいていのドキュメントより丁寧に書かれています</li>
<li><a href="https://git-scm.com/docs/git-worktree"  target="_blank" rel="noreferrer">git-worktree</a>：何が共有され、何がworktreeごとなのか</li>
<li><a href="https://pnpm.io/settings/node-modules#packageimportmethod"  target="_blank" rel="noreferrer">pnpmの<code>packageImportMethod</code></a>：クローンとハードリンクについて</li>
</ul>
]]></content:encoded>
      <media:content url="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/featured.jpg" medium="image" type="image/jpeg" />
    </item>
  </channel>
</rss>
