Introduction
I wanted to explore something deeper than just prompting an AI coding assistant.
What happens if we run multiple AI agents at the same time on the same repository?
Not sequentially.
Not switching branches manually.
But truly in parallel, with isolation and full observability.
This post documents how I designed a local parallel AI coding lab using:
- Claude Code CLI
- Git worktrees
- tmux
- WSL Ubuntu
The goal was not experimentation for novelty. The goal was safe orchestration.
Prerequisite: Configuring the Anthropic API Key
Claude Code CLI requires an Anthropic API key to function.
Inside WSL Ubuntu, set the key as an environment variable:
export ANTHROPIC_API_KEY=your_api_key_here
To persist it across terminal sessions, add it to your shell profile:
echo 'export ANTHROPIC_API_KEY=your_api_key_here' >> ~/.bashrcsource ~/.bashrc
Verify the key is available:
echo $ANTHROPIC_API_KEY
Important considerations:
• Do not commit the API key into your repository
• Do not hardcode it inside scripts
• Treat it as a secret
• In production workflows, inject it via environment configuration or a secure secret management system
Claude CLI automatically reads the ANTHROPIC_API_KEY environment variable at runtime.
The Engineering Problem
If you simply open two terminals and run AI in the same folder:
- Files get overwritten
- Branch state becomes inconsistent
- Commits collide
- Debugging becomes painful
Parallel AI requires isolation.
So I designed the system around one rule:
Each AI agent must behave like an independent developer.
Folder Design
Instead of duplicating the repository multiple times, I used a single base repository and created lightweight working directories.
My structure looks like this:
~/dev/base-repo~/ai-sessions/alpha~/ai-sessions/beta~/ai-sessions/gamma
Notice:
- No reuse of generic naming
- No cloning multiple times
- Clear separation of session workspaces
Step 1: Prepare Base Repository
mkdir -p ~/devcd ~/devgit clone https://github.com/yourname/yourproject.git base-repocd base-repogit fetch origin
This contains the full Git history.
Step 2: Create Isolated AI Workspaces
Create session directory root:
mkdir -p ~/ai-sessions
Now create independent branches and worktrees.
Session Alpha
git worktree add ~/ai-sessions/alpha -b feature/alpha origin/main
Session Beta
git worktree add ~/ai-sessions/beta -b feature/beta origin/main
Session Gamma
git worktree add ~/ai-sessions/gamma -b feature/gamma origin/main
Check active worktrees:
git worktree list
Each session now has:
- Its own branch
- Its own folder
- Shared repository backend
No duplication of Git history.
Step 3: Run Persistent AI Agents Using tmux
Each session runs inside its own persistent terminal.
Start Alpha Agent
tmux new-session -s alpha-agent
Inside:
cd ~/ai-sessions/alphaclaude
Detach:
Press Ctrl + b then d
Start Beta Agent
tmux new-session -s beta-agent
Inside:
cd ~/ai-sessions/betaclaude
Detach again.
List Running Agents
tmux ls
Attach anytime:
tmux attach -t alpha-agent
This allows live monitoring and intervention.
Automating Session Creation
To make this reproducible, I created a simple launcher script.
Create:
nano ~/launch-ai-lab.sh
Paste:
#!/bin/bashPROJECT=base-repoBASE_BRANCH=mainROOT="$HOME/dev/$PROJECT"SESSION_ROOT="$HOME/ai-sessions"cd "$ROOT"for name in delta epsilon zeta; do WORKDIR="$SESSION_ROOT/$name" BRANCH="feature/$name" if [ ! -d "$WORKDIR" ]; then git worktree add "$WORKDIR" -b "$BRANCH" "origin/$BASE_BRANCH" fi tmux new-session -d -s "$name-session" "cd $WORKDIR && claude" echo "Started AI session: $name"done
Make executable:
chmod +x ~/launch-ai-lab.sh
Run:
~/launch-ai-lab.sh
You now have multiple AI agents running in parallel.
What This Architecture Achieves
Isolation
Each agent edits only its own branch.
Observability
Every session is visible and controllable.
Efficiency
No duplicate cloning. Shared Git backend.
Scalability
Adding new agents is just adding another worktree and tmux session.
Clean PR Workflow
Each branch maps cleanly to a pull request.
Practical Observations
After testing this setup:
- Git discipline becomes essential.
- AI agents must have clearly scoped tasks.
- Parallel execution increases review load.
- Human oversight remains critical.
- Isolation is non negotiable.
This pattern transforms AI from assistant to orchestrated workforce.
Why This Matters
As AI coding tools evolve, raw model intelligence will not be the differentiator.
Workflow architecture will be.
The real advantage lies in:
- Isolation strategies
- Version control discipline
- Observability design
- Human intervention points
Parallel AI is powerful, but only when engineered responsibly.
