Skip to content

Worktrees Separate Files, Not Experiments

2026-07-22

You want two agents at once: one refactoring the data loader, one adding an ablation flag. Separate git worktrees give each its own directory and branch, so their edits cannot overwrite each other.

Claude Code has this built in. Per its worktrees documentation, claude --worktree ablation-flag creates .claude/worktrees/ablation-flag/ on a new branch named worktree-ablation-flag. A worktree is a fresh checkout, so install dependencies there, and add a .worktreeinclude file to copy gitignored files such as .env into each new one. The documentation is precise about scope: worktrees "isolate file edits."

Nothing else is isolated. The sessions share the repository's .git directory, and research code usually shares more than that: one GPU, one results directory at an absolute path, one dataset cache, one experiment-tracker project. Two runs that both write to runs/latest/ will overwrite each other's results, and no merge conflict will warn you.

The check.

  1. Run git worktree list and confirm each session sits in the path you expect.
  2. Search both branches for absolute output paths and fixed port numbers. Each experiment should write under a directory named for its branch or run id.
  3. After you merge both branches, run the full test suite and one short end-to-end run on the combined code. A clean merge shows that git found no textual conflict. It does not show that the two changes work together.

This note is about what parallel worktrees share. The opposite gap, what a new worktree lacks, changes a single result: gitignored data and .env files that .worktreeinclude does not list are simply absent. Check a worktree's inputs before you compare its numbers with your main checkout's.

Worktrees cost no tokens by themselves; each session you run in one does. Whether a second session pays off depends on how much of the work is truly independent and how much time you spend coordinating. When a second agent pays works through that trade with numbers you can check.

Claude Code worktrees documentation.