Introduction
Forge uses Git worktrees to provide complete isolation for every task attempt. This means each AI agent works in its own separate workspace, eliminating conflicts, race conditions, and the fear of breaking your main codebase.Think of it this way: Instead of one workspace where everyone fights for control, each task gets its own private sandbox to play in safely.
What are Git Worktrees?
Git worktrees allow you to check out multiple branches of the same repository simultaneously in different directories. Unlike traditional branching where you switch contexts in a single workspace, worktrees give you parallel, isolated environments.Traditional Git vs Git Worktrees
- Traditional Git
- Git Worktrees
Why Forge Uses Worktrees
The Problem Without Worktrees
Imagine running multiple AI agents on the same codebase: Result: Chaos, file conflicts, unpredictable behaviorThe Solution With Worktrees
Each task gets its own isolated environment: Result: Safe parallel execution, no conflicts, easy comparisonKey Benefits
Complete Isolation
Each attempt runs in its own directory. No risk of agents interfering with each other or your main codebase.
Parallel Execution
Run multiple agents simultaneously. Try Claude and Gemini on the same task at once.
Safe Experimentation
Your main branch stays pristine. Experiment fearlessly knowing you can always discard attempts.
Easy Comparison
Review different approaches side-by-side. See exactly what each agent produced.
Automatic Worktree Management
Forge handles all worktree operations automatically. You don’t need to know git worktree commands!What Forge Does For You
1
Task Creation
When you create a task, Forge prepares to create worktrees for attempts:
2
Attempt Start
When an agent starts working, Forge creates the worktree:
3
Agent Execution
The AI agent works in complete isolation:Your main code is never touched during execution.
4
Review
You review changes in the isolated worktree:
5
Merge or Discard
Choose to merge good work or discard bad attempts:
6
Cleanup
Forge removes worktrees when done:
Worktree Lifecycle
Worktree States
| State | Description | Location |
|---|---|---|
| Pending | Task created, no worktree yet | N/A |
| Active | Agent working in worktree | .forge/worktrees/task-N-attempt-M/ |
| Review | Work complete, awaiting review | .forge/worktrees/task-N-attempt-M/ |
| Merged | Changes merged to main, worktree removed | Deleted |
| Discarded | Attempt rejected, worktree removed | Deleted |
Best Practices
DO ✅
Let Forge manage worktrees automatically
Let Forge manage worktrees automatically
Forge handles all worktree operations. Don’t create/remove worktrees manually unless you know what you’re doing.
Review changes before merging
Review changes before merging
Always check what the agent did before merging:
Use multiple attempts for important tasks
Use multiple attempts for important tasks
Try different agents on critical features:
Clean up old attempts
Clean up old attempts
Discard failed or unwanted attempts promptly:
DON’T ❌
Don’t manually modify worktree files while an agent is running. Let the agent complete its work first.
Don’t delete
.forge/worktrees/ manually. Use forge task discard or forge task merge to properly clean up.Don’t commit directly in worktrees. Forge manages all git operations. Manual commits can break the workflow.
Troubleshooting
Worktree Already Exists
Disk Space Issues
Worktrees create full copies of your working directory. For large repos:Locked Worktrees
Advanced: Manual Worktree Operations
You rarely need to do this! Forge handles everything automatically. But if you need manual control:

