Clone Plugin
The clone plugin provides workspace isolation by creating full git clones of your repository. Each agent session gets a completely independent copy, ideal for experiments that require maximum isolation.Overview
Unlike worktrees which share the git object database, the clone plugin creates full repository copies for each session. This provides complete independence at the cost of more disk space and slower creation.Use the clone plugin when you need complete isolation between workspaces, such as testing destructive operations or maintaining fully independent git histories.
Configuration
Configure the clone plugin in youragent-orchestrator.yaml:
Configuration Options
Base directory where clones will be created. Path supports
~ expansion for home directory.Clones are organized as: {cloneDir}/{projectId}/{sessionId}/How It Works
- Get Remote URL: Retrieves the
originremote URL from the source repository - Clone with Reference: Uses
git clone --referenceto speed up cloning by sharing objects with the source repo - Create Branch: Checks out the default branch and creates a new feature branch
- Post-Create Hooks: Runs custom setup commands after clone creation
Usage Example
Requirements
Path Segment Safety
Project IDs and session IDs must contain only safe characters:a-z, A-Z, 0-9, _, -
This prevents directory traversal attacks and ensures filesystem compatibility.
Features
Workspace Lifecycle
Create- Retrieves remote URL from source repository
- Clones with
--referenceflag for faster cloning (shares objects with source) - Clones the default branch initially
- Creates and checks out the feature branch
- Runs post-create hooks
- Cleans up partial clones on failure
- Recursively deletes the clone directory
- Uses
rmSyncwith{ recursive: true, force: true }
- Lists all clones for a project by reading directory contents
- Queries each clone for its current branch using
git branch --show-current - Skips corrupted clones with a warning message
- Checks if clone path exists and is a valid git working tree
- Uses
git rev-parse --is-inside-work-tree - Has a 30-second timeout
- Recreates a workspace after it was destroyed or corrupted
- Clones fresh from remote
- Checks out the feature branch (creates if needed)
- Cleans up on failure
Clone with Reference
The
--reference flag creates a clone that borrows objects from the source repository, significantly speeding up the clone operation and saving disk space initially.Post-Create Hooks
Run custom commands after clone creation:Troubleshooting
Error: Workspace path already exists
Error: Workspace path already exists
The plugin fails early if the destination path already exists to avoid accidentally deleting a pre-existing workspace.Solution: Destroy the existing workspace first:
Clone failed with network error
Clone failed with network error
The clone plugin requires network access to the remote repository.If cloning from a local source, ensure the For offline work, consider using the worktree plugin instead.
origin remote is accessible:Failed to checkout branch
Failed to checkout branch
If the feature branch exists on remote but checkout fails, the plugin:
- Tries to checkout the existing branch
- Falls back to creating a new branch with
-b - Cleans up the orphaned clone on failure
Corrupted clone in list output
Corrupted clone in list output
If a clone directory exists but isn’t a valid git repository, the Solution: Manually remove corrupted clones:
list command logs a warning and skips it:Out of disk space
Out of disk space
Each clone is a full repository copy. For multiple sessions, this can consume significant disk space.Solutions:
- Use the worktree plugin instead (shares git objects)
- Clean up old clones regularly
- Use
git gcto compress repository objects - Increase available disk space
Advanced Configuration
Clone Directory Structure
Clones are organized by project and session:Comparison with Worktree Plugin
| Feature | Clone | Worktree |
|---|---|---|
| Disk usage | High (full copy) | Low (shared objects) |
| Creation speed | Slower | Fast |
| Independence | Fully independent | Shared git database |
| Use case | Isolated experiments | Parallel branches |
| Offline support | Limited (needs remote) | Better (uses local refs) |
When to Use Clone vs Worktree
Use Clone when:- You need complete isolation between sessions
- Testing destructive git operations
- Working with different git configurations per session
- Maintaining independent git histories
- Working on multiple branches in parallel
- Disk space is limited
- Faster workspace creation is needed
- Shared git object database is acceptable
Performance Considerations
Clone Speed
The--reference flag significantly speeds up cloning:
- Without reference: Full object transfer (~1-2 minutes for large repos)
- With reference: Only new objects copied (~5-10 seconds)
Disk Usage
Example for a typical Node.js project:- Source repository: 500 MB
- Clone without reference: 500 MB per clone
- Clone with reference: 50-100 MB per clone (initially)
- Worktree: 10-20 MB per worktree
Over time, clones with
--reference will grow as they create their own objects for new commits.Security Considerations
Source Code
Source:packages/plugins/workspace-clone/src/index.ts