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.
| Isolation | Protects | Choose it when |
|---|---|---|
| Context isolation | Main session context | A lot of reading without editing |
| Worktree isolation | Files, branch, and diff | Experimental or parallel changes |
| Both | Context and working copy | Broad research plus risky experiment |
| Neither | No additional overhead | Small, 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
- Create a worktree for the experimental branch.
- Check directory cleanliness and branch identity.
- Run the session in the separate copy.
- Inspect diff and tests.
- Keep, transfer, or remove the result only after the owner decides.
Combined scenario
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