Isolate risky work in a worktree
Experiment freely on a branch without touching your main checkout.
A git worktree is a second working copy of your repo on its own branch. The agent can refactor freely there while your primary checkout stays clean and buildable.
Why it matters
It’s the safe way to let an agent run a large or speculative change. If it goes wrong, you delete the worktree — your main checkout never moved. If it goes right, you merge the branch. Either way you keep working in your primary checkout in parallel.
How to improve
- For large refactors or anything you might throw away, start the session in a dedicated worktree and branch.
- Combine with plan mode: review the plan, then let the agent execute it in the isolated worktree.
- Pair worktrees with subagents when you want several independent changes explored at once without them colliding.