YBX.

Agents · · 简体中文

Claude Code worktrees: how to keep a parallel edit for review

Start Claude with --worktree for a second checkout. Before closing it, check both uncommitted edits and commits that only exist on its branch.

Start from the right baseline

Suppose a release branch is frozen and a colleague wants a documentation fix. From your Git repository, start claude --worktree docs-fix. In the new session check git status -sb and git log -1 before giving the agent the edit. An uncommitted draft in your first checkout is a poor starting reference: a separate worktree has its own working files and index.

What our two-checkout test showed

We checked the flag in Claude Code 2.1.333 and tested the underlying isolation with Git, without a model call. A temporary repository contained a committed note.txt with the word original. After git worktree add -b docs ../docs, we changed only the second copy to revised. The first still read original and had a clean status; only the second reported a modified file.

Hand the change to a reviewer

Inside the worktree, run git status --short to find local edits, then git log main..HEAD --oneline to find commits missing from main (substitute the actual target branch). A clean status alone can hide an entire committed fix. Retain the worktree if anything still needs review, record its branch name, and use git worktree list to locate it later.

Sources

Related reading