<?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>Tmux · 仁才德</title>
    <link>https://jared.lynskey.co.nz/zh-cn/tags/tmux/</link>
    <description>关于软件工程与研发团队领导力的短文——绩效评估、招聘与团队扩张、CI/CD、DevOps 监控、智能体 AI。写于首尔。</description>
    <generator>Hugo</generator>
    <language>zh-CN</language>
    <copyright>© 2026 仁才德</copyright>
    <lastBuildDate>Thu, 19 Nov 2026 00:00:00 +1300</lastBuildDate>
    <atom:link href="https://jared.lynskey.co.nz/zh-cn/tags/tmux/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Claude Code worktree 如何使用：让多个智能体并行工作而不互相覆盖</title>
      <link>https://jared.lynskey.co.nz/zh-cn/posts/2026/claude-code-git-worktrees/</link>
      <guid isPermaLink="true">https://jared.lynskey.co.nz/zh-cn/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>。从这以后，这个会话只能修改这个目录里的文件。在另一个终端里换个名字再跑一遍同样的命令，就有了两个碰不到彼此文件的智能体。坑在于 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="日本語">
    <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="简体中文" default>
  </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="日本語">
    <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="简体中文" default>
  </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>这篇文章的八分钟视频版。旁白是英文，配有中文字幕。部分视频素材来自 Coverr。</figcaption>
</figure>


<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="#%e4%b8%ba%e4%bb%80%e4%b9%88%e4%b8%80%e4%b8%aa%e6%a3%80%e5%87%ba%e7%9b%ae%e5%bd%95%e6%92%91%e4%b8%8d%e4%bd%8f%e5%a4%9a%e4%b8%aa%e5%b9%b6%e8%a1%8c%e6%99%ba%e8%83%bd%e4%bd%93" aria-label="锚点">#</a>
    </span>
    
</h2>
<p>九月的某一天，我在自己做的一个交易平台应用的同一个检出目录里，同时开着五个 Claude Code 会话，结果出了两件事。一个测试配置文件的一行修复，挺过了四次构建失败，等到要提交时却不见了：<code>git commit</code> 说工作区是干净的，文件里装的是另一个会话写的内容。这种丢失的修改，git 里不会留下任何记录：reflog 里没有，stash 里也没有，修改时间看起来也很正常。同一天，一个直接拿工作区构建的部署脚本，差点把另一个会话没做完的改动发到了生产环境。</p>
<p>十月又出了第三件事。一个会话在另一个会话未暂存的改动旁边提交自己的文件，pre-commit 钩子在运行期间把所有未暂存的改动<em>全部</em> stash 了。另一个会话的修改在这段时间里从磁盘上消失，类型检查随后在它新建的文件上报错，提交也中止了。再加上所有会话都用我的名字提交，<code>git log</code> 根本看不出是谁做了什么。</p>
<p>用 worktree 的理由一句话就能说清：有多个写入者的工作区就是竞态，输的一方连自己输了都不知道。给每个智能体一个独立的工作区，竞态也就没了。</p>
<figure class="diagram">
  <div role="img" aria-label="示意图：一个共享的 .git 目录，里面有提交、分支、配置，以及每个 worktree 一个的小型私有目录，连向三个工作目录：main 分支上的主检出目录（有 .env 和 node_modules），用 git worktree add 创建、在 fix-login 分支上的检出（两样都没有），用 claude -w 创建、在 worktree-add-search 分支上的检出（.env 由 .worktreeinclude 复制，会话运行期间被锁定）"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 700 882" 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">三个工作目录</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="M190.1,474 l4.5,4.5 l9.5,-10"></path>
