<?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: Mirek Hovorka</title>
    <description>The latest articles on DEV Community by Mirek Hovorka (@mirekhovorka).</description>
    <link>https://dev.to/mirekhovorka</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%2F149441%2F557943bc-25cd-4fbd-bc23-8b36057c9b1c.jpg</url>
      <title>DEV Community: Mirek Hovorka</title>
      <link>https://dev.to/mirekhovorka</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mirekhovorka"/>
    <language>en</language>
    <item>
      <title>Claude Code and git worktrees: two sessions, one repo</title>
      <dc:creator>Mirek Hovorka</dc:creator>
      <pubDate>Fri, 28 Aug 2026 08:40:12 +0000</pubDate>
      <link>https://dev.to/mirekhovorka/claude-code-and-git-worktrees-two-sessions-one-repo-3do5</link>
      <guid>https://dev.to/mirekhovorka/claude-code-and-git-worktrees-two-sessions-one-repo-3do5</guid>
      <description>&lt;p&gt;Parallel Claude Code sessions only started to make sense to me once I stopped running them on the same checkout. Before that, for example, one session would be writing tests for a blog build while another was editing the CSS at the same time. But both were working on the same files. The first one would make a change and commit it, and the second one would carry on as if nothing had happened. Then, in the evening, instead of checking the results, I'd have to figure out which session each change actually came from. And it was completely unnecessary. Git has had a solution for this for years — worktrees: each session gets its own directory and its own branch, but they still work on the same repository. This way, the files don't overwrite each other, and both can commit independently of one another.&lt;/p&gt;

&lt;p&gt;(Everything here runs locally on my machine. If I want to completely separate the task from the computer, I use a different approach — I describe it in &lt;a href="https://mirekhovorka.cz/en/blog/claude-code-in-the-cloud/" rel="noopener noreferrer"&gt;the article about Claude Code in the cloud&lt;/a&gt;. And if you need a refresher on Git commands, I have a separate &lt;a href="https://mirekhovorka.cz/en/blog/git-github-cheatsheet-claude-code/" rel="noopener noreferrer"&gt;cheat sheet&lt;/a&gt;.)&lt;/p&gt;

&lt;h2&gt;
  
  
  How worktrees work
&lt;/h2&gt;

&lt;p&gt;You can think of a Git worktree as another working directory connected to the same repository. It shares the history and remote with other worktrees, but its own working files and branch are separate. For details, see the &lt;a href="https://git-scm.com/docs/git-worktree" rel="noopener noreferrer"&gt;Git documentation&lt;/a&gt;. One thing is essential for Claude Code: two sessions can run on a single repository, each in its own directory, and one cannot access the other's files.&lt;/p&gt;

&lt;h2&gt;
  
  
  When it pays off
&lt;/h2&gt;

&lt;p&gt;For me, two things are decisive.&lt;/p&gt;

&lt;p&gt;First: tasks must truly be able to be done independently of one another. One session can write tests while another works on CSS. One can refactor code while another updates the documentation. One can fix a bug while another prepares a new feature. But as soon as the second session needs the results from the first, it doesn't make sense. Instead of saving time, I'm just adding another branch of work that I have to keep track of.&lt;/p&gt;

&lt;p&gt;Second: The number of sessions isn't limited by the machine, but by how many outputs I can keep up with. I can handle two sessions. With three, it's a mess: I just end up switching between contexts, rushing through reviews, and doing more harm than good. As a result, I just end up with a growing pile of half-read diffs that I have to go back to one by one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step by step
&lt;/h2&gt;

