Feature Request: Context Inheritance for Batch/Iterator Operations — Enable Efficient Parallel Execution

Resolved 💬 3 comments Opened Feb 25, 2026 by udayshnk Closed Feb 28, 2026

Problem Statement

When running multiple agents in parallel via the Task tool to perform similar operations, each agent spawns with a fresh context window. This creates significant inefficiencies:

  1. Redundant File I/O: Foundation data (code style guides, API specs, design systems, etc.) is re-read for every parallel task
  2. Context Window Waste: Identical setup data (examples, configurations, constraints) duplicates across every agent's context
  3. Exponential Token Cost: For N parallel tasks with shared 50KB master data, current approach wastes ~50KB × (N-1) tokens
  4. Scalability Ceiling: Can't efficiently parallelize beyond 3-5 tasks due to cost; would want 50+ parallel tasks

Generic Pattern: Master Context + Batch Operations

This feature would enable any scenario following this pattern:

Master Setup (read/prepare once)
  ├─ Foundation data
  ├─ Configuration/constraints  
  ├─ Examples/patterns
  └─ Shared utilities
    ↓ (context fork/inherit)
  ├─ Agent 1: Operation on Item A
  ├─ Agent 2: Operation on Item B
  ├─ Agent 3: Operation on Item C
  └─ Agent N: Operation on Item Z

Real-World Use Cases

1. Code Generation (50-100+ parallel tasks)

  • Generate API endpoint handlers (N endpoints, each forked task)
  • Generate React/Vue components (N components)
  • Generate database migrations (N migrations)
  • Generate test suites (N test files)

Master context: Style guide, architecture patterns, examples, shared types (~50KB)

2. Batch Data Processing (500-1000+ parallel tasks)

  • Extract/validate info from multiple records
  • Categorize items according to rules
  • Normalize data across multiple formats
  • Enrich records with derived data

Master context: Schema definition, validation rules, business logic (~25KB)

3. Code Migration/Transformation (100-1000+ parallel tasks)

  • Migrate function calls across codebase (v3 → v4)
  • Refactor multiple files to new patterns
  • Update multiple config files to new format
  • Convert code between languages

Master context: Migration guide, compatibility matrix, transformation patterns (~30KB)

4. Documentation Generation (50-200+ parallel tasks)

  • Generate API docs from specs (N endpoints)
  • Create user guides from templates (N features)
  • Generate troubleshooting docs (N issues)
  • Create release notes (N versions)

Master context: Style guide, template structure, brand voice (~40KB)

5. Content Creation & Variation (100-500+ parallel tasks)

  • Generate product descriptions (N products)
  • Create marketing variations (A/B tests)
  • Generate social media posts (N announcements)
  • Create email campaigns (N variations)

Master context: Brand guidelines, tone of voice, best practices (~35KB)

Current Workarounds (All Inefficient)

| Approach | Pros | Cons |
|----------|------|------|
| Read all data into prompt | Native | Wastes context, pollutes every task |
| Pre-compile to cache files | Somewhat isolated | Requires manual workaround, not elegant |
| Single agent batch processing | No duplication | Removes parallelism benefits |
| Current parallel (re-read each time) | Native parallel | Massive token waste |

Feature Request: Context Inheritance

Enable agents to inherit pre-loaded context from parent task:

# Parent context loads foundation data once
foundation_data = load_files([
  'code-style-guide.md',
  'architecture-patterns.md', 
  'shared-types.ts',
  'examples.json'
])

# Fork N child agents with inherited context
for item in items:
  Task(
    inherit_context=True,  # ← Inherit parent's loaded data
    prompt=f"Generate {item} using inherited context"
  )

Alternative API:

Task(
  fork_from=current_context,  # Snapshot parent context
  inherit_files=['style/**/*', 'patterns/**/*'],  # Or explicit file list
  prompt="Generate variant..."
)

Expected Benefits

| Metric | Current | With Forking |
|--------|---------|--------------|
| Token waste (50 tasks, 50KB master) | 2.5M tokens | 100K tokens |
| Token efficiency | 2% | 100% |
| Safe parallelization scale | 3-5 tasks | 50-100+ tasks |
| Cost per operation | High + master | Low (delta only) |
| Setup I/O | N reads | 1 read |

Implementation Considerations

  1. Context Snapshot: Capture parent LLM context state at fork point
  2. Memory Management: Share read-only foundation data across child agents
  3. Delta Context: Child agents only add new context for their specific task
  4. API Design: Simple flag like inherit_context=True or explicit data passing
  5. Limitations: Would need to respect context window limits with multiple forks

Why This Matters

This unlocks Claude Code for:

  • Design systems: Generate 50+ component variants without redundancy
  • Code generation pipelines: Scale to 100+ files/endpoints
  • Batch migrations: Handle 1000+ file transformations efficiently
  • Data processing: Process large datasets in parallel without token waste
  • Content platforms: Generate hundreds of variations economically

Alternatives Considered

  1. ❌ User manually manages data in prompts — Wastes context, fragile
  2. ❌ Pre-compile all data to JSON files — Works but hacky, not native
  3. ❌ Limit to single-agent batch — Removes parallelism benefits
  4. ✅ Native context inheritance — Clean, efficient, scalable

Links & References

---

This feature would transform Claude Code from a single-task tool into a powerful batch processing engine.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