Product case study · October 27, 2026

Claude Code Worktrees: Review One Isolated Edit

Give Claude Code a separate Git checkout, verify one edit against an answer key, and bring back only the reviewed change in a disposable lab.

Reading time
7 min
Checked
Oct 27, 2026
Two paper file cards on separate charcoal branches, with an ochre inspection lens over the blue workspace
Separate the edit from your original checkout, then review exactly what comes back.
Bottom line

Use a separate checkout for the agent, inspect both directories, and transfer a change only after its bytes and scope pass your checks.

You want Claude Code to try an edit without disturbing the files you are already reviewing. Give it a separate Git worktree, then inspect the result before bringing it back. This lab uses one text file so the acceptance check stays small enough to understand completely.

Sources checked October 27, 2026. We tested the local Git setup, comparisons, patch transfer and cleanup with a manually simulated edit, including negative checks. We did not run an authenticated Claude session. The agent step is a documented workflow to try, not a reported model success.

You need Bash, Git with a working commit identity, and an installed, authenticated Claude Code. Use the synthetic fixture below in a new temporary directory. No remote repository or push is needed.

Set up two checkouts and an answer key

Git’s worktree manual describes linked working directories that share a repository while keeping their own HEAD and index. We will create the worktree explicitly so its starting commit, branch and directory are visible before Claude starts.

Run this in a terminal outside your working projects:

lab_root=$(mktemp -d /tmp/claude-worktree-lab.XXXXXX)
mkdir "$lab_root/project" "$lab_root/evidence"
cd "$lab_root/project"
git init -q
printf 'Release: Lantern\nReview: pending\n' > release.txt
git add release.txt
git commit -m "Record release checklist baseline"

Stop if the commit fails. Fix your local Git identity before continuing. Then record the original and the exact intended result outside both checkouts:

cp release.txt "$lab_root/evidence/original.txt"
printf 'Release: Lantern\nReview: ready\n' > "$lab_root/evidence/expected.txt"
git rev-parse HEAD > "$lab_root/evidence/baseline-commit.txt"
git worktree add -b review-copy "$lab_root/review" HEAD
git worktree list
printf 'Lab root: %s\n' "$lab_root"

The listing should contain project and review. The second checkout must be on review-copy, starting at the baseline commit. Keep the printed lab-root path for later. The answer key expresses our editorial decision: only the review status should change; the release name and final newline must stay intact.

A worktree separates checked-out files. It does not restrict a process to that folder, revoke network access or isolate credentials. Keep your normal permission controls. The evidence directory is outside the requested edit scope, but it is not protected from everything running as your user.

Start Claude in the review directory

From the same terminal:

cd "$lab_root/review"
pwd
git branch --show-current
claude --version > "$lab_root/evidence/cli-version.txt"
claude

Before launching, confirm the directory ends in /review and the branch is review-copy. If Claude requests folder trust, inspect that path. Review any tool approvals rather than bypassing them.

Submit this prompt:

Read release.txt in this working directory. Change only "Review: pending"
to "Review: ready". Preserve the release name and final newline.
Use a file-edit tool. Do not change any other file, inspect sibling folders,
run shell commands, create commits, switch branches, or contact a remote.
Stop after the edit and report which file changed.

The task prompt defines what you want; it does not enforce filesystem permissions. Decline a proposed action outside the requested scope. Exit the session after the edit so no agent is still working while you inspect or transfer it.

Anthropic’s common workflows guide also documents claude --worktree feature-auth for starting a session in a separate checkout. The CLI reference places those managed checkouts under .claude/worktrees/. This exercise already created its checkout with Git: launch ordinary claude there, without adding --worktree and creating another directory.

Verify the result from outside the agent session

Continue in the same shell after Claude exits. If you opened a new terminal, first set lab_root to the exact path printed earlier. Run the following checks individually and stop at any failure:

cmp "$lab_root/evidence/expected.txt" "$lab_root/review/release.txt"
cmp "$lab_root/evidence/original.txt" "$lab_root/project/release.txt"
git -C "$lab_root/review" diff HEAD -- release.txt
git -C "$lab_root/review" status --short --untracked-files=all
git -C "$lab_root/project" status --short --untracked-files=all
git -C "$lab_root/review" rev-parse HEAD > "$lab_root/evidence/review-commit.txt"
cmp "$lab_root/evidence/baseline-commit.txt" "$lab_root/evidence/review-commit.txt"
git -C "$lab_root/project" rev-parse HEAD > "$lab_root/evidence/project-commit.txt"
cmp "$lab_root/evidence/baseline-commit.txt" "$lab_root/evidence/project-commit.txt"

