Git Worktrees
AgentLoop leverages Git worktrees to enable true parallel development. Each worktree is a separate working directory linked to the same repository, allowing multiple agents to work on different branches simultaneously without conflicts.
What Are Worktrees?
Git worktrees allow you to have multiple working directories from a single repository. Each worktree has its own branch, but they all share the same Git history and objects.
Main Repository (.git)
│
├── Main Working Directory (main branch)
│
├── .worktrees/
│ ├── feature-auth/ ← Agent 1 working here
│ │ └── (branch: feature/auth)
│ │
│ ├── feature-api/ ← Agent 2 working here
│ │ └── (branch: feature/api)
│ │
│ └── bugfix-login/ ← Agent 3 working here
│ └── (branch: bugfix/login)Benefits
| Benefit | Description |
|---|---|
| No Merge Conflicts During Work | Each agent has its own isolated working directory |
| True Parallelism | Multiple agents can compile, test, and modify code simultaneously |
| Branch Isolation | Changes in one worktree don’t affect others until merged |
| Efficient Storage | Worktrees share the same Git objects, minimizing disk usage |
Enabling Worktrees
Configure worktrees in your project config:
[orchestrator]
use_worktrees = true
worktrees_dir = ".worktrees" # Directory for worktrees (relative to project)
cleanup_worktrees_on_complete = false # Auto-cleanup when tasks completeOr set via environment variables:
export AGENTLOOP_USE_WORKTREES=true
export AGENTLOOP_WORKTREES_DIR=".worktrees"
export AGENTLOOP_CLEANUP_WORKTREES=falseWorktree Commands
Interactive Mode
Manage worktrees in interactive mode:
| Command | Description |
|---|---|
/worktrees | Open interactive worktree management view |
/worktrees list | List all active worktrees |
/worktrees status | Show worktree status summary |
/worktrees help | Display worktree usage guide |
How It Works
When the orchestrator runs with worktrees enabled:
- Task Assignment - A task is assigned to an available agent
- Worktree Creation - A new worktree is created with a branch for the task
- Agent Execution - The agent works in the isolated worktree
- Commit & Push - Changes are committed to the task branch
- PR Creation - A pull request is created (if configured)
- Cleanup - Worktree is optionally removed after completion
Configuration Options
| Option | Default | Description |
|---|---|---|
use_worktrees | false | Enable git worktrees for parallel development |
worktrees_dir | .worktrees | Directory for worktrees (relative to project root) |
cleanup_worktrees_on_complete | false | Automatically remove worktrees when tasks complete |
Example Workflow
# Enable worktrees in config
> /config show
# Start orchestrator with multiple parallel agents
> /orchestrator run
# The orchestrator will:
# 1. Pick up 3 independent tasks
# 2. Create 3 worktrees (one per task)
# 3. Assign an engineer agent to each
# 4. Process tasks in parallel
# View active worktrees
> /worktrees list
# Output:
# .worktrees/feature-auth (branch: feature/auth) - Task 3
# .worktrees/feature-api (branch: feature/api) - Task 4
# .worktrees/bugfix-login (branch: bugfix/login) - Task 5Remote Development
Worktrees are particularly useful for remote development scenarios:
- SSH into a server
- Start the orchestrator with worktrees enabled
- Disconnect and reconnect later
- Work directly on mounted worktrees from your local IDE
This allows you to edit code locally while agents work remotely.
Best Practices
- Use meaningful branch names - Worktrees create branches based on task names
- Enable auto-cleanup for temporary work - Set
cleanup_worktrees_on_complete = truefor short-lived tasks - Keep worktrees for code review - Disable cleanup to review agent changes before merging
- Monitor disk space - Multiple worktrees can consume significant disk space for large repos
Worktrees share Git objects, so storage overhead is minimal. However, each worktree is a full working copy, so project files are duplicated.
Troubleshooting
Worktree not created:
- Ensure
use_worktrees = truein your config - Verify you’re in a git repository
Permission errors:
- Check that the worktrees directory is writable
- Ensure git has access to create branches
Cleanup issues:
- Manually remove worktrees:
git worktree remove .worktrees/<name> - List all worktrees:
git worktree list