<text class="d-label" x="214.1" 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="M208.1,611.5 l10,10 M218.1,611.5 l-10,10"></path>
<text class="d-sub" x="230.1" 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="M401.1,754.5 l10,10 M411.1,754.5 l-10,10"></path>
<text class="d-sub" x="423.1" 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 之间共享两样东西：“don't ask again”的授权</text>
<text class="d-sub" x="2" y="874" font-size="16">（保存在主检出目录的 .claude/settings.local.json）和项目级插件。</text>
</svg>
</div><figcaption>一个仓库，三个工作目录。历史只存一份；文件、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-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e8%a1%8c%e4%b8%ba" 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>worktree-add-search</code> 上创建 <code>.claude/worktrees/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 过，它会先 fetch 一次，最多等五秒。设成 <code>&quot;head&quot;</code> 的话，新 worktree 从你本地当前的 <code>HEAD</code> 切出来，没 push 的提交也会一起带过去。它不能设成某个分支名；想从特定分支创建，就自己用 <code>git worktree add</code>。</li>
<li><strong>Pull request。</strong> <code>claude --worktree &quot;#1234&quot;</code> 会 fetch 这个 PR 的 head，然后创建 <code>.claude/worktrees/pr-1234</code>。记得加引号，不然 shell 会把 <code>#</code> 后面当成注释。</li>
<li><strong>信任确认。</strong> 在一个从没开过 Claude 的目录里第一次运行交互式的 <code>claude -w</code>，会报错 &ldquo;Workspace trust not yet accepted&rdquo;。在那个目录里先普通地运行一次 <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> 或 shell 重定向，这些检查不会拦。</li>
</ul>
<p>worktree 和主检出目录共享什么，和不共享什么一样重要。所有 worktree 都写同一个 <code>.git</code>，所以在任何一个里面做的提交和分支，在所有 worktree 里都看得到。项目级插件在哪里都会加载。还有，在 worktree 里回答的 &ldquo;Yes, and don&rsquo;t ask again&rdquo;，会保存到<em>主</em>检出目录的 <code>.claude/settings.local.json</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="#%e6%b8%85%e7%90%86%e4%bb%a5%e5%8f%8a%e7%95%99%e4%b8%8b%e6%9d%a5%e7%9a%84%e9%94%81" 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> 报错 &ldquo;cannot remove a locked working tree, lock reason: claude session add-search&rdquo;。文档写的也正是这样：等后面某个会话清理过期锁时会释放，或者先运行 <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%e5%85%a8%e6%96%b0%e6%a3%80%e5%87%ba%e9%87%8c%e6%b2%a1%e6%9c%89%e7%9a%84%e6%96%87%e4%bb%b6" 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>，因为最容易被忘掉的被忽略文件，往往不会大声报错。我的应用把部署脚本改成了从干净的 worktree 构建，这样其他会话没提交的修改就永远不会被发出去。可是那个干净的工作区里，缺了某个功能要用的、被 git 忽略的签名证书。镜像照样构建成功，那个功能在生产环境里失败了 13 天，直到脚本改成把证书复制进去、缺一个就报警为止。另一次从 worktree 部署时，缺的是一个被忽略的主题目录，构建是在一个两分钟的导出把工作区弄脏<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%e6%9c%80%e8%b4%b5%e7%9a%84%e9%83%a8%e5%88%86" aria-label="锚点">#</a>
    </span>
    
</h2>
<p><code>.worktreeinclude</code> 是给小文件用的。它帮不了 <code>node_modules</code>，Claude Code 也没有在 worktree 之间共享它的机制，所以每个需要运行代码的 worktree，都得有自己的一份。</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，以及 detached 在 origin/main 上的 myapp-hotfix；git worktree list 列出三个；新 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 不等，最大的四个正好就是自带 <code>node_modules</code> 的那四个。这周我笔记本的磁盘用到了 96%，要清理的话，就该从它们开始。</p>
<p>几种做法，从简单到巧妙：</p>
<ol>
<li><strong>每个 worktree 单独安装。</strong> 让智能体一开始就跑 <code>npm install</code>，或者自己装。慢，占磁盘，但不会给你惊喜。</li>
<li><strong>从 lockfile 相同的检出目录克隆。</strong> 在 macOS 上，<code>cp -c -R ../myapp/node_modules .</code> 用的是 APFS 克隆，两边在任何一方改动之前共享数据块。克隆演示里的 45 MB 只用了 0.8 秒。我在真实的 worktree 部署里也用过这个办法。只在 lockfile 一致时克隆，原生构建目录要小心：我的主检出目录里的 iOS Pods 是为比 worktree 分支更旧的 SDK 构建的，所以那部分只能重新安装。</li>
<li><strong>用 pnpm。</strong> 它的包都放在一个 store 里，macOS 上的 pnpm <a href="https://pnpm.io/settings/node-modules#packageimportmethod"  target="_blank" rel="noreferrer">会先尝试克隆，再尝试硬链接</a>（Linux 和 Windows 上是先硬链接）。在演示里，第二个 worktree 的安装大约五秒就完成了。</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="#%e5%9c%a8-tmux-%e9%87%8c%e8%b7%91%e5%b9%b6%e8%a1%8c%e6%99%ba%e8%83%bd%e4%bd%93" aria-label="锚点">#</a>
    </span>
    
</h2>
<p>我本来就住在 tmux 里（布局写在<a href="https://jared.lynskey.co.nz/zh-cn/posts/2026/2026-10-22-claude-code-day-to-day/" >我每天怎么用 Claude Code</a>那篇里），所以 worktree 直接就能放进去：一个 worktree 一个窗口，或者一个窗格。下面是同时启动的三个智能体，每个都被要求改同一个文件：</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="分成三个窗格的 tmux：claude -w add-bye、add-greet、add-tests 同时运行，运行期间窗格标题变成各自 worktree 的名字；两个报告修改了 src/index.js，一个报告新建了测试目录；最后上面的窗格显示主检出目录是干净的，还有三个被锁定的 worktree">
    <source src="https://jared.lynskey.co.nz/en/posts/2026/claude-code-git-worktrees/parallel-agents-tmux.mp4" type="video/mp4">
  </video><figcaption>三个智能体，一个文件，没有冲突。主检出目录保持干净，每个改动都在自己的分支里等着。</figcaption>
</figure>

