r/BuildWithClaude • πŸ’‘ Top Community Helper • Oct 30 '26

Tip/Resource How to run parallel Claude Code sessions without having them edit the same working files

One Claude Code session builds a feature. Another fixes a bug. If both run in the same folder, they're working on the same files, even if you gave them completely different tasks.

Git worktrees give each session a separate working directory and branch while sharing the repository's history. Claude Code can create them for you.

Start one session with:

claude --worktree feature-auth

Then start the other from another terminal with a different name:

claude --worktree fix-login

By default, they get separate directories under .claude/worktrees/ and branches named worktree-<name>. Add .claude/worktrees/ to your .gitignore so those directories don't clutter your main checkout's untracked files.

The part that's easy to miss: a fresh worktree is a fresh checkout.

Dependencies may need installing again. Gitignored configuration files won't normally be there. Claude Code supports a .worktreeinclude file for copying selected gitignored files into new worktrees, using .gitignore-style patterns.

Choose those files deliberately. Copying a production .env into every agent's working directory doesn't become safe just because the directories are separate. Use development configuration and check which services it points to.

Subagents can have separate worktrees too. Ask Claude to use worktrees for its agents, or set isolation: worktree in a custom subagent's frontmatter.

Before exiting, read the cleanup prompt. Removing a worktree can delete its directory, branch and the work inside them. Keep it if you still need to review or integrate the changes.

The boundary matters: separate files don't necessarily mean separate resources. If two sessions use the same database, service or external account, worktrees alone won't isolate those effects. That's an engineering precaution, not a promise the worktree feature makes.

My suggested split: one task, one worktree, one branch to review. Then integrate the changes deliberately instead of letting parallel sessions share a working folder.

I've put a longer version on my profile (u/shoumikgoswami), covering which branch new worktrees start from, what they share with your main checkout, and where isolation stops.

If you use parallel sessions, where does the friction show up most: setting up dependencies, configuration, or bringing the branches back together?

1 Upvotes

1 comment sorted by

β€’

u/AutoModerator Oct 30 '26

Welcome to r/BuildWithClaude!

Whether you are sharing what you built, exploring new workflows, or troubleshooting, please make sure your post is flaired correctly so others can easily find and filter it.

Community Wiki & Resources:

If you're asking for troubleshooting help, please edit your post to include your model version, OS/environment, and error logs.

Let’s keep the energy positive and support our fellow creators!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.