<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Suman Maharjan</title>
    <description>The latest articles on DEV Community by Suman Maharjan (@suman_maharjan_ee09fcd9b8).</description>
    <link>https://dev.to/suman_maharjan_ee09fcd9b8</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4244894%2F64e5a012-b510-40a5-a38d-9ff0808dea16.jpg</url>
      <title>DEV Community: Suman Maharjan</title>
      <link>https://dev.to/suman_maharjan_ee09fcd9b8</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/suman_maharjan_ee09fcd9b8"/>
    <language>en</language>
    <item>
      <title>The git worktrees your coding agents leave behind, and how to clean them up</title>
      <dc:creator>Suman Maharjan</dc:creator>
      <pubDate>Sat, 14 Nov 2026 18:29:48 +0000</pubDate>
      <link>https://dev.to/suman_maharjan_ee09fcd9b8/the-git-worktrees-your-coding-agents-leave-behind-and-how-to-clean-them-up-3pji</link>
      <guid>https://dev.to/suman_maharjan_ee09fcd9b8/the-git-worktrees-your-coding-agents-leave-behind-and-how-to-clean-them-up-3pji</guid>
      <description>&lt;p&gt;Claude Code, Cursor and Codex run in git worktrees so several agents can work at once. Each worktree is a full checkout with its own node_modules and build output, and they pile up quietly. One Claude Code user found 27 forgotten worktrees using 80 GB (&lt;a href="https://github.com/anthropics/claude-code/issues/63087" rel="noopener noreferrer"&gt;issue 63087&lt;/a&gt;). 61 Codex worktrees of a Rails app took about 100 GB (&lt;a href="https://github.com/openai/codex/issues/35383" rel="noopener noreferrer"&gt;issue 35383&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Where they live
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Claude Code:&lt;/strong&gt; &lt;code&gt;.claude/worktrees/&lt;/code&gt; inside each repository (older versions used &lt;code&gt;~/.claude-worktrees&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cursor:&lt;/strong&gt; &lt;code&gt;~/.cursor/worktrees/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Codex:&lt;/strong&gt; &lt;code&gt;~/.codex/worktrees/&lt;/code&gt;, on a detached HEAD rather than a branch&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  See what they take
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git worktree list                                  &lt;span class="c"&gt;# inside a repository&lt;/span&gt;
du -sh .claude/worktrees/* 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null &lt;span class="o"&gt;|&lt;/span&gt; sort -h   &lt;span class="c"&gt;# inside each repository&lt;/span&gt;
du -sh ~/.cursor/worktrees/*/* ~/.codex/worktrees/* 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null &lt;span class="o"&gt;|&lt;/span&gt; sort -h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Check before you remove one
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git -C &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;path&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; status --short             &lt;span class="c"&gt;# prints nothing if nothing is uncommitted&lt;/span&gt;
git -C &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;path&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; status --short --ignored   &lt;span class="c"&gt;# .env and other ignored files you'd lose&lt;/span&gt;
git log --oneline main..&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;branch&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;         &lt;span class="c"&gt;# prints nothing if the branch is merged&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Squash merges leave the commits out of main, so ask GitHub instead: &lt;code&gt;gh pr list --head &amp;lt;branch&amp;gt; --state merged --json headRefOid&lt;/code&gt;, and check it matches &lt;code&gt;git rev-parse &amp;lt;branch&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Remove it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git worktree remove &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;path&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Skip &lt;code&gt;--force&lt;/code&gt;: without it, git refuses when there's uncommitted work, which is the point. The branch stays, so nothing committed is lost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stop the pile-up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Claude Code:&lt;/strong&gt; lower &lt;code&gt;cleanupPeriodDays&lt;/code&gt; (default 30)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cursor:&lt;/strong&gt; lower &lt;code&gt;cursor.worktreeMaxCount&lt;/code&gt; (default 25)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Codex:&lt;/strong&gt; lower the limit of 15 kept worktrees in its settings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href="https://mopup.online/guides/coding-agent-worktrees" rel="noopener noreferrer"&gt;full guide&lt;/a&gt; covers the rest, including Codex's detached worktrees and a Codex bug that saved 54,504 crash reports in a day.&lt;/p&gt;




&lt;p&gt;I make &lt;a href="https://mopup.online/developers" rel="noopener noreferrer"&gt;Mopup&lt;/a&gt;, a Mac app that runs these checks for you and removes only finished worktrees, never with &lt;code&gt;--force&lt;/code&gt;. It's free to scan.&lt;/p&gt;

</description>
      <category>git</category>
      <category>ai</category>
      <category>productivity</category>
      <category>swift</category>
    </item>
  </channel>
</rss>