Each cmp should exit zero with no output. The review checkout should show exactly one modified path, release.txt; the original checkout’s status should be empty. The diff should contain one replacement: pending becomes ready. Both commit comparisons should pass because this exercise asked Claude not to commit.

These checks answer different questions. The first comparison verifies the requested edit. The second verifies the original bytes. Status catches extra untracked or modified paths, while comparing commit IDs catches an unexpected commit that a clean status would hide. Git status does not list ignored files by default; this tiny fixture has no project ignore rules, but global excludes can still hide files. Investigate unexpected artifacts rather than treating status as a security audit.

If any check fails, leave both directories intact and inspect what happened. An agent’s completion message is not a substitute for these observations.

Transfer only the reviewed patch

After every check above passes, save and inspect the patch:

git -C "$lab_root/review" diff --binary HEAD -- release.txt \
  > "$lab_root/evidence/review.patch"
cat "$lab_root/evidence/review.patch"

Require a nonempty patch touching only release.txt, with the single intended replacement. Do not apply a patch whose contents you have not reviewed. Then:

cd "$lab_root/project"
git apply --check "$lab_root/evidence/review.patch" && \
  git apply "$lab_root/evidence/review.patch"
cmp "$lab_root/evidence/expected.txt" release.txt
git diff --check
git diff -- release.txt
git status --short --untracked-files=all

Stop if the apply or comparison fails. Otherwise, require only the intended release.txt change, then make the local lab commit:

git add release.txt
git commit -m "Accept reviewed checklist update"
git status --short

The status should now be empty. This patch-based transfer is deliberately limited to the one tracked text file in our exercise. For a real feature with new files, renames or several commits, design a broader review and integration process rather than copying these exact path filters.

Retain the worktree until cleanup is safe

Our review checkout still contains its uncommitted edit. Git’s worktree documentation says ordinary removal refuses a dirty checkout. Preserve that protection: do not add --force just to finish the lab.

After confirming the accepted file is committed in project, preserve the reviewed state on its own branch too:

cd "$lab_root/review"
git add release.txt
git commit -m "Preserve reviewed worktree result"
git status --short

Proceed only if status is empty and Claude has exited. Remove the separate working directory from the original checkout:

cd "$lab_root/project"
git worktree remove "$lab_root/review"
git worktree list
git branch --list review-copy
cmp "$lab_root/evidence/expected.txt" release.txt

The review directory should disappear from the worktree listing. Its branch should remain, and the accepted file should still match. Keep the lab and evidence until you have reviewed the outcome; removing the worktree is separate from deleting its branch.

Diagnose a failed isolation check

ObservationWhat to inspect next
Worktree creation failsConfirm the baseline commit exists and the requested branch or directory is not already in use. Choose a fresh lab rather than forcing reuse.
Original file changes before transferCheck the directory where Claude ran and the paths its tools used. Record the failed isolation check.
Review status has extra pathsInspect each file and any local hooks or customizations before continuing.
Commit comparison failsReview the new commits; do not treat this as the uncommitted-edit exercise any longer.
Patch check failsKeep the patch, inspect the original checkout and resolve the mismatch before applying anything.
Worktree removal refusesInspect modified, untracked and ignored files. Keep anything needed before attempting ordinary removal again.

For a real coding task, replace the byte answer key with the tests and review criteria for that feature. The lesson on defining concrete acceptance checks helps decide what evidence you need before accepting an agent’s change.

Primary sources checked

All checked October 27, 2026:

Put this to work

Distinguish a separate Git checkout from a security sandbox.

Try

Ask Claude to update one synthetic release checklist in a disposable worktree.

Prove it worked

Compare exact bytes, verify the original is unchanged, and inspect the patch before applying it.

Keep in view

  • Start from a committed baseline and give Claude its own working directory.
  • Check the edited file, changed paths and original checkout independently.
  • Keep the worktree until the reviewed change has been transferred and checked.
Learn the workflow: Define acceptance checks for AI coding work