Separate Claude Code sessions with Git worktrees
Give parallel sessions separate files and branches while keeping their shared repository history.
Published · 1 source · Resume reading
Claude Code's worktree docs describe separate working folders and branches for parallel sessions [1]. Use one per task when two sessions would otherwise edit the same files.
Start the first isolated session
From your Git repository, use the documented example [1].
claude --worktree feature-authYou should see a worktree at .claude/worktrees/feature-auth on branch worktree-feature-auth [1]. In another terminal, use a different worktree name for the second task.
Keep generated worktrees out of status
Add this entry to your existing ignore file, preserving its other entries [1].
.claude/worktrees/Copy only the ignored files you need
A fresh checkout lacks untracked environment files. The documented .worktreeinclude mechanism copies files only when they match its patterns and are also Git-ignored [1].
Warning: this creates additional copies of your local environment files. Include secrets only when the isolated task needs them.
.env
.env.localReview work before cleanup
The docs say Claude prompts about keeping or removing a worktree when it contains changes or commits. Keep any work you still need [1]. Separate worktrees isolate file edits; they are not a substitute for reviewing the combined changes before merging.
Keep this guide
Filed under Claude Code, Dev tools
Sources
- Claude Code docs: worktreescode.claude.com