<p>其中两个同时改了 <code>src/index.js</code>，谁也没察觉到对方，因为它们各自的 <code>src/index.js</code> 在磁盘上是不同的文件。主检出目录也一直是干净的。最后留给你的，是三个要审查、要合并的分支，这是 worktree 替你做不了的事：两个智能体改了同一行，照样会有合并冲突。只不过它不再是悄无声息的覆盖，而是出现在你看得见的合并环节。</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-%e6%98%af%e4%b8%80%e5%bc%a0%e5%bf%ab%e7%85%a7" aria-label="锚点">#</a>
    </span>
    
</h2>
<p>worktree 也会过时。11 月 19 日，一个两三天前就准备好的 worktree 发出了一次 OTA 更新，结果悄悄回退了这期间从别处发出的两个修复。当天就发现并替换掉了，但 worktree 隔离得太好，问题恰恰在这：它从来没看到过那两个修复。其实一行 git 命令就能在发布前发现：</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 上有一个新提交 &#39;Fix sign-in token handling&#39;；一个旧的 worktree 还停在第一个提交上；git merge-base --is-ancestor main HEAD 输出 &#39;missing the fix: rebase before you ship&#39;；执行 git rebase main 之后，同样的检查输出 &#39;has the fix&#39;">
    <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 保持最新，所以从旧 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="#%e5%ad%90%e6%99%ba%e8%83%bd%e4%bd%93%e5%92%8c%e9%92%a9%e5%ad%90" aria-label="锚点">#</a>
    </span>
    
</h2>
<p>要得到这种隔离，并不需要给每个智能体开一个终端。在 front matter 里写上 <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 会被删除；有改动的会一直保留，直到定期清理能在不丢工作的前提下删掉它。有个细节：在 <code>.claude/worktrees/</code> 下的 worktree 里运行的子智能体，指令来自你的主对话，不会加载 worktree 根目录里的 <code>CLAUDE.md</code>。</p>
<p><code>WorktreeCreate</code> 和 <code>WorktreeRemove</code> 钩子会整个替换 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="#%e4%bb%80%e4%b9%88%e6%97%b6%e5%80%99%e7%9b%b4%e6%8e%a5%e7%94%a8-git-worktree-add-%e6%9b%b4%e5%a5%bd" aria-label="锚点">#</a>
    </span>
    
</h2>
<p>坦白说，我那个应用仓库里的 <code>.claude/worktrees</code> 目录是空的。它的 19 个 worktree 全是用普通的 <code>git worktree add</code> 建的，全是最近一个月建的，一半处于 detached HEAD 状态。笔记本上其他仓库里还有 40、40、18、10、3、2、2 个。而且大多数不是我建的：这台笔记本上的 638 份 Claude Code 对话记录里，有 85 份是智能体在运行 <code>git worktree add</code>，加起来一共 336 次。</p>
<p>直接用 git 更好的情况：</p>
<ul>
<li><strong>需要某个已有的分支时，</strong> 比如为热修复保留的发布分支。<code>baseRef</code> 做不到。</li>
<li><strong>只想发出一个修复时。</strong> 其他会话已经往 <code>main</code> 提交了还没部署的工作，所以我在生产环境正在运行的那个提交上建了一个 detached worktree，只把我的修复 cherry-pick 进去，从那里部署。这样发出去的就只有这一个修复。</li>
<li><strong>自己给智能体写任务说明时。</strong> 在一个仓库上同时启动好几个智能体时，我给每个的说明里都会写：用 <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> 推送，有冲突就 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="#%e7%ae%80%e7%9f%ad%e6%80%bb%e7%bb%93" 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>，要把构建需要的被忽略文件都列进去。提前想好 <code>node_modules</code> 怎么办：每个 worktree 单独装、克隆，还是用 pnpm。用 <code>-p</code> 跑完之后，可能会留下一把需要 <code>git worktree unlock</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="#%e5%bb%b6%e4%bc%b8%e9%98%85%e8%af%bb" aria-label="锚点">#</a>
    </span>
    
