Context and file isolation solve different problems

Context isolation protects the main session: a subagent reads code, tests, or logs and returns a concise report. Worktree isolation protects files, branch, and diff: changes happen in a separate working copy.

One type of isolation does not replace the other. A clean context does not make a bad diff safe, and a worktree does not make conclusions true automatically.

IsolationProtectsChoose it when
Context isolationMain session contextA lot of reading without editing
Worktree isolationFiles, branch, and diffExperimental or parallel changes
BothContext and working copyBroad research plus risky experiment
NeitherNo additional overheadSmall, understood change in a safe area

Context isolation for research

  • Delegate architecture search, log analysis, docs, or missing-test discovery.
  • Return conclusions, file:line, checks, and limits.
  • Do not forward every intermediate search result.
  • Do not mistake isolation for truth.
  • Do not isolate a tiny one-file step without a real benefit.

Worktree isolation for changes

  1. Create a worktree for the experimental branch.
  2. Check directory cleanliness and branch identity.
  3. Run the session in the separate copy.
  4. Inspect diff and tests.
  5. Keep, transfer, or remove the result only after the owner decides.

Combined scenario

Sequence for a risky experiment
1. Context isolation: research the flow and return an evidence-backed report.
2. Worktree isolation: add a regression test or try a fix.
3. Main session: compare findings, diff, and tests.
4. Owner: decide what may move to the main branch.

Quick selection rule

  • Many reads without edits — context isolation.
  • Files will change — worktree isolation.
  • Broad research plus risky experiment — both.
  • Small safe change — perhaps neither.

Canonical lesson source · JavaRush

Open JavaRush material