&lt;p&gt;I'll start with one flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;claude &lt;span class="nt"&gt;--worktree&lt;/span&gt; testy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Claude Code creates a worktree at &lt;code&gt;.claude/worktrees/testy/&lt;/code&gt;, creates a branch named &lt;code&gt;worktree-testy&lt;/code&gt;, and starts the session within that branch. In a second terminal, I can open another session with a different name in the same way, and both sessions then run concurrently. If I don't specify a name, Claude generates one on its own, something like &lt;code&gt;dark-chocolate-cookie&lt;/code&gt;. The shortcut is &lt;code&gt;-w&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I recommend setting the following right away:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.gitignore&lt;/code&gt;&lt;/strong&gt;: Add &lt;code&gt;.claude/worktrees/&lt;/code&gt; to &lt;code&gt;.gitignore&lt;/code&gt;. Otherwise, the contents of the worktrees will appear in &lt;code&gt;git status&lt;/code&gt; of the main checkout.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gitignored files like &lt;code&gt;.env&lt;/code&gt;&lt;/strong&gt;: a new worktree is a clean checkout, so they are not there. If you need them in individual worktrees, create &lt;code&gt;.worktreeinclude&lt;/code&gt; in the root directory. The syntax works similarly to &lt;code&gt;.gitignore&lt;/code&gt;, except that here you specify the files to be copied into each new worktree.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The existing branch&lt;/strong&gt;: &lt;code&gt;--worktree&lt;/code&gt; branches from the default branch by default. However, if I need to run Claude on a specific branch I'm currently working on, I'll create a worktree manually using git and run Claude from within it:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git worktree add ../oprava-formulare fix-formular
&lt;span class="nb"&gt;cd&lt;/span&gt; ../oprava-formulare
claude
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cleanup&lt;/strong&gt;: After the interactive session is complete, Claude takes care of cleanup. If the worktree is empty, it deletes it automatically. If there is unfinished work left in it, it asks if I want to keep it. I can check the current status at any time via &lt;code&gt;git worktree list&lt;/code&gt; and remove an unnecessary worktree using &lt;code&gt;git worktree remove&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On Mac and Windows, the principle and set of commands are the same. On Windows, you'll just see paths with backslashes, such as &lt;code&gt;.claude\worktrees\testy&lt;/code&gt;. And one thing that surprised me the first time I cleaned up: if there's an NTFS junction or a symlink inside the worktree pointing to a directory located elsewhere, deleting the worktree will only remove the link itself. The target directory remains in place. That's how it's supposed to work, so don't be surprised if the "folder is still there."&lt;/p&gt;

&lt;h2&gt;
  
  
  Traps and guardrails
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Parallel sessions do not mean parallel subscriptions.&lt;/strong&gt; They all draw from the same standard five-hour window and the same weekly limit. The more I run at the same time, the faster they use up the shared quota. This saves me time at the keyboard, not tokens. So running three large tasks in parallel when I'm nearing the end of the window doesn't really pay off for me — I'll easily end up with several sessions in progress at once, and when the window runs out, they'll all stop.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Every worktree starts as a new, clean checkout.&lt;/strong&gt; That means no &lt;code&gt;node_modules&lt;/code&gt;, no virtualenv, and no existing build cache. So I reinstall the dependencies for each new worktree. For a smaller project, this is a minor issue, but with a large monorepo, the cost of maintaining additional parallel environments can add up enough that I have to think carefully about the number of worktrees I use. &lt;code&gt;.worktreeinclude&lt;/code&gt; helps with smaller configuration files, but of course, it won't install dependencies for me.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The new worktree doesn't see my work in progress locally.&lt;/strong&gt; I ran into this when I first used it: the session told me the file didn't exist. Well, of course — it wasn't in its checkout yet. If I want the new session to be based on my current work, I have to commit the changes first. And to ensure the worktree is created from the commit I'm currently working on (including changes I haven't pushed yet), rather than from the default branch on the remote, I set &lt;code&gt;worktree.baseRef&lt;/code&gt; to &lt;code&gt;"head"&lt;/code&gt; in my settings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-interactive runs via &lt;code&gt;-p&lt;/code&gt; behave differently.&lt;/strong&gt; If I run &lt;code&gt;claude -p --worktree ...&lt;/code&gt;, the final interactive cleanup does not occur, and the created worktree remains active. Therefore, from time to time, I go to &lt;code&gt;git worktree list&lt;/code&gt; and remove unnecessary items using &lt;code&gt;git worktree remove&lt;/code&gt;. If Git reports that the worktree is locked, I first run &lt;code&gt;git worktree unlock&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;For me, worktrees are one of the easiest ways to get usable parallel work out of Claude Code. I don't need any additional infrastructure or complicated setup — all it takes is one flag, and each session has its own separate working files and branch.&lt;/p&gt;

&lt;p&gt;Rules that have worked well for me: I only run tasks in parallel that aren't dependent on one another; I limit the number of concurrent sessions based on how many results I can thoroughly check; I use &lt;code&gt;.claude/worktrees/&lt;/code&gt; in &lt;code&gt;.gitignore&lt;/code&gt;; and I use &lt;code&gt;.worktreeinclude&lt;/code&gt; to transfer the necessary local configurations to new worktrees. Most importantly, I keep in mind that all sessions draw from the same subscription limit — the more there are, the faster I burn through tokens.&lt;/p&gt;

&lt;p&gt;If a task doesn't require my computer at all — if it's small, clearly defined, and easy to set up — I prefer to send it straight to a &lt;a href="https://mirekhovorka.cz/en/blog/claude-code-in-the-cloud/" rel="noopener noreferrer"&gt;cloud session&lt;/a&gt;. There, I don't have to worry about isolation or cleanup afterward, because I get a fresh sandbox every time. I mainly use worktrees when I want to keep my work locally and maintain continuous control over it.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://mirekhovorka.cz/en/blog/claude-code-parallel-worktrees/" rel="noopener noreferrer"&gt;mirekhovorka.cz&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

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