</h2>
<p><strong>本站：</strong></p>
<ul>
<li><a href="https://jared.lynskey.co.nz/zh-cn/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>
    <item>
      <title>我每天怎么用 Claude Code：tmux、权限模式和我的手机</title>
      <link>https://jared.lynskey.co.nz/zh-cn/posts/2026/2026-10-22-claude-code-day-to-day/</link>
      <guid isPermaLink="true">https://jared.lynskey.co.nz/zh-cn/posts/2026/2026-10-22-claude-code-day-to-day/</guid>
      <pubDate>Thu, 22 Oct 2026 00:00:00 +1300</pubDate>
      <dc:creator>Jared Lynskey</dc:creator>
      <category>Claude Code</category>
      <category>AI Agents</category>
      <category>LLM</category>
      <category>Developer Experience</category>
      <category>DevOps</category>
      <category>tmux</category>
      <category>SSH</category>
      <category>Codex</category>
      <category>Automation</category>
      <description>Claude Code 是 Anthropic 的编程 agent：Claude 模型在你自己的机器上，用你的文件和 shell 干活。我每天怎么用它，数字来自我自己的日志：在 tmux 里的终端开五个 session，权限提示基本都绕过，从手机上通过 Remote Control、SSH 和聊天机器人连过去，以及为什么我没法告诉你它和 Codex 比谁更好。</description>
      <content:encoded><![CDATA[<p>Claude Code 是 Anthropic 的编程 agent。它跑的是和 Claude 应用一样的 Claude 模型，只不过是在你自己的机器上，能读你的文件、跑 shell 命令、改你的代码，付费的 Claude 套餐都带它。我是在终端里用它，而不是 VS Code 扩展或桌面应用：笔记本上一个 tmux session 里开着五个 session，几乎全是关掉权限提示启动的，在手机上可以通过 Claude 应用的 Remote Control、SSH 或一个聊天机器人连过去。</p>
<p>下面就是这套配置的细节，数字来自我自己的机器，而不是凭记忆：设置文件、Claude Code 存放在 <code>~/.claude/projects</code> 下的 session 记录（我的最早到 8月28日），还有它的 prompt 历史，最早到 2 月，一共 7,323 条 prompt。</p>

<h2 class="relative group">Claude 和 Claude Code 不是一回事
    <div id="claude-和-claude-code-不是一回事" 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-%e5%92%8c-claude-code-%e4%b8%8d%e6%98%af%e4%b8%80%e5%9b%9e%e4%ba%8b" aria-label="锚点">#</a>
    </span>
    
</h2>
<p>Claude 是一个模型家族，也是你跟这些模型对话的那个聊天应用：claude.ai、桌面端和手机上的都是。Claude Code 是建在这些模型之上的 agent。你在一个项目文件夹里启动它，它就在那儿循环干活：读文件、跑命令、改代码、跑测试，直到活干完，或者需要你出面。问 Claude 怎么修一个问题，你得到的是一个回答。问 Claude Code，你得到的是修好的代码，外加一份等你看的 diff。</p>
<p>两个我都用。从 10月18日起，我做的一个集市兼社区应用就从 Django 后端直接把翻译请求发给 Claude API，而把它切换过去的那次改动，就是在一个 Claude Code session 里做的。在我的 session 记录里，94% 的回复来自 Opus 5.5，我设置里的 effort 级别是 high。</p>
<p>原生安装程序只有一行，而且会自己更新：</p>
<div class="highlight-wrapper"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">curl -fsSL https://claude.ai/install.sh <span class="p">|</span> bash</span></span></code></pre></div></div>
<p>它会在 <code>~/.local/bin</code> 里留下一个 <code>claude</code> 符号链接，指向 <code>~/.local/share/claude/versions/</code>；我的在 10月21日自己从 2.1.305 升到了 2.1.306。Claude Code 需要付费的 Claude 套餐（Pro、Max、Team 或 Enterprise），或者一个 API 账号。价格变得太勤，我就不写了，请看 <a href="https://claude.com/pricing"  target="_blank" rel="noreferrer">Anthropic 的价格页面</a>。</p>

<h2 class="relative group">一个 tmux session，七个窗口
    <div id="一个-tmux-session七个窗口" 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="#%e4%b8%80%e4%b8%aa-tmux-session%e4%b8%83%e4%b8%aa%e7%aa%97%e5%8f%a3" aria-label="锚点">#</a>
    </span>
    
</h2>
<p>写这篇的时候，<code>tmux list-panes -a</code> 显示我笔记本上只有一个 session，叫 <code>main</code>，里面有七个窗口。其中五个是 Claude Code，每个项目一个：我的集市应用和我的估价应用（两个都在<a href="https://jared.lynskey.co.nz/zh-cn/posts/2026/2026-07-22-my-current-stack/" >Fly.io 上的 Django 自动扩缩容</a>里介绍过）、这个博客，还有两个小东西。我的终端 profile 打开每个窗口时都会起一个登录 shell，并把它接到 <code>main</code> 上。所以在笔记本上新开一个标签页，和从手机 SSH 登录进来，落到的是同一批 session。</p>
<p>9月17日到 10月8日，我试过另一个终端多路复用器，后来回到 tmux，原因很实际：我手机上的 SSH 应用是用 tmux 做多路复用的，它的快捷按钮发的也是 tmux 的默认按键。<code>~/.tmux.conf</code> 里类似下面这几行，就是为手机写的：</p>
<div class="highlight-wrapper"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">set</span> -g prefix C-a                 <span class="c1"># Ctrl-a prefix</span>
</span></span><span class="line"><span class="cl"><span class="nb">set</span> -g prefix2 C-b                <span class="c1"># stock Ctrl-b too, for apps that send it</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Size each window to the client that used it last, not the smallest one,</span>
</span></span><span class="line"><span class="cl"><span class="c1"># so a phone attached to the same session doesn&#39;t shrink it.</span>
</span></span><span class="line"><span class="cl">setw -g window-size latest
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Copy to the clipboard of whichever terminal is attached (OSC 52),</span>
</span></span><span class="line"><span class="cl"><span class="c1"># so over SSH it lands on the phone&#39;s clipboard too.</span>
</span></span><span class="line"><span class="cl"><span class="nb">set</span> -g set-clipboard on</span></span></code></pre></div></div>
<p>在 tmux 里，有两件事会不一样。Claude Code 用 Ctrl+B 把正在跑的命令放到后台，而 Ctrl+B 现在是我的第二个 tmux prefix，所以 <code>~/.claude/keybindings.json</code> 把它关掉，改用 Meta+B：</p>
<div class="highlight-wrapper"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="nt">&#34;bindings&#34;</span><span class="p">:</span> <span class="p">[</span>
</span></span><span class="line"><span class="cl">    <span class="p">{</span> <span class="nt">&#34;context&#34;</span><span class="p">:</span> <span class="s2">&#34;Global&#34;</span><span class="p">,</span> <span class="nt">&#34;bindings&#34;</span><span class="p">:</span> <span class="p">{</span> <span class="nt">&#34;ctrl+b&#34;</span><span class="p">:</span> <span class="kc">null</span> <span class="p">}</span> <span class="p">},</span>
</span></span><span class="line"><span class="cl">    <span class="p">{</span> <span class="nt">&#34;context&#34;</span><span class="p">:</span> <span class="s2">&#34;Task&#34;</span><span class="p">,</span> <span class="nt">&#34;bindings&#34;</span><span class="p">:</span> <span class="p">{</span> <span class="nt">&#34;ctrl+b&#34;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&#34;meta+b&#34;</span><span class="p">:</span> <span class="s2">&#34;task:background&#34;</span> <span class="p">}</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">  <span class="p">]</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></div></div>
<p>另一件是换行。按 Enter 会发送 prompt。文档说，<code>\</code> 加 Enter，以及 Ctrl+J，是在任何终端里都能用的两种；Option+Enter 要等终端把 Option 当作 Meta 发送之后才能用；Shift+Enter 在有些终端里原生就能用，但 tmux 只有在开了 <code>extended-keys</code> 时才会把它传过去。我没开，所以在我的 session 里，Shift+Enter 就是发送 prompt。这些我其实很少用到：7,323 条 prompt 里，只有 84 条含有我手敲的换行，而有 279 条含有粘贴的内容。Claude Code 会把粘贴折叠成 <code>[Pasted text #1 +34 lines]</code> 这样的占位符，发出去的还是全文。</p>

<h2 class="relative group">终端、VS Code 扩展还是桌面应用？
    <div id="终端vs-code-扩展还是桌面应用" 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%bb%88%e7%ab%afvs-code-%e6%89%a9%e5%b1%95%e8%bf%98%e6%98%af%e6%a1%8c%e9%9d%a2%e5%ba%94%e7%94%a8" aria-label="锚点">#</a>
    </span>
    
</h2>
<p>同一个 agent 有好几种外壳，它们读的是同一套设置文件。按 Claude Code 在每份 session 记录里记下的入口来算，我的 session 是这么分布的：</p>
<table>
	<thead>
			<tr>
					<th>形态</th>
					<th>是什么</th>
					<th>我的使用情况，8月28日到10月21日</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>终端里的 CLI</td>
					<td>在终端里、tmux 里跑的 <code>claude</code></td>
					<td>128 个 session</td>
			</tr>
			<tr>
					<td>桌面应用的 Code 标签页</td>
					<td>Claude 应用里的 Claude Code，带 diff 视图和多个面板</td>
					<td>2 个 session</td>
			</tr>
			<tr>
					<td>VS Code 扩展</td>
					<td>编辑器里的一个聊天面板</td>
					<td>没用过；现在没装，只剩下它的设置</td>
			</tr>
	</tbody>
</table>
<p>Claude 应用和 claude.ai/code 不是启动 session 的第四个地方：它们操控的是笔记本上已经在跑的 session（或者云端的一个），而 10 月以来我的大部分 session 都通过 Remote Control 带着这条链接。</p>
<p>对我来说就是终端，而且不是出于情怀。我手机要接上去的 tmux 需要终端，channels 也需要。channels 能把外部事件推进一个 session，文档把它列为 CLI 的功能。</p>
<p>也常有人问 Claude Code 需不需要 git。CLI 不需要：我的 home 目录不是仓库，而我有 208 条 prompt 发给了在那里启动的 session。桌面应用的文档说，它的 session 隔离需要 git，每个 session 有自己的 worktree；把云端 session 拉到终端里，也需要同一个仓库的 checkout。&ldquo;Git is required&rdquo; 这条提示我自己从没见过。我最近一次用桌面应用是 10月20日，那个 session 跑在一个根本不是仓库的文件夹里。</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="#%e6%9d%83%e9%99%90%e6%a8%a1%e5%bc%8f%e4%bb%a5%e5%8f%8a%e6%88%91%e5%ae%9e%e9%99%85%e7%94%a8%e7%9a%84%e9%82%a3%e4%b8%aa" aria-label="锚点">#</a>
    </span>
    
</h2>
<p>权限模式决定 Claude Code 多久停下来问你一次，用 Shift+Tab 在各个模式之间切换。Manual（<code>default</code>）在大多数编辑文件、跑命令或访问网络的操作之前都会问。<code>acceptEdits</code> 放行文件编辑和常见的文件系统命令。<code>plan</code> 只读、只提方案，不做编辑。<code>auto</code> 让第二个模型，也就是一个分类器，去拦下有风险的操作，而不是来问你。<code>bypassPermissions</code> 几乎什么都不问。从 2.1.283 版开始，除非你在 <code>permissions.defaultMode</code> 里另行指定，终端里的 session 默认以 auto 模式启动。</p>
<p>所以&quot;怎么让 Claude Code 不问权限就跑&quot;，我的老实回答是：我就是这么启动它的：</p>
<div class="highlight-wrapper"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">claude --dangerously-skip-permissions</span></span></code></pre></div></div>
<p>我 shell 历史里的 69 条 <code>claude</code> 命令，有 62 条带着这个 flag，现在在跑的五个 session 也全都带着。8月28日到10月21日之间我敲的 1,266 条 prompt 里，1,179 条发给了 bypass 模式的 session，82 条给了 auto 模式，5 条给了 Manual 或 accept-edits。</p>
<p>文档说得很直白，bypass 模式是给&quot;容器、虚拟机或不联网的 dev container 这类隔离环境用的，在那里 Claude Code 损坏不了你的宿主系统&quot;。我的笔记本哪种都不是，而且我的设置里记着我已经点掉了那条警告（<code>&quot;skipDangerousModePermissionPrompt&quot;: true</code>）。如果你也这么做，要知道 allow 规则在 bypass 模式下不起作用，所以在我日常的 session 里，分散在 19 个设置文件里的 378 条 allow 规则完全是摆设。deny 和 ask 规则仍然生效，而这两种我一条都没有。</p>
<p>例外是那个要读别人说的话的 session。它的启动脚本不带这个 flag，所以它以 auto 模式启动。10月12日到20日之间到达 session 的 27 个生产环境事件，全部是在 auto 模式下到的，43 条聊天消息里也有 42 条是，没有一条落在 bypass 下。</p>
<p>真正让 bypass 模式没反咬我一口的，是几条习惯，是九月某天两个 session 在同一个 checkout 里互相覆盖了对方的改动、还差点把它部署出去之后，写进 Claude 记忆里的（来龙去脉在<a href="https://jared.lynskey.co.nz/zh-cn/posts/2026/2026-10-22-agentic-ai-security/#隔离因为最可能出事的是另一个-agent" >那篇 agentic AI 安全的文章</a>里）：小修复一能用就马上 commit；按文件名 stage，永远不用 <code>git add -A</code>；看看 <code>git status</code> 里有没有不是你做的改动；当 <code>main</code> 上有其他 session 还没部署的改动时，从线上那个 commit 建一个 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="#%e4%bb%8e%e6%89%8b%e6%9c%ba%e4%b8%8a%e8%bf%9e%e8%bf%87%e5%8e%bb" aria-label="锚点">#</a>
    </span>
    
</h2>
<p>有三条路，每条通到的东西都不一样。</p>
<table>
	<thead>
			<tr>
					<th>入口</th>
					<th>手机上能拿到什么</th>
					<th>靠什么跑起来</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Claude 应用里的 Remote Control</td>
					<td>一个 session 的对话：打字、回答它的问题、附一张照片</td>
					<td><code>remoteControlAtStartup: true</code>，外加推送通知</td>
			</tr>
			<tr>
					<td>用手机上的 SSH 应用连进 <code>main</code></td>
					<td>终端本身，所有窗口</td>
					<td>一个私有网络、一个以我的用户身份运行的 sshd，再用一个短别名接上</td>
			</tr>
			<tr>
					<td>一个聊天机器人</td>
					<td>一个能听到生产环境报错、也能回消息的 session</td>
					<td>一个官方的 Claude Code channel 插件，加上我写的一个事件 channel</td>
			</tr>
	</tbody>
</table>
<p>Remote Control 把手机上的 Claude 应用，或者浏览器里的 claude.ai/code，连到一个一直在笔记本上跑着的 session，文件、工具和 MCP server 都在。9月13日到10月20日之间，我敲了 26 次 <code>/rc</code>。现在 <code>remoteControlAtStartup</code> 开着，新 session 会自己连上：10 月初以来我启动的 77 个 session 里，有 67 个带 Remote Control 链接，而 9 月下半月是 52 个里只有 3 个。</p>
<p>开着 <code>agentPushNotifEnabled</code> 的话，Claude 觉得有必要时可以发推送通知，文档说通常是长任务跑完，或者需要你拿主意的时候。它需要 claude.ai 的订阅，而不是 API key；而且因为 session 跑在笔记本上，笔记本必须醒着。从 10月15日起，我的笔记本合上盖子也不睡了（<code>sudo pmset -a disablesleep 1</code>）。</p>
<p>反过来也行。<code>/teleport</code>，或者 <code>claude --teleport</code>，可以把在网页或应用里启动的云端 session 拉到终端里，连同它的分支和对话一起。我这么做过两次，都在 7 月。</p>
<p>SSH 是我想要终端本身的时候用的。手机通过<a href="https://jared.lynskey.co.nz/zh-cn/posts/2026/2026-10-01-cloudflare-warp-dev-network/" >我那篇私有网络的文章</a>里的私有网络连到笔记本，一个别名再把它接到 <code>main</code> 上，于是我可以在留在笔记本上的那些窗口之间划来划去。让 Mac 正常响应手机上的应用，前后修了四个地方，其中跟 Claude Code 有关的是：tmux 绝不能自己启动。有个应用开了个 session 想跑 <code>docker ps</code>，拿回来的却是 72 KB 的屏幕重绘。</p>
<p>聊天机器人是给那个我不想守在旁边看的 session 用的。从 10月12日起，有一个 session 带着我写的一个小 channel 在跑，它每分钟查一次应用的服务器有没有新的生产环境报错和项目看板动态，然后交给这个 session；另外还加载了一个官方的聊天插件，这样在它 allowlist 上的我们两个人就能给它发消息。启动的那一行大致如下，名字都换成了通用的：</p>
<div class="highlight-wrapper"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">exec</span> claude <span class="se">\
</span></span></span><span class="line"><span class="cl">  --channels plugin:&lt;chat-plugin&gt;@claude-plugins-official <span class="se">\
</span></span></span><span class="line"><span class="cl">  --dangerously-load-development-channels server:my-events <span class="s2">&#34;</span><span class="nv">$@</span><span class="s2">&#34;</span></span></span></code></pre></div></div>
<p>一个 supervisor 脚本让它一直在 tmux 里跑着。重启之后它会接着原来的对话，所以 session 是接着干，而不是一觉醒来脑子一片空白；每次重启它都会在聊天里通报一声。这个 session 在工作区里修东西，修完就停，只有一个例外，是我 10月13日加的：如果一个 bug 真的在生产环境伤到了用户，它可以修复、测试、commit 并部署，然后告诉我们它做了什么。</p>

<h2 class="relative group">Skills、记忆和 /goal
    <div id="skills记忆和-goal" 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="#skills%e8%ae%b0%e5%bf%86%e5%92%8c-goal" aria-label="锚点">#</a>
    </span>
    
</h2>
<p>我的设置文件里没有一个 <code>hooks</code> 键。最接近的是 <code>/goal</code>，从 7月11日起我用了一次又一次。它接受一个条件，为这个 session 设一个 Stop hook，用 Claude Code 自己的话说，这个 hook &ldquo;在条件满足之前会阻止停止&rdquo;。我写的 goal 读起来就跟我嘴上说的一样。一条 7 月的真实例子，错别字原样保留，告诉它构建 &ldquo;still broken, try a deeper fix and dont stop until&rdquo;（还是坏的，往深里修，别停），直到发到测试人员手上为止。想看看长任务进展如何、又不想打断它，可以用 <code>/btw</code>，它问的是一个不进入对话的旁支问题。我问的大多是某种版本的 &ldquo;hows it going?&quot;（进展如何？）。</p>
<p>Skills 装的是那些不然我每次都得重新解释一遍的东西。有一个用户级的 skill，读我维护的几个网站（这个博客也在其中）的每周关键词报告，再把结果用到标题、描述和标签上。这篇文章回答的那些问题，就来自它给这个博客出的、日期为 10月18日的那份报告，而这个 skill 文件和它的代码一起放在一个仓库里做版本管理。那个集市应用的仓库有自己的 skills：一个在 Docker 里启动 API 并跑冒烟测试，一个处理项目看板，还有一个负责提交公司的费用报销。我装的两个插件，一个是 Swift 的语言服务器插件，另一个就是那个聊天插件。</p>
<p>记忆是存放教训的地方。我在 17 个项目里一共有 160 个记忆文件，其中 83 个属于那个集市应用，很多都跟某次出故障有关。这个应用的 <code>CLAUDE.md</code> 现在大约是 6 月时的六倍长。这个博客的 <code>CLAUDE.md</code> 则是个空文件；一篇文章该是什么语气，写在一个记忆文件里。</p>
<p>遇到更大的活，Claude 会启动 subagent，在我的主 session 里一共 120 次，其中 40 次是对话的 fork。这个博客的日文、韩文、中文和越南文版本就是这么来的。10月19日和20日，这个应用社区板块的改版前后四次过了 Workflow 工具：一次从七个角度加一个 critic 做的审查，确认了大约 58 个问题；五个小组分头修复，每组只负责自己的文件，修完各自经过评审；一轮收拾剩下的问题；最后一次独立检查，确认每个问题都修好了。它在 20 号上线。</p>

<h2 class="relative group">通过 SSH 操控工作站
    <div id="通过-ssh-操控工作站" 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="#%e9%80%9a%e8%bf%87-ssh-%e6%93%8d%e6%8e%a7%e5%b7%a5%e4%bd%9c%e7%ab%99" aria-label="锚点">#</a>
    </span>
    
</h2>
<p><a href="https://jared.lynskey.co.nz/zh-cn/posts/2026/2026-10-01-cloudflare-warp-dev-network/" >我那篇私有网络的文章</a>讲的是把重活放到 devbox 上，也就是办公室里那台带 GPU 的工作站，再从哪儿都能连过去。这些&quot;连过去&rdquo;，大多是 Claude Code 在做。9月24日到10月19日之间，笔记本上的 21 个 session 通过普通的 <code>ssh</code> 在 devbox 上跑了 1,470 条命令：<code>kubectl</code> 进那上面跑着的集群，在一个数据库 pod 里跑 <code>psql</code>，用 <code>tmux capture-pane</code> 看看一个长任务跑到哪儿了。因为离开办公室网络时 <code>ssh devbox</code> 会退回到一条隧道，同一个 session 在办公室、在家、在咖啡馆都能用。而且笔记本不再睡眠，session 可以一直操控着 devbox，我就在手机上时不时看一眼。</p>

<h2 class="relative group">为什么我没法拿它和 Codex 比
    <div id="为什么我没法拿它和-codex-比" 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="#%e4%b8%ba%e4%bb%80%e4%b9%88%e6%88%91%e6%b2%a1%e6%b3%95%e6%8b%bf%e5%ae%83%e5%92%8c-codex-%e6%af%94" aria-label="锚点">#</a>
    </span>
    
</h2>
<p>凭我自己的使用经验，我没法告诉你 Claude Code 是不是比 Codex 好，看这张表就知道为什么：</p>
<table>
	<thead>
			<tr>
					<th></th>
					<th>Codex</th>
					<th>Claude Code</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>时间</td>
					<td>2025年11月29日到12月4日</td>
					<td>至少从 2025年11月起；prompt 历史从 2026年2月开始</td>
			</tr>
			<tr>
					<td>在哪儿用</td>
					<td>VS Code 扩展</td>
					<td>终端（128 个 session），桌面应用（2 个）</td>
			</tr>
			<tr>
					<td>模型和 effort</td>
					<td><code>gpt-5.1-codex</code>，medium</td>
					<td>Opus 5.5，high</td>
			</tr>
			<tr>
					<td>审批</td>
					<td><code>workspace-write</code> 沙箱，网络关闭，按需询问</td>
					<td>93% 的 prompt 用 bypass，聊天那个 session 用 auto</td>
			</tr>
			<tr>
					<td>用量</td>
					<td>4 个 thread</td>
					<td>2 月以来 7,323 条 prompt</td>
			</tr>
			<tr>
					<td>项目说明</td>
					<td>读 <code>AGENTS.md</code></td>
					<td>读 <code>CLAUDE.md</code>，外加它的记忆文件</td>
			</tr>
	</tbody>
</table>
<p>一周里四个 thread，一个关于图片的问题、对一个网站的两次改动、一个 3D 场景，这叫试用，算不上比较。不过其中有个细节，换任何 agent 时都用得上。那个 3D 项目把规则放在一个 <code>claude.md</code> 里，我在那儿问 Codex 的第一个问题，就是它在对话开始前会不会读 Claude 的文件。它说不会，直到我让它去读那个文件，它才知道项目的规则。不管你换到哪个 agent，说明文件都会留在原地，除非你自己把它带过去。从那以后我再没开过 Codex 的 thread。9月24日到10月4日之间，有那么几天这个扩展在 VS Code 里加载过，但我一个 thread 也没开，现在它已经卸载了。</p>
<p>所以我能站得住的结论很窄。我的整套配置是围绕 Claude Code 搭起来的，而我也没有回头去看现在的 Codex 处理同样的事情会怎么样。</p>
<p>最后一个数字，比上面任何内容都更能说明我是怎么用它的。8 月下旬以来，在我笔记本上的主 session 里，Claude Code 跑了 18,311 条 shell 命令，读、写或编辑文件 2,331 次。按次数算，它的大部分工作是在跑那些本来要我自己敲的命令，在笔记本上，也通过 SSH，不管我人在哪儿。而它真写起代码来，那些代码也不是到哪儿都受欢迎，这是另一个故事了，见 <a href="https://jared.lynskey.co.nz/zh-cn/posts/2026/2026-10-18-pyhtml2text/" >pyhtml2text 那篇</a>。</p>
]]></content:encoded>
      <media:content url="https://jared.lynskey.co.nz/en/posts/2026/2026-10-22-claude-code-day-to-day/featured.jpg" medium="image" type="image/jpeg" />
    </item>
  </channel>
</rss>
