Skip to main content
guidesSource-backedReview first Safety Privacy

Using Worktrees For Parallel Claude Code Sessions

Use git worktrees with Claude Code to run parallel sessions safely: EnterWorktree, background isolation, cleanup of .claude/worktrees/, and branch ownership rules that prevent conflicting edits.

by kiannidev·added 2026-06-15·
HarnessClaude Code
Review first review before installing

Open the source and read safety notes before installing.

Safety notes

  • Worktrees isolate working copies but share one git object database—understand fetch and prune impact.
  • Setting worktree.bgIsolation to none allows background agents to edit the shared checkout—use only with approval.
  • Sandbox write allowlists differ in worktrees—retest autonomous agents in linked checkouts.

Privacy notes

  • Each worktree may contain proprietary diffs and local env files—treat every checkout as sensitive.
  • Session transcripts under .claude may reference paths across worktrees—follow retention policy.
  • Shared machines need filesystem permissions so worktrees are not readable by other users.

Prerequisites

  • Git worktree familiarity and permission to create linked checkouts on developer machines.
  • Claude Code with worktree and background isolation features on your build.
  • Disk space for multiple checkouts and session transcripts.
  • Team rules for branch naming, merge authority, and worktree cleanup.

Schema details

Install type
copy
Reading time
8 min
Difficulty score
54
Troubleshooting
Yes
Breaking changes
No
Full copyable content
Create a worktree per parallel task, launch Claude Code from each checkout, use EnterWorktree or background isolation for agents, and prune .claude/worktrees/ when jobs finish.

About this resource

TL;DR

Git worktrees give each Claude Code session its own checkout so parallel agents do not stomp the same files. Create one worktree per task, launch Claude Code inside each path, use EnterWorktree or background isolation defaults, and prune .claude/worktrees/ when jobs complete.

Prerequisites & Requirements

  • {"task": "Worktree policy", "description": "Team agrees when worktrees are required versus branch switching"}
  • {"task": "Disk budget", "description": "Developers have space for multiple linked checkouts"}
  • {"task": "Isolation settings reviewed", "description": "worktree.bgIsolation defaults are documented"}
  • {"task": "Cleanup owner", "description": "Someone prunes stale worktrees weekly"}
  • {"task": "Sandbox retest", "description": "Autonomous agents were validated inside worktrees if used"}

Core Concepts Explained

Worktrees isolate working directories

Official worktree docs describe linked checkouts that share git history but keep working files separate—ideal for parallel Claude Code sessions on different tasks.

EnterWorktree moves agents into isolation

Background and subagent flows can call EnterWorktree so edits land in an isolated checkout instead of the shared working tree.

Background isolation can be relaxed deliberately

Release notes document worktree.bgIsolation: "none" for cases where background sessions must edit the primary checkout—treat that as a conscious exception.

Cleanup prevents disk drift

Background retention sweeps and manual pruning of .claude/worktrees/ keep orphan checkouts from accumulating after parallel runs.

Step-by-Step Implementation Guide

  1. Pick tasks that truly need parallelism. Use worktrees when two agents must edit different branches simultaneously.

  2. Create linked checkouts. Add a worktree per branch with clear directory names tied to ticket IDs.

  3. Launch Claude Code per worktree. Open CLI or Desktop sessions from each checkout path—not from the repo root alone.

  4. Enable isolation defaults. Keep background isolation on unless policy documents an approved worktree.bgIsolation: "none" exception.

  5. Use EnterWorktree in workflows. For background agents and subagents, confirm isolation before approving write tools.

  6. Retest sandbox rules. Validate autonomous bash policies inside worktrees when sandbox write allowlists differ from the main checkout.

  7. Prune on completion. Remove finished worktrees and clean .claude/worktrees/ during daily or weekly hygiene.

Parallel Session Checklist

  • {"task": "One worktree per task", "description": "No two active agents share one checkout unintentionally"}
  • {"task": "Branch ownership clear", "description": "Each worktree maps to one merge owner"}
  • {"task": "Isolation verified", "description": "EnterWorktree or bgIsolation policy matches the task risk"}
  • {"task": "Sandbox validated", "description": "Autonomous tools were tested in the linked checkout if used"}
  • {"task": "Cleanup scheduled", "description": "Stale worktrees are removed after jobs finish"}

Troubleshooting

Agent edited files in the wrong checkout

Confirm session cwd and re-dispatch from the intended worktree path.

Orphan directories under .claude/worktrees/

Prune after background jobs finish; release notes cover retention sweeps tied to background session lifecycle.

Sandbox writes fail only in worktrees

Review sandbox write allowlists and symlinked settings paths documented in release notes for worktree-specific fixes.

Shared checkout races despite worktrees

Check for sessions still running in the primary tree or bgIsolation set to none.

Source Verification Notes

Verified against official Claude Code documentation on 2026-06-15:

  • code.claude.com/docs/en/worktrees documents Claude Code worktree workflows including parallel session patterns and EnterWorktree behavior.
  • Public CHANGELOG.md entries describe worktree isolation guards for background subagents, .claude/worktrees/ cleanup, worktree.bgIsolation: "none", and sandbox write allowlist fixes for linked checkouts.

Duplicate Check

Checked content/guides and open pull requests for Claude Code worktrees, parallel sessions, and EnterWorktree workflows. Sandbox and dynamic workflow guides mention worktrees tangentially. This guide is the dedicated parallel-session worktree workflow.

