Overview
Forge’s sandbox feature leverages git worktrees to create isolated development environments. This allows you to experiment with changes, test new features, or work on multiple branches simultaneously without affecting your main working directory.What are Git Worktrees?
Git worktrees allow you to have multiple working directories attached to the same repository. Each worktree:- Has its own checked-out branch
- Shares the same git history and objects
- Can be modified independently
- Doesn’t affect other worktrees or the main directory
Creating a Sandbox
Using the —sandbox Flag
Create a sandbox when starting Forge:What Happens
git rev-parse --is-inside-work-treegit rev-parse --show-toplevelUsage Examples
Experiment with Refactoring
Test a Risky Change
Parallel Development
Reusing Sandboxes
If a sandbox already exists, Forge will reuse it:Managing Sandboxes
List All Worktrees
Remove a Sandbox
Clean Up All Sandboxes
Advanced Usage
Sandbox with Specific Directory
Combine sandbox with directory flag:Working on Existing Branches
Create a sandbox from an existing branch:Integration with Conversations
Sandboxes work seamlessly with conversation management:Common Workflows
Safe Experimentation Workflow
# Inside Forge session
"Try implementing feature X using approach Y"
"Run tests to verify it works"
# Commit in sandbox
git add .
git commit -m "Implement feature X"
# Switch to main and merge
cd /path/to/main/repo
git merge try-new-approach
Multi-Feature Development
forge --sandbox feature-1 "Implement user authentication"
# In another terminal
forge --sandbox feature-2 "Add payment processing"
Troubleshooting
”Not in a git repository”
Ensure you’re starting Forge from within a git repository:“Directory exists but is not a git worktree”
A non-worktree directory has the same name:“Cannot create worktree in parent directory”
Repository is at filesystem root:- This is a limitation of the worktree approach
- Move your repository to a non-root location
Worktree Shows as “locked”
Best Practices
Naming Conventions
Use descriptive sandbox names:Clean Up Regularly
Remove unused sandboxes:Commit Before Removing
If the sandbox has valuable work:Use for Isolated Testing
Sandboxes are perfect for:- Trying new dependencies
- Testing destructive operations
- Experimenting with major refactors
- Working on proof-of-concepts