Building with Claude Code Agent Teams

Building with Claude Code Agent Teams

Why Agent Teams?

Agent Team : Multiple Claude Code instances working on different aspects of a project, coordinated to achieve a larger goal than any single agent could efficiently handle.

Single agents hit limits:

  • Context window caps
  • Serial execution
  • Scope creep

Agent teams solve these:

  • Separate contexts per agent
  • Parallel execution
  • Focused responsibilities

Pattern 1: Parallel Workers

The simplest pattern—multiple agents on independent tasks.

Setup

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
# parallel-agents.sh

# Agent 1: Backend work
claude --no-interactive "
Focus: apps/api/src/
Task: Add new endpoint for user preferences
" &

# Agent 2: Frontend work
claude --no-interactive "
Focus: apps/web/app/
Task: Add preferences UI component
" &

# Agent 3: Tests
claude --no-interactive "
Focus: tests/
Task: Write integration tests for preferences feature
" &

# Wait for all to complete
wait

echo "All agents completed"

When to Use

  • Independent features
  • Different modules
  • Tasks that don’t affect each other’s files

Coordination

Coordinate through git:

  1. Agents work on separate branches
  2. Merge branches when complete
  3. Resolve conflicts manually

Pattern 2: Specialized Roles

Agents with specific expertise handle different concerns.

Role Definitions

1
2
3
4
5
6
# .claude/agents/architect.md
You are the Architect agent. Your responsibilities:
- Review proposed designs
- Ensure consistency with existing patterns
- Flag potential issues with scale or complexity
- You DO NOT write implementation code
1
2
3
4
5
6
# .claude/agents/implementer.md
You are the Implementer agent. Your responsibilities:
- Write code based on approved designs
- Follow existing patterns exactly
- Ask questions if requirements are unclear
- You DO NOT make architectural decisions
1
2
3
4
5
6
# .claude/agents/reviewer.md
You are the Reviewer agent. Your responsibilities:
- Review code for security vulnerabilities
- Check for edge cases and error handling
- Verify tests cover requirements
- You DO NOT write implementation code

Workflow

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Step 1: Architect designs
claude --system "$(cat .claude/agents/architect.md)" \
  "Design user preferences feature. Output design doc only."

# Step 2: Human reviews design

# Step 3: Implementer builds
claude --system "$(cat .claude/agents/implementer.md)" \
  "Implement based on design in design.md"

# Step 4: Reviewer checks
claude --system "$(cat .claude/agents/reviewer.md)" \
  "Review implementation in apps/api/src/preferences/"

When to Use

  • Complex features requiring design
  • Security-critical code
  • When you want explicit review stages

Pattern 3: Orchestrated Pipeline

A coordinator agent manages other agents.

Coordinator Script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# orchestrator.py
import subprocess
import json

def run_agent(prompt: str, focus: str = None) -> str:
    cmd = ["claude", "--no-interactive", "--json"]
    if focus:
        prompt = f"Focus: {focus}\n\n{prompt}"

    result = subprocess.run(
        cmd,
        input=prompt,
        capture_output=True,
        text=True
    )
    return json.loads(result.stdout)

def build_feature(feature_spec: str):
    # Step 1: Plan
    plan = run_agent(
        f"Create implementation plan for: {feature_spec}",
        focus="architecture"
    )

    # Step 2: Implement each part
    for task in plan['tasks']:
        result = run_agent(
            f"Implement: {task['description']}",
            focus=task['focus_area']
        )

        # Step 3: Review each part
        review = run_agent(
            f"Review changes for: {task['focus_area']}",
            focus="security"
        )

        if review['issues']:
            # Fix issues
            run_agent(
                f"Fix these issues: {review['issues']}",
                focus=task['focus_area']
            )

    # Step 4: Integration test
    run_agent(
        "Run integration tests and fix failures",
        focus="tests"
    )

# Run
build_feature("User subscription management with Stripe")

When to Use

  • Complex multi-step features
  • Automated pipelines (CI/CD)
  • When you want programmatic control

Pattern 4: Context Handoff

Agents pass context to each other explicitly.

