Skip to main content
MindStudio
Pricing
Blog About
My Workspace

Parallel Agentic Development: How to Run Multiple Claude Code Sessions at Once

Use Git worktrees, database branching, and isolated environments to run 5+ Claude Code agents in parallel and ship features faster without conflicts.

MindStudio Team RSS
Parallel Agentic Development: How to Run Multiple Claude Code Sessions at Once

Why Running One Claude Code Session at a Time Is Leaving Speed on the Table

Most developers using Claude Code work sequentially: start a session, finish a task, start another. It feels natural because that’s how solo programming has always worked. But Claude Code isn’t a solo programmer — it’s an agent that can run autonomously for minutes or hours at a stretch. Running one at a time means you’re using maybe 20% of what’s available to you.

Parallel agentic development changes the math. Instead of one agent working on one feature while you wait, you run five agents simultaneously — one per feature branch, each in its own isolated environment, none stepping on the others. When they’re done, you review and merge. The result is a fundamentally different development velocity.

This guide covers exactly how to set that up: Git worktrees for code isolation, database branching for data isolation, environment configuration for preventing conflicts, and coordination patterns that keep multiple Claude Code sessions working together without chaos.


The Core Problem: Why Agents Conflict Without Isolation

Before getting into the setup, it’s worth understanding what actually goes wrong when you run multiple Claude Code sessions naively — meaning multiple terminal windows all pointed at the same project directory.

The problems fall into three categories:

File conflicts. Two agents editing the same file simultaneously produces corrupted output or one agent’s changes overwriting the other’s. Even if they’re working on different features, shared files like package.json, config files, or shared utilities become collision points.

Database conflicts. If both agents are writing to the same development database, you get interleaved state that makes neither feature testable in isolation. One agent’s seed data interferes with the other’s test assumptions.

Context confusion. Each Claude Code session holds a mental model of what it’s building. When two sessions share a workspace, they can read each other’s in-progress changes and make incorrect assumptions about the state of the codebase.

Isolation solves all three. The goal is to give each agent its own workspace, its own database, and its own environment — so five agents running in parallel behave exactly like five independent developers working in separate branches.


Step 1: Set Up Git Worktrees for Code Isolation

Git worktrees are the foundation of parallel agentic development. A worktree lets you check out multiple branches of the same repository simultaneously, each in its own directory on disk. No stashing, no switching — just separate working directories.

Claude Code has native support for this pattern, and it’s the cleanest way to run agents in parallel without file conflicts.

Create Your Worktrees

Start from your main project directory. For each feature you want to develop in parallel, create a dedicated worktree:

# Create worktrees for three parallel features
git worktree add ../project-feature-auth feature/auth
git worktree add ../project-feature-payments feature/payments
git worktree add ../project-feature-dashboard feature/dashboard

This gives you three directories alongside your main project, each on its own branch:

/projects/
  my-app/              ← main branch
  project-feature-auth/     ← feature/auth branch
  project-feature-payments/ ← feature/payments branch
  project-feature-dashboard/ ← feature/dashboard branch

Each directory is a full working copy of your repository. An agent working in project-feature-auth/ cannot touch files in the other directories. Git tracks them independently.

Run Claude Code in Each Worktree

Open a terminal in each worktree directory and start Claude Code:

# Terminal 1
cd ../project-feature-auth
claude

# Terminal 2
cd ../project-feature-payments
claude

# Terminal 3
cd ../project-feature-dashboard
claude

Each session sees only its own branch. File writes stay contained. When an agent finishes, you merge the branch back normally — git merge or a pull request.

For a deeper walkthrough of this pattern, see the guide on running parallel feature branches with Git worktrees.

Clean Up When Done

After merging, remove the worktree:

git worktree remove ../project-feature-auth
git branch -d feature/auth

Step 2: Isolate Databases for Each Agent

Code isolation handles file conflicts, but database conflicts are subtler and cause more confusing bugs. If five agents share a development database, their test data and schema migrations interfere with each other constantly.

The right approach depends on your stack.

SQLite (Simplest Approach)

If you’re using SQLite, the solution is trivial: each worktree gets its own database file. Set your database path using an environment variable:

# In each worktree's .env file
DATABASE_URL=./db/dev.sqlite

Since each worktree is a separate directory, ./db/dev.sqlite resolves to a different file for each agent. No additional setup required.

PostgreSQL / MySQL with Schema Branching