References

  • Worktrees docs - https://code.claude.com/docs/en/worktrees
  • Agent view guide - agent-view-for-managing-multiple-claude-code-sessions
  • Desktop parallel sessions - claude-code-desktop-parallel-sessions-workflow

Source citations

Add this badge to your README

Show that Using Worktrees For Parallel Claude Code Sessions is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.

Listed on HeyClaude
[![Listed on HeyClaude](https://heyclau.de/badge/guides/using-worktrees-for-parallel-claude-code-sessions.svg)](https://heyclau.de/entry/guides/using-worktrees-for-parallel-claude-code-sessions)

How it compares

Using Worktrees For Parallel Claude Code Sessions side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.

FieldUsing Worktrees For Parallel Claude Code Sessions

Use git worktrees with Claude Code to run parallel sessions safely: EnterWorktree, background isolation, cleanup of .claude/worktrees/, and branch ownership rules that prevent conflicting edits.

Open dossier
Claude Code Desktop Parallel Sessions Workflow

Run parallel Claude Code Desktop sessions safely: separate windows or tabs per workstream, branch ownership rules, notification hygiene, and handoffs between foreground and background jobs.

Open dossier
Channels and Webhooks into Running Claude Code Sessions

A practical walkthrough of Claude Code channels: how an MCP-server channel pushes messages, alerts, and webhooks into a running session, how to install and enable Telegram, Discord, or iMessage, sender allowlists, and enterprise controls.

Open dossier
Compaction and Memory Hygiene for Long Claude Sessions

Guide to /compact, /memory, and CLAUDE.md hygiene for long Claude Code sessions: when to compact, what to store in memory, and avoiding stale context.

Open dossier
Trust
Install riskReview firstReview firstReview firstReview first
Notes Safety Privacy Safety Privacy Safety Privacy Safety Privacy
Categoryguidesguidesguidesguides
Sourcesource-backedsource-backedsource-backedsource-backed
AuthorkiannidevkiannidevJPette1783kiannidev
Added2026-06-152026-06-152026-06-052026-06-14
Platforms
Claude Code
Claude Code
Claude Code
Claude Code
Source repo
Safety notesWorktrees isolate working copies but share one git object database—understand fetch and prune impact. Setting worktree.bgIsolation to none allows background agents to edit the shared checkout—use only with approval. Sandbox write allowlists differ in worktrees—retest autonomous agents in linked checkouts.Parallel desktop sessions on the same branch can race—use worktrees or separate branches. Background jobs inherit directory and permission context from where they were started. Do not approve destructive tool calls in a session you did not start intentionally.Channel input is untrusted external content; treat incoming messages as data, not as instructions that should widen permissions. Events only arrive while the session is open; for unattended use, --dangerously-skip-permissions bypasses prompts and should be used only in trusted environments. Each channel keeps a sender allowlist; only paired/allowlisted IDs can push messages, and anyone who can reply can also approve permission relays if enabled, so allowlist only trusted senders.Compaction summarizes conversation history; verify summaries before relying on them for security-sensitive or release-critical decisions. Do not store secrets, credentials, or customer identifiers in `/memory` or CLAUDE.md. After compaction, re-validate repository state, test results, and open PR status before continuing destructive edits.
Privacy notesEach worktree may contain proprietary diffs and local env files—treat every checkout as sensitive. Session transcripts under .claude may reference paths across worktrees—follow retention policy. Shared machines need filesystem permissions so worktrees are not readable by other users.Desktop session titles and diffs may expose proprietary code during screen sharing. Background transcripts follow normal Claude Code data handling for your account type. Notification previews may leak ticket or branch names—configure OS privacy settings accordingly.A channel is an MCP server you configure with your own credentials; tokens are stored locally (for example ~/.claude/channels/telegram/.env). Incoming and outgoing messages pass through the third-party platform (Telegram, Discord, Apple Messages); review what data flows there. The iMessage channel reads your Messages database and requires Full Disk Access; understand that exposure before enabling it.Memory files persist across sessions and may be committed if stored in project scope. Compaction summaries can retain file paths, issue titles, and internal URLs—review before sharing session exports. Clear memory when offboarding contractors or rotating shared machines.
Prerequisites
  • Git worktree familiarity and permission to create linked checkouts on developer machines.
  • Claude Code with worktree and background isolation features on your build.
  • Disk space for multiple checkouts and session transcripts.
  • Team rules for branch naming, merge authority, and worktree cleanup.
  • Claude Code Desktop installed per the desktop quickstart for your platform.
  • Multiple concurrent tasks that benefit from parallel sessions rather than one long thread.
  • Team agreement on branch ownership, review, and merge authority.
  • Optional agent view access for monitoring background sessions.
  • Claude Code v2.1.80 or later, authenticated through claude.ai or a Console API key (channels are not available on Bedrock, Vertex AI, or Foundry).
  • Bun installed, since the channel plugins are Bun scripts.
  • On Team, Enterprise, or managed Console orgs, an admin must enable channels first.
  • An active long-running Claude Code session or multi-day task spanning several sessions.
  • A project with CLAUDE.md or memory files defining durable conventions.
  • Agreement on what may be written to user or project memory versus kept ephemeral.
  • Permission to run `/compact` and inspect resulting summaries before continuing work.
Install
claude --channels plugin:telegram@claude-plugins-official
Config
Citations
ClaimUnclaimedUnclaimedUnclaimedUnclaimed

Signals

Loading live community signals…

More like this, weekly

A short, calm digest of reviewed Claude resources. Unsubscribe any time.