Implementation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
# context-handoff.sh

# Agent 1: Explore and document
claude --no-interactive "
Explore the billing module.
Output a context summary document.
" > .claude/handoff/billing-context.md

# Agent 2: Use that context
claude --no-interactive "
Read .claude/handoff/billing-context.md

Using this context, implement coupon support.
"

# Agent 3: Review with context
claude --no-interactive "
Read .claude/handoff/billing-context.md
Review the coupon implementation for issues.
"

Handoff Documents

Structure for effective handoffs:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# Context Handoff: Billing Module

## Current State
- Stripe integration via apps/api/src/billing/stripe.ts
- Subscription model in packages/db/schema.prisma
- Webhook handler at apps/api/src/billing/webhooks.ts

## Key Patterns
- All Stripe calls wrapped in try/catch with logging
- Subscriptions sync on webhook, not API response
- Invoices stored locally for quick access

## Active Concerns
- Proration not yet implemented
- Coupon support pending
- Currency handling is USD-only

## Files Modified This Session
- apps/api/src/billing/routes.ts (added /coupons endpoint stub)

Pattern 5: Competitive Agents

Multiple agents attempt the same task, best wins.

When Useful

  • Exploring different approaches
  • Uncertain about best solution
  • A/B testing implementations

Implementation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
# competitive-agents.sh

# Agent A: Approach 1
claude --no-interactive "
Implement user search with Postgres full-text search.
Focus on performance for 1M+ users.
" > /tmp/approach-a.md &

# Agent B: Approach 2
claude --no-interactive "
Implement user search with Elasticsearch.
Focus on relevance and fuzzy matching.
" > /tmp/approach-b.md &

wait

# Evaluator agent
claude --no-interactive "
Compare these two approaches:
- Approach A: $(cat /tmp/approach-a.md)
- Approach B: $(cat /tmp/approach-b.md)

Evaluate on: performance, maintainability, cost.
Recommend one with justification.
"

Security Considerations

Agent Permissions

Limit what agents can do:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# .claude/permissions.yaml
agents:
  implementer:
    can_read: true
    can_write: true
    can_execute: false
    restricted_paths:
      - .env*
      - credentials/

  reviewer:
    can_read: true
    can_write: false
    can_execute: false

Audit Logging

Log all agent actions:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def run_agent_with_audit(prompt, agent_role, focus=None):
    start_time = time.time()
    result = run_agent(prompt, focus)

    audit_log.write({
        'timestamp': start_time,
        'agent_role': agent_role,
        'prompt_hash': hash(prompt),
        'focus': focus,
        'files_modified': result.get('files_modified', []),
        'duration': time.time() - start_time
    })

    return result

Review Gates

Never let agents push to production directly:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# CI workflow
jobs:
  agent-review:
    steps:
      - name: Agent implements
        run: ./run-agent.sh

      - name: Human review required
        uses: hmarr/auto-approve-action@v3
        with:
          require-approvals: 1

FAQ

How many agents should I run in parallel?

Depends on your task. Start with 2-3 for parallel features. More agents = more coordination overhead. The sweet spot is usually 3-5 for complex projects.

Do agents share context automatically?

No. Each agent has independent context. Use handoff documents or explicit file reads to share information between agents.

How do I handle conflicts between agents?

Have agents work on separate files/branches when possible. Use a coordinator agent or human review to resolve conflicts. Git merge is your friend.

Can I use different models for different agents?

Yes. Use Claude Sonnet for complex reasoning, Haiku for simple tasks. Match model capability to task complexity.

Conclusion

Key Takeaways

  • Parallel workers handle independent tasks simultaneously
  • Specialized roles (architect, implementer, reviewer) add structure
  • Orchestrated pipelines enable complex automated workflows
  • Context handoff documents transfer state between agents
  • Competitive agents explore multiple approaches
  • Limit agent permissions for security
  • Always include human review gates
  • Start simple, add coordination as needed

AI Coding Security Insights.
Ship Vibe-Coded Apps Safely.

Effortlessly test and evaluate web application security using Vibe Eval agents.