A tool for creating isolated Git environments in Docker containers to enable parallel features, experiments, and fixes without cluttering your main workspace.
CapsulateRepo provides containerized Git environments with proper isolation. It allows developers to work on multiple isolated branches simultaneously without the risk of accidental changes leaking between branches. The isolation is achieved through Docker containers, each with its own Git state.
CapsulateRepo uses OverlayFS to create efficient, isolated environments without duplicating files:
βββββββββββββββββββββββββββββββββββββββ
β CONTAINER VIEW β <- What you see when working
βββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββββββββββββββ β
β β Your Changes (Diff) β β <- Only your modifications
β βββββββββββββββββββββββββββββββ€ β are stored here
β β β β
β β βββββββββββββββββββββββ β β
β β β Base Repository β β β <- Read-only, shared across
β β β (Read-only) β β β all containers
β β βββββββββββββββββββββββ β β
β β β β
β βββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββ
When you open a file, you see a merged view that combines:
- The original file from the base repository (bottom layer)
- Any changes you've made (upper layer)
Changes you make are only stored in the diff layer, while the base repository remains untouched. This provides several benefits:
CapsulateRepo implements a sophisticated dependency management system that balances standardization with flexibility:
βββββββββββββββββββββββββββββββββββββββ
β CONTAINER DEPENDENCIES β <- Container-specific deps
βββββββββββββββββββββββββββββββββββββββ€ (for experimentation)
β β
β βββββββββββββββββββββββββββββββ β
β β TEAM DEPENDENCIES β β <- Team/feature-specific deps
β βββββββββββββββββββββββββββββββ€ β (shared among a team)
β β β β
β β βββββββββββββββββββββββ β β
β β β CORE DEPENDENCIES β β β <- Organization-wide deps
β β β β β β (shared by all containers)
β β βββββββββββββββββββββββ β β
β β β β
β βββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββ
How it works:
-
Core Dependencies: Shared across all containers
- Ensures standardization across the organization
- Reduces duplication and saves storage
- Examples: foundational libraries, testing frameworks, core utilities
-
Team Dependencies: Shared within specific teams or features
- Balances standardization with team-specific needs
- Enables team autonomy while maintaining consistency
- Examples: UI frameworks for frontend teams, data processing libraries for backend teams
-
Container Dependencies: Specific to individual containers
- Allows full experimentation freedom
- Can override or add to team/core dependencies
- Perfect for testing new libraries, version upgrades, or experimental features
This approach gives you the perfect balance between standardization, efficiency, and flexibility - critical for both human and AI-driven development workflows.
-
Parallel experimentation: Multiple AI agents or humans can work on the same codebase simultaneously without interference
-
Efficient storage: Only store the changes, not entire copies of repositories
-
Safe isolation: Changes in one environment never leak into another
-
Visibility: External tools like VS Code can seamlessly work with these environments by connecting to the workspace directory
-
Context switching: Instantly switch between different isolated environments without the overhead of git stashing or branch switching
-
Dependency isolation: Each environment can have its own dependencies without conflicts
This architecture is particularly powerful for human-in-the-loop development where:
- AI agents can suggest changes in isolated environments
- Humans can review and modify those changes
- Multiple experiments can run concurrently
- Teams can collaborate without stepping on each other's work
External tools can access these environments by:
- Opening the filesystem at
<workspace-dir>/.capsulate/workspaces/<agent-id> - Using the
git-capsulate execcommand to run operations inside the container - Using VS Code's Remote Container extension to connect directly to the container
CapsulateRepo enables a powerful orchestration model where a single human can direct multiple AI agents:
βββββββββββββββββββββββββββββββ
β HUMAN ORCHESTRATOR β
β β
β βββββββ βββββββ βββββββ β
β βView β βEdit β βMergeβ β
β βββββββ βββββββ βββββββ β
βββββ¬ββββββββββ¬ββββββββββ¬βββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β AI AGENT 1 β β AI AGENT 2 β β AI AGENT 3 β
β β β β β β
β βββββββββββββ β β βββββββββββββ β β βββββββββββββ β
β βContainer 1β β β βContainer 2β β β βContainer 3β β
β βββββββββββββ β β βββββββββββββ β β βββββββββββββ β
ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ
β β β
βββββββββββ¬ββββββββββ΄ββββββββββ¬ββββββββββ
β β
βββββββββΌββββββββ βββββββββΌββββββββ
β DIFF LAYER β βVERSION CONTROLβ
β(Minimal Size) β β (Checkpoints) β
βββββββββ¬ββββββββ βββββββββββββββββ
β
βββββββββΌββββββββ
βBASE REPOSITORYβ
β (Read-only) β
βββββββββββββββββ
Orchestration Benefits:
-
Human as Conductor:
- Supervise multiple AI agents from a single dashboard
- Review, approve, or redirect each agent's work
- Gameified management of small, focused AI teams
-
Minimal Resource Overhead:
- Each agent only stores its changes (diffs)
- Run 5-10 agents with barely more storage than a single repo
- No need for multiple full repository copies
-
Checkpoint & Rollback:
- Version control built into every environment
- Roll back AI experiments that went wrong
- Preserve successful approaches for future use
- Time-travel between different versions of AI output
-
Scale Without Complexity:
- Start with 2-3 agents for tight control
- Scale to dozens when needed for larger projects
- Same interface regardless of team size
Example Orchestration Workflows:
-
Feature Development Pipeline
- Agent 1: Working issue 102 new feature
- Agent 2: Updating deps to see if breaking change (Impacts no one but Agent 2)
- Agent 3: Writing comprehensive tests for ITDD (Incrimental Test Driven Development)
- Human: Orchestrates, reviews, and approves each stage
-
Competing Solutions Approach
- Assign the same task to multiple agents with different approaches
- Review all solutions in parallel
- Choose the best implementation or merge ideas
- All with minimal switching cost or context loss
-
Incremental Team Expansion
- Start with 1-2 trusted agents
- Add specialized agents as needed
- Each agent maintains its own branch
- Human maintains control without cognitive overload
This orchestration model makes building with AI more like a strategy game - you direct the team, make the decisions, and maintain creative control while leveraging multiple specialized AI agents.
- Container creation and management
- SSH authentication sharing
- Basic command execution
- Container lifecycle management
- Git repository cloning
- Branch creation and management
- Status tracking and visualization
- Repository sharing between containers
- Three-tier dependency management (core, team, container levels)
- Efficient file storage with OverlayFS
- Dependency isolation and overrides
- Team-based dependency sharing
- Background syncing from central branches
- Conflict detection and management
- Scaling to many containers efficiently
- Resource usage monitoring
- Container health checks
- Branch activity metrics
Each phase includes comprehensive tests that validate the implemented functionality:
tests/phase1-core-infrastructure.sh: Tests for container creation, destruction, and command executiontests/phase2-git-operations.sh: Tests for Git isolation, branch management, and status reportingtests/phase3-dependency-management.sh: Tests for dependency management and OverlayFS functionality
Detailed analysis documents for each phase are available in the docs/ directory:
docs/phase1-analysis.md: Core infrastructure design and implementationdocs/phase2-analysis.md: Git operations and branch management implementationdocs/phase3-analysis.md: Dependency and file system management architecture
git-capsulate create my-feature --repo=git@github.com:user/repo.git --branch=main --dependency-level=team --team-id=frontend --use-overlay=truegit-capsulate exec my-feature "git status"git-capsulate branch my-feature new-branch -c
git-capsulate checkout my-feature maingit-capsulate add-dep my-feature lodash
git-capsulate list-deps my-featuregit-capsulate create-team frontend
git-capsulate add-team-dep frontend reactgit-capsulate overlay-status my-featuregit-capsulate destroy my-feature- Docker installed and running
- Go 1.21+ (for building from source)
- Git
- SSH keys configured for Git operations
-
Clone this repository:
git clone https://github.com/your-org/CapsulateRepo.git cd CapsulateRepo -
Make the script executable:
chmod +x git-capsulate
-
(Optional) Add to your PATH for global access:
export PATH="$PATH:$(pwd)"
./git-capsulate create my-feature./git-capsulate exec my-feature "git clone git@github.com:your-org/your-repo.git repo"
./git-capsulate exec my-feature "cd repo && git checkout -b feature/my-feature"
./git-capsulate exec my-feature "cd repo && echo 'New feature code' > feature.txt"
./git-capsulate exec my-feature "cd repo && git add feature.txt && git commit -m 'Add new feature'"./git-capsulate destroy my-feature./git-capsulate create deps-test --dependency-level=container --override-deps="lodash,express"./git-capsulate create overlay-test --use-overlay=true- Make sure tests pass for your changes
- Follow Go coding conventions
- Add tests for new functionality
- Update documentation as needed
Apache 2.0