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.
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.
# You have ONE working directory~/my-project/# Switch branches (context switching)git checkout feature-a # Work on feature Agit checkout feature-b # Oops, lost context of feature A# Can only work on one branch at a time# AI agents would conflict with each other
Problem: Context switching, conflicts, can’t run multiple agents simultaneously
Copy
# You have MULTIPLE working directories~/my-project/ # Main workspace.forge/worktrees/task-1/ # Feature A workspace.forge/worktrees/task-2/ # Feature B workspace.forge/worktrees/task-3/ # Bug fix workspace# All share the same .git repository# All exist simultaneously# No conflicts between tasks
Solution: Parallel development, zero conflicts, multiple agents working at once
When you create a task, Forge prepares to create worktrees for attempts:
Copy
# You do thisforge task create --title "Add authentication"# Forge prepares (but doesn't create worktree yet)# Waits for actual attempt execution
2
Attempt Start
When an agent starts working, Forge creates the worktree:
Copy
# You do thisforge task attempt --llm claude# Forge does this automatically$ git worktree add .forge/worktrees/task-42-attempt-1 -b task-42-attempt-1$ cd .forge/worktrees/task-42-attempt-1$ # Agent works here in isolation
3
Agent Execution
The AI agent works in complete isolation:
Copy
Main repo: Worktree:~/my-project/ .forge/worktrees/task-42-attempt-1/├── src/ ├── src/│ └── app.js (unchanged) │ └── app.js (modified by agent)├── tests/ ├── tests/│ └── ... (unchanged) │ └── auth.test.js (new file!)
Your main code is never touched during execution.
4
Review
You review changes in the isolated worktree:
Copy
# See what the agent changedforge task diff 42 1# Compare multiple attemptsforge task compare 42
5
Merge or Discard
Choose to merge good work or discard bad attempts:
Copy
# Merge attempt 1 into mainforge task merge 42 1# Or discard attempt 2forge task discard 42 2
6
Cleanup
Forge removes worktrees when done:
Copy
# Automatic cleanup after merge/discard$ git worktree remove .forge/worktrees/task-42-attempt-1
# List all worktreesgit worktree list# Remove the stuck worktreeforge task cleanup 42# Or manually remove itgit worktree remove .forge/worktrees/task-42-attempt-1
You rarely need to do this! Forge handles everything automatically. But if you need manual control:
Copy
# Create a worktree manuallygit worktree add .forge/worktrees/my-experiment -b feature-xyz# Work in the worktreecd .forge/worktrees/my-experiment# Make changes...# List all worktreesgit worktree list# Remove when donecd ../..git worktree remove .forge/worktrees/my-experiment