DEV Community

brian austin
brian austin

Posted on

Claude Code parallel agents: how to run multiple AI instances on the same codebase

Claude Code Parallel Agents: How to Run Multiple AI Instances on the Same Codebase

If you've ever watched Claude Code churn through a massive refactor — one file at a time, sequentially — you've felt the pain. There's a better way: parallel agents.

This is how senior engineers at high-velocity teams use Claude Code: multiple instances, coordinated work, no context collision.

Here's the complete workflow.

Why Sequential Claude Code Sessions Are Slow

By default, Claude Code works linearly:

  1. You give it a task
  2. It reads files, edits, reads more files
  3. It finishes
  4. You start the next task

For small tasks, this is fine. For large codebases — microservices, frontend/backend splits, shared libraries — sequential work means:

  • 2-4x longer sessions (more tokens, more rate limit hits)
  • Context window fills with irrelevant files from earlier in the session
  • No parallelism on independent subsystems

The Parallel Agent Pattern

The core idea: split work by subsystem, run agents simultaneously, merge at a known sync point.

# Terminal 1 — API layer
cd /repos/myapp/api
claude

# Terminal 2 — Frontend layer  
cd /repos/myapp/frontend
claude

# Terminal 3 — Shared types/contracts
cd /repos/myapp/shared
claude
Enter fullscreen mode Exit fullscreen mode

Each agent has a focused context. The shared types agent runs first (or concurrently if the interface is already defined), then API and frontend agents work independently.

Setting Up CLAUDE.md Per Agent

The secret weapon for parallel agents is per-directory CLAUDE.md files:

# api/CLAUDE.md
## Scope
This agent manages the REST API layer only.
Do NOT modify files in /shared or /frontend.

## Current Task
Refactor auth middleware to use JWT refresh tokens.
See /shared/types/auth.ts for the interface contract.

## Constraints
- Never modify database schema directly — use migrations in /db/migrations/
- All endpoints must pass existing test suite: npm test
- API versioning: all new endpoints under /api/v2/
Enter fullscreen mode Exit fullscreen mode
# frontend/CLAUDE.md  
## Scope
This agent manages the React frontend only.
Do NOT modify /api or /shared source files.

## Current Task
Update auth flow to handle JWT refresh tokens.
The new token response shape is in /shared/types/auth.ts

## Constraints
- Use React Query for all data fetching
- No direct localStorage calls — use useAuthStore
- E2E tests live in /e2e/ — run with: npm run e2e
Enter fullscreen mode Exit fullscreen mode

With explicit scope boundaries in CLAUDE.md, each agent stays in its lane.

The Sync Protocol

Parallel agents need coordination checkpoints. Use a shared contract file:

// shared/types/contracts.ts
// THIS FILE IS THE SYNC POINT
// Both API and Frontend agents read from here
// Only the Shared agent writes here

export interface AuthResponse {
  accessToken: string;
  refreshToken: string;
  expiresIn: number;  // seconds
  tokenType: 'Bearer';
}

export interface RefreshRequest {
  refreshToken: string;
}
Enter fullscreen mode Exit fullscreen mode

Workflow:

  1. Shared agent defines the contract
  2. API and Frontend agents implement against it simultaneously
  3. Sync point: run integration tests that verify both sides match

Rate Limits and Parallel Agents

Here's the catch: running 3 agents simultaneously = 3x the token consumption. You'll hit rate limits 3x faster.

Options:

  1. Stagger agents — start one, let it finish a milestone, start the next
  2. Use a proxy endpoint — route all agents through a single API key with pooled limits
  3. Morning sessions — rate limits reset, run the big parallel jobs before 9am

For option 2, if you're regularly running parallel agents, you want an endpoint that handles the rate limit pooling for you. That's what SimplyLouie does — single API endpoint, all your Claude Code instances route through it, $2/month flat. Each agent runs independently without burning through a single account's quota.

Practical Example: Database + API + Frontend Migration

Scenario: you need to add a user_preferences table, expose it via API, and build a settings page.

Agent 1 — Database (runs first):

Create migration for user_preferences table.
Add indexes for user_id lookups.
Generate TypeScript types from the schema.
Output types to /shared/types/userPreferences.ts
Enter fullscreen mode Exit fullscreen mode

Agent 2 — API (starts after types exist):

Add GET /api/v2/users/:id/preferences
Add PATCH /api/v2/users/:id/preferences  
Use types from /shared/types/userPreferences.ts
Write unit tests in /api/tests/preferences.test.ts
Enter fullscreen mode Exit fullscreen mode

Agent 3 — Frontend (starts after types exist):

Build SettingsPage component using PreferencesForm
Fetch from /api/v2/users/:id/preferences
Use types from /shared/types/userPreferences.ts
Add to router at /settings/preferences
Enter fullscreen mode Exit fullscreen mode

Agents 2 and 3 run in parallel. Typical time savings: 40-60% vs sequential.

Anti-Patterns to Avoid

❌ Two agents editing the same file simultaneously
This creates merge conflicts. Use CLAUDE.md scope boundaries to prevent it.

❌ No sync point between agents
Agents that work without a shared contract end up with incompatible interfaces. Always define the contract first.

❌ Too many parallel agents
More than 3-4 agents on one codebase creates coordination overhead that erases the time savings. Sweet spot is 2-3 agents.

❌ Agents with context from the previous session
Always start parallel agents fresh. Use /clear if resuming a session to avoid stale context contaminating the agent's understanding.

The Result

With parallel agents + CLAUDE.md scope files + a shared contract sync point:

  • 40-60% faster on multi-subsystem changes
  • Each agent has a focused, smaller context window (fewer tokens, fewer rate limit hits)
  • Merge conflicts are rare because agents stay in their scope
  • Integration bugs are caught at the sync point, not in production

This is how teams ship large features in Claude Code without spending hours watching a single instance work through files one by one.


Running parallel Claude Code agents burns through API rate limits fast. If you're hitting limits, SimplyLouie ($2/month) gives you a proxy endpoint all your agents can share — no per-seat pricing, no rate limit pooling headaches.

Top comments (0)