Skip to main content

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

Problem: Context switching, conflicts, can’t run multiple agents simultaneously

Why Forge Uses Worktrees

The Problem Without Worktrees

Imagine running multiple AI agents on the same codebase: Result: Chaos, file conflicts, unpredictable behavior

The Solution With Worktrees

Each task gets its own isolated environment: Result: Safe parallel execution, no conflicts, easy comparison

Key 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


Best Practices

DO ✅

Forge handles all worktree operations. Don’t create/remove worktrees manually unless you know what you’re doing.
Always check what the agent did before merging:
Try different agents on critical features:
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

Solution:

Disk Space Issues

Worktrees create full copies of your working directory. For large repos:

Locked Worktrees

Solution:

Advanced: Manual Worktree Operations

You rarely need to do this! Forge handles everything automatically. But if you need manual control:

Next Steps

Tasks & Attempts

Learn about task lifecycle and attempts

AI Agents

Understand the 8 AI coding agents

Creating Tasks

Start creating tasks with worktree isolation

Troubleshooting

Fix common worktree issues