For shared database servers, create a separate schema or database for each branch:

-- One-time setup per feature branch
CREATE DATABASE myapp_feature_auth;
CREATE DATABASE myapp_feature_payments;
CREATE DATABASE myapp_feature_dashboard;

Then set the connection string in each worktree’s .env:

# project-feature-auth/.env
DATABASE_URL=postgresql://localhost/myapp_feature_auth

# project-feature-payments/.env
DATABASE_URL=postgresql://localhost/myapp_feature_payments

When the branch is merged and deleted, drop the database:

dropdb myapp_feature_auth

Database Branching Services

Tools like Neon offer instant database branching — you create a branch of your database in seconds, complete with a copy of your production schema and data. This is especially useful when agents need realistic seed data to test against, not just empty schemas.

# Using Neon CLI
neon branch create --name feature-auth
# Returns a connection string for the new branch

Each agent gets a database branch with the same starting state, then diverges independently. Merge the code branch, drop the database branch.


Step 3: Configure Isolated Environments

Beyond code and databases, agents can conflict through shared resources: port numbers, API keys with rate limits, cache layers, and external service credentials.

Port Allocation

Each agent running a dev server needs its own port. Assign them in each worktree’s .env:

# project-feature-auth/.env
PORT=3001
NEXT_PUBLIC_API_URL=http://localhost:3001

# project-feature-payments/.env
PORT=3002
NEXT_PUBLIC_API_URL=http://localhost:3002

# project-feature-dashboard/.env
PORT=3003
NEXT_PUBLIC_API_URL=http://localhost:3003

API Keys and Rate Limits

If your agents are hitting third-party APIs, shared credentials can lead to rate limit collisions. Where possible, use separate API keys per agent, or use mock/sandbox credentials for non-critical external calls during development.

For internal services, make sure agents aren’t sharing session tokens or authentication state that could cause one agent’s actions to appear under another agent’s session.

Redis and Cache Layers

If your app uses Redis for caching or session storage, use separate key prefixes or separate Redis databases per worktree:

# project-feature-auth/.env
REDIS_KEY_PREFIX=auth:
REDIS_DB=1

# project-feature-payments/.env
REDIS_KEY_PREFIX=payments:
REDIS_DB=2

Step 4: Write Effective Per-Agent Instructions

Each Claude Code session starts fresh. To run five agents in parallel without babysitting each one, you need each agent to have clear, complete instructions for its task.

This is where Claude Code’s claude.md file becomes important. You can place a CLAUDE.md in each worktree with task-specific instructions that persist across the session.

A good per-agent CLAUDE.md includes:

  • The specific feature scope — What exactly is this agent building? Be precise about what’s in scope and what isn’t.
  • File boundaries — Which files and directories this agent should touch. Reduces the chance of accidental modifications outside the feature.
  • Test requirements — What tests should pass when the feature is complete.
  • Merge criteria — How the agent should know it’s done.

Example for the auth feature agent:

# Auth Feature Agent

## Scope
Build email/password authentication: registration, login, logout, and session management.

## Files to modify
- src/auth/ (create if doesn't exist)
- src/middleware/auth.ts
- src/routes/auth.ts
- tests/auth/

## Do not touch
- src/payments/
- src/dashboard/
- database/migrations/ (create new files only, don't modify existing)

## Done when
- All tests in tests/auth/ pass
- Registration creates a user with hashed password
- Login returns a valid session token
- Logout invalidates the session

For coordinating agents on larger tasks, you might also look at how parallel agents share task lists in real time — useful when agents need to be aware of each other’s progress.


Step 5: Choose a Coordination Pattern

How your agents coordinate — or don’t — depends on the nature of the work. Three patterns cover most situations.

Fully Independent (No Coordination Needed)

The simplest pattern: each agent works on a completely isolated feature. The only coordination happens at merge time, when you review and integrate the branches.

This works when:

  • Features have no shared code dependencies
  • Agents don’t need to build on each other’s output
  • Tasks are genuinely parallelizable end-to-end

Five agents, five branches, five pull requests. Review them in sequence, resolve any merge conflicts at the end. This is the default pattern for most parallel development work.

Operator + Workers

One agent acts as an orchestrator: it breaks down a large task, spawns sub-agents to handle pieces, and then integrates their output. Claude Code’s operator pattern formalizes this approach.

The operator agent doesn’t write much code itself — it directs, reviews, and coordinates. The worker agents focus on implementation. This works well when a feature is too large for a single context window but has clearly separable pieces.

Split-and-Merge

Similar to operator + workers, but more symmetric. A root agent splits a task into parallel workstreams, waits for all of them to complete, then merges the results. The split-and-merge pattern is particularly good for tasks like comprehensive testing, multi-file refactors, or generating multiple variations of a solution.

For example: split a codebase analysis across four sub-agents, each responsible for a different module, then merge their findings into a single report. This avoids hitting rate limits on large codebases while cutting the time dramatically. There’s more on this approach in the guide on using sub-agents for codebase analysis without hitting rate limits.


Step 6: Manage Five Sessions Without Losing Track

Running five Claude Code sessions in parallel terminals is manageable, but only if you have a system. Without one, you’ll spend time hunting for which terminal has which agent and what state each one is in.

tmux for Terminal Organization

tmux lets you split your terminal into panes and windows, each named and organized. A basic setup for five parallel agents:

tmux new-session -s agents

# Create windows for each agent
tmux new-window -t agents -n "auth"
tmux new-window -t agents -n "payments"
tmux new-window -t agents -n "dashboard"
tmux new-window -t agents -n "api"
tmux new-window -t agents -n "tests"

# Switch between agents with Ctrl+b, then window number

Label each window clearly. Check in periodically to see where each agent is, answer any clarifying questions, and approve any tool calls that require confirmation.

Log Agent Output

For long-running agents, capture their output to a log file so you can review what happened without watching a terminal in real time:

claude --output-format stream-json | tee agent-auth.log

You can tail the log when you want to check in without interrupting the agent’s workflow.

Build a Command Center

For teams running many agents regularly, a proper monitoring interface makes sense. The AI command center pattern describes how to build a dashboard that shows all active agents, their current tasks, and their status — so you’re managing by goals rather than by watching terminals.

This is especially relevant as your parallel agent count grows past five or six. At that point, terminal management becomes its own job. Managing agents by goals instead of terminals is a useful architectural shift to make early.


Step 7: Merge, Review, and Integrate

Parallel development creates parallel pull requests. The merge strategy matters — both for code correctness and for keeping your main branch stable.

Sequential Merging

Merge one branch at a time, running your test suite after each merge. This makes it easy to attribute any failures to a specific branch and keeps the integration surface manageable.

Order your merges from most foundational to most dependent. If the auth feature is a dependency of the dashboard feature, merge auth first.

Conflict Resolution

Even with isolated worktrees, some merge conflicts are inevitable — shared config files, updated dependencies, or two agents that both needed to touch a utility function.

When conflicts occur, resolve them manually in the context of what each agent was trying to accomplish. If you’ve kept your per-agent CLAUDE.md files, reviewing those helps clarify intent quickly.

Post-Merge Cleanup

After all branches are merged:

# Remove worktrees
git worktree remove ../project-feature-auth
git worktree remove ../project-feature-payments
git worktree remove ../project-feature-dashboard

# Delete branches
git branch -d feature/auth feature/payments feature/dashboard

# Drop database branches
dropdb myapp_feature_auth
dropdb myapp_feature_payments
dropdb myapp_feature_dashboard

Keep your workspace clean. Stale worktrees and databases accumulate quickly when you’re running parallel sessions regularly.


Where Remy Fits Into This

Parallel agentic development is powerful, but it requires managing a fair amount of infrastructure: worktrees, database branches, environment variables, port assignments, merge strategies. Each piece is straightforward on its own, but the coordination overhead adds up.

Remy approaches this from a different angle. Rather than managing multiple agents against a shared codebase, Remy works from a spec — an annotated markdown document that is the single source of truth for your application. When you update the spec, Remy compiles the change into a full-stack app: backend, database, auth, frontend, deployment. The code is derived output, not the primary artifact.

This means the “parallel sessions” problem mostly disappears. You’re not managing five agents reading and writing the same files — you’re updating a structured document that the system compiles consistently. When you need something changed, you change the spec and recompile. The generated code stays in sync.

Remy runs on infrastructure built by MindStudio: 200+ AI models, production-grade databases, auth, and deployment baked in. You open a browser tab and describe what you want built. The full-stack app follows.

If you’re building net-new applications and want to skip the agent coordination overhead entirely, try Remy at mindstudio.ai/remy.


Common Mistakes and How to Avoid Them

Running Too Many Agents at Once

More isn’t always better. Five to six parallel agents is usually the practical ceiling before the review and merge overhead outweighs the parallelism gains. Start with two or three, get comfortable with the workflow, then scale up.

Giving Agents Overlapping Scope

If two agents both have permission to modify src/utils/helpers.ts, you’ll have a conflict regardless of worktrees. Be explicit about file boundaries in your per-agent instructions. When in doubt, assign ownership of shared files to one agent.

Skipping the Database Isolation Step

This is the most commonly skipped step, and it causes the most confusing bugs. Two agents running migrations against the same database will produce a schema that neither agent expects. Always give each agent its own database, even if it feels like extra setup.

Not Running Tests Before Merging

Each worktree should have passing tests before you merge. Running the test suite after every merge makes failures easy to attribute. Running it only at the end makes debugging painful.

Forgetting to Clean Up

Unused worktrees and database branches pile up fast. Build the cleanup step into your workflow, not as an afterthought. A simple shell script that removes worktrees and drops databases when you’re done with a sprint saves a lot of disk space and mental overhead.


Frequently Asked Questions

How many Claude Code sessions can I run in parallel?

Practically, five to eight is a reasonable upper limit for most developers. The constraint isn’t technical — Claude Code can run as many sessions as you have compute for. The constraint is review bandwidth. Each parallel agent creates a branch to review and merge. If you’re running ten agents, you need to review ten pull requests. Start with three or four and scale based on how much review capacity you have.

Do I need a special Claude Code plan for parallel sessions?

No. Claude Code runs as many sessions as you open. The cost is per token, not per session, so running five sessions costs roughly five times as much as one in inference. Check your current plan’s rate limits — heavy parallel usage can hit them faster than sequential usage. Claude Code’s Ultra plan multi-agent architecture is worth reviewing if you’re planning sustained parallel workloads.

What if two agents need to share code, like a utility function?

Two options. First, complete the shared utility in one agent’s branch and merge it to main before the other agents start. Second, define a clear interface for the utility in advance and let each agent implement against the interface independently, then reconcile at merge time. Avoid letting two agents edit the same shared file simultaneously — it always ends in a conflict.

How do I handle agents that get stuck or go in the wrong direction?

Check in periodically — every 15 to 30 minutes for long-running tasks. If an agent has gone off course, it’s usually faster to stop it, review what it did, update the instructions, and restart than to try to redirect a session mid-flight. Clear scoping upfront (specific file boundaries, explicit acceptance criteria) is the best way to prevent drift. You can also look at agentic workflow patterns that build in checkpoints and review steps.

Can I run parallel agents in headless mode?

Yes. Claude Code’s headless mode lets you run agents without an interactive terminal — useful for CI pipelines, scheduled tasks, or running agents on a remote server overnight. Combine this with worktrees and you can kick off a parallel run before you go home and review the results the next morning.

What’s the difference between parallel worktree agents and the split-and-merge pattern?

Worktree-based parallel agents are independent: each runs in its own branch, completes its own task, and produces its own pull request. The split-and-merge pattern is hierarchical: a parent agent splits a single task into parallel sub-agents, waits for all of them to finish, and then merges their output into a unified result. Worktrees are for developing independent features simultaneously. Split-and-merge is for accelerating a single complex task by distributing the work. See the split-and-merge pattern deep dive for a full walkthrough.


Key Takeaways

  • Isolation is the prerequisite. Git worktrees handle code isolation. Separate databases handle data isolation. Per-agent environment variables handle everything else. All three are necessary for conflict-free parallel sessions.
  • Clear scoping prevents drift. Define file boundaries and acceptance criteria per agent before you start. Vague instructions produce vague output — and merge conflicts.
  • The right coordination pattern depends on the work. Fully independent agents for separate features. Operator + workers for large tasks with clear subtasks. Split-and-merge for single tasks that benefit from parallelism.
  • Review capacity limits practical parallelism. You can run ten agents, but you’ll need to merge ten branches. Match your parallel count to your review bandwidth.
  • Clean up after every sprint. Remove worktrees, delete branches, drop database branches. Build it into the habit.

If you want to build full-stack applications without managing the underlying agent coordination at all, try Remy — a spec-driven approach where the entire application compiles from a single structured document.

Presented by MindStudio

No spam. Unsubscribe anytime.