Overview
Emdash can run multiple AI agents simultaneously, each working on different tasks in complete isolation. This enables:- Faster iteration: Test multiple approaches in parallel
- Multi-agent collaboration: Different agents working on related features
- Context switching: Start a new task while another agent continues working
- Experimentation: Try multiple solutions and pick the best one
Technical architecture
Parallel execution is enabled by three key isolation mechanisms:1. Separate worktrees
Each task runs in its own git worktree at a unique path:- File system isolation: Each agent modifies only its own files
- Branch isolation: Each task is on a separate git branch
- No conflicts: Agents never interfere with each other’s changes
2. PTY isolation
Each agent runs in its own pseudo-terminal (PTY) process:- Process isolation: Each agent is a separate OS process
- Environment isolation: Each PTY has its own environment variables
- Resource isolation: Agents don’t compete for terminal state
- Independent lifecycle: Agents can start/stop/crash independently
3. Process management
Emdash tracks all agent processes in a central registry:- Provider: Which agent (claude, codex, qwen, etc.)
- Type: Main task or additional chat conversation
- Target: Task ID or conversation ID
src/shared/ptyId.ts:
claude-main-task-abc123— Claude working on task abc123codex-main-task-def456— Codex working on task def456qwen-chat-conv-xyz789— Qwen in additional conversation xyz789
How it works
When you create multiple tasks and start agents:1. Task creation
Each task gets:2. Agent spawning
Each agent gets its own PTY:3. Independent execution
Each agent:- Reads/writes files only in its worktree
- Commits to its own branch
- Has its own terminal state
- Runs until completion or error
- Can be stopped independently
4. Data streaming
Terminal output from each agent is streamed independently:Performance benefits
CPU utilization
Multiple agents can utilize multiple CPU cores:Time savings
Parallel execution can dramatically reduce total time: Sequential (one agent at a time):Resource management
Emdash automatically manages:- Memory: Each PTY has reasonable memory limits
- File handles: Proper cleanup on task completion
- Network: API calls distributed across agents
- Disk I/O: Each worktree on local filesystem
Use cases
1. Multi-approach problem solving
Try multiple solutions simultaneously:2. Feature parallelization
Work on independent features:3. Provider comparison
Compare different agents on the same task:4. Staged development
Work on different stages of a feature:Limitations
What can be parallelized
✅ Independent features✅ Bug fixes in different areas
✅ Documentation and code separately
✅ Multiple approaches to same problem
✅ Refactoring different modules
What cannot be parallelized
❌ Sequential dependencies: Task B needs Task A’s changes❌ Shared file conflicts: Both agents modify the same line
❌ Database migrations: Must be applied in order
❌ Breaking changes: Affects other in-progress work
Resource constraints
- API rate limits: Multiple agents share your API quota
- System memory: Each agent consumes ~200-500MB
- Disk space: Each worktree is a full repository copy
- Network bandwidth: Multiple simultaneous API calls
Best practices
Independent tasks
Ensure tasks are independent and won’t conflict with each other’s changes.
Monitor resources
Watch CPU and memory usage when running many agents simultaneously.
Stagger starts
Start agents a few seconds apart to avoid API burst limits.
Clear goals
Give each agent a specific, well-defined task to maximize efficiency.
Example: Multi-agent workflow
Here’s a complete example of parallel execution:1. Create tasks
2. Start agents
All three agents start simultaneously, each in their own:- Worktree (e.g.,
worktrees/add-rest-api-endpoints-x7k/) - PTY process (e.g.,
claude-main-task-abc123) - Git branch (e.g.,
emdash/add-rest-api-endpoints-x7k)
3. Monitor progress
Watch all three terminals simultaneously in the Emdash UI:4. Review and merge
As each task completes:- Review the changes in isolation
- Create a pull request
- Merge when approved
- Other tasks continue unaffected
Advanced: Session isolation
Some providers like Claude support session IDs for multiple conversations in the same worktree:- Multiple Claude conversations per task
- Isolated chat histories
- Independent context per conversation
- No state collision between sessions