Feature Request: Context Inheritance for Batch/Iterator Operations — Enable Efficient Parallel Execution
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:
- Redundant File I/O: Foundation data (code style guides, API specs, design systems, etc.) is re-read for every parallel task
- Context Window Waste: Identical setup data (examples, configurations, constraints) duplicates across every agent's context
- Exponential Token Cost: For N parallel tasks with shared 50KB master data, current approach wastes ~50KB × (N-1) tokens
- 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
- Context Snapshot: Capture parent LLM context state at fork point
- Memory Management: Share read-only foundation data across child agents
- Delta Context: Child agents only add new context for their specific task
- API Design: Simple flag like
inherit_context=Trueor explicit data passing - 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
- ❌ User manually manages data in prompts — Wastes context, fragile
- ❌ Pre-compile all data to JSON files — Works but hacky, not native
- ❌ Limit to single-agent batch — Removes parallelism benefits
- ✅ Native context inheritance — Clean, efficient, scalable
Links & References
- Claude Code Task tool: https://github.com/anthropics/claude-code
- Potential use cases: Design token generation, batch code generation, data migrations, content generation pipelines
---
This feature would transform Claude Code from a single-task tool into a powerful batch processing engine.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