16 KiB
CLAUDE.md - Infinite Loop Variant 3: Pluggable Agent Task Templates
This file provides guidance to Claude Code when working with the pluggable agent task template system.
Project Overview
This is an advanced infinite loop variant that uses pluggable agent task templates - reusable, parameterized blueprints for agent behavior. The system loads templates, substitutes parameters, and deploys parallel agents with complete, unambiguous instructions.
Core Innovation
Instead of hardcoding agent instructions in orchestrator commands, this system:
- Stores reusable task templates in
.claude/templates/ - Uses parameter substitution (
{{PARAMETER}}syntax) - Instantiates templates with specific values per iteration
- Deploys agents with fully formed, explicit instructions
- Follows Anthropic's "be clear and direct" prompt engineering principles
Key Commands
Running the Infinite Templated Loop
# Web-enhanced generation (5 iterations)
/infinite-templated web-research-generator specs/example_spec.md viz_output 5
# Pure code generation (10 iterations)
/infinite-templated code-generator specs/example_spec.md viz_output 10
# Infinite mode (continuous waves)
/infinite-templated web-research-generator specs/example_spec.md viz_output infinite params/url_strategy.json
# Analysis of existing artifacts
/infinite-templated analyzer specs/analysis_criteria.md reports/analysis.md 1 params/analysis_params.json
# Validation of artifacts
/infinite-templated validator specs/validation_rules.md reports/validation.md 1
Creating New Templates
# Interactive template creation
/create-template my-template-name generation "What this template does"
# Example: Create API testing template
/create-template api-tester testing "Tests REST APIs and generates test reports"
How to Work with Templates
Reading Templates
Templates are in .claude/templates/ directory. When examining a template:
- Understand the structure: Templates have 11 required sections
- Identify parameters: Look for
{{PARAMETER}}placeholders - Review execution steps: 3-7 numbered steps define agent behavior
- Check parameter table: All parameters documented with types and examples
Creating Templates
Follow this process (or use /create-template):
- Start with base-template.md: Copy structure
- Define agent role: What expertise and responsibilities?
- Write execution steps: 3-7 clear, sequential steps
- Document parameters: Create reference table
- Provide example: Show concrete usage
- Add validation: Checklist for agents
- Follow spec: See
specs/template_spec.md
Modifying Templates
When updating existing templates:
- Read current version: Understand existing structure
- Maintain sections: Don't remove required sections
- Update parameters: Keep parameter table in sync
- Test substitution: Ensure no unintended placeholders
- Update version: Increment version number
- Update examples: Keep examples current
Template System Architecture
Directory Structure
.claude/
├── commands/
│ ├── infinite-templated.md # Orchestrator - loads and instantiates templates
│ └── create-template.md # Template creation utility
├── templates/
│ ├── base-template.md # Template for making templates
│ ├── web-research-generator.md
│ ├── code-generator.md
│ ├── analyzer.md
│ └── validator.md
└── settings.json
specs/
├── example_spec.md # Example visualization spec
└── template_spec.md # Requirements for creating templates
docs/
└── template_guide.md # Template creation guide
examples/
└── template_usage.md # Concrete usage examples
Orchestrator Workflow
The /infinite-templated command:
-
Phase 1: Template Loading
- Reads template from
.claude/templates/{{name}}.md - Parses structure and parameters
- Validates template completeness
- Reads template from
-
Phase 2: Context Preparation
- Loads specification file
- Analyzes existing iterations
- Prepares URL strategy (for web templates)
-
Phase 3: Task Instantiation
- For each iteration:
- Creates parameter mapping
- Substitutes all
{{PARAMETER}}placeholders - Verifies uniqueness
- Results in complete agent task
- For each iteration:
-
Phase 4: Parallel Deployment
- Launches agents with instantiated tasks
- Agents work independently
- Collects results
-
Phase 5: Wave Management (infinite mode)
- Analyzes wave completion
- Prepares next batch
- Continues until context limits
-
Phase 6: Summary
- Reports results
- Quality checks
- Lists generated files
Parameter Substitution Mechanism
Templates use {{PARAMETER}} syntax:
**Template:**
Read file: `{{SPEC_FILE}}`
Generate output in: `{{OUTPUT_DIR}}/{{FILE_NAME}}`
Learn from: `{{WEB_URL}}`
Orchestrator creates mapping:
{
"SPEC_FILE": "specs/example_spec.md",
"OUTPUT_DIR": "viz_output",
"FILE_NAME": "viz_network_001.html",
"WEB_URL": "https://d3js.org/d3-force"
}
Instantiated task:
Read file: `specs/example_spec.md`
Generate output in: `viz_output/viz_network_001.html`
Learn from: `https://d3js.org/d3-force`
Available Templates
1. web-research-generator
Purpose: Fetch web resources, extract techniques, generate artifacts with applied learning
Key Features:
- WebFetch or WebSearch integration
- Technique extraction and documentation
- Progressive learning support
- Web source attribution
Use When:
- Learning from documentation
- Implementing from tutorials
- Applying best practices from web
- Progressive skill building
Parameters:
WEB_URL: URL to fetchLEARNING_FOCUS: What to extractMIN_TECHNIQUES: Minimum techniques to applyOUTPUT_DIR,SPEC_FILE,FILE_NAME, etc.
2. code-generator
Purpose: Generate code artifacts from specifications without web dependencies
Key Features:
- Theme-based variation
- Uniqueness assurance
- Creative interpretation
- Specification compliance
Use When:
- Creating variations of components
- Exploring creative themes
- Generating diverse implementations
- No external learning needed
Parameters:
THEME: Unique theme for iterationUNIQUE_FEATURES: Distinguishing characteristicsOUTPUT_DIR,SPEC_FILE,FILE_NAME, etc.
3. analyzer
Purpose: Analyze artifacts to extract patterns, metrics, and insights
Key Features:
- Systematic analysis
- Pattern detection
- Metrics collection
- Comprehensive reporting
Use When:
- Assessing quality across iterations
- Identifying patterns or trends
- Collecting metrics
- Generating analysis reports
Parameters:
TARGET_PATTERN: Files to analyzeCRITERIA_FILE: Analysis criteriaMETRICS: Metrics to collectOUTPUT_FILE: Report destination
4. validator
Purpose: Validate artifacts against requirements and standards
Key Features:
- Specification compliance checking
- Evidence-based pass/fail
- Remediation guidance
- Detailed reporting
Use When:
- Checking spec compliance
- Pre-deployment validation
- Quality assurance
- Standard adherence verification
Parameters:
VALIDATION_SPEC: Validation rulesTARGET_PATTERN: Files to validateCRITERIA_LIST: Specific criteriaOUTPUT_FILE: Report destination
Template Design Principles
Templates in this system follow Anthropic's "Be Clear and Direct" prompt engineering guidance:
1. Contextual Clarity
Templates provide complete context:
- Task purpose: Why is this task being performed?
- Workflow position: Where does it fit in larger process?
- Success criteria: What defines success?
- Constraints: What must the agent avoid or respect?
2. Explicit Instructions
Every template uses:
- Numbered steps: Sequential, ordered execution
- Step names: Clear description of what step does
- Detailed instructions: Exact actions to take
- Expected outputs: What each step should produce
3. "New Employee" Approach
Templates treat agents as capable but uninformed:
- Explain norms and styles
- Don't assume prior knowledge
- Provide examples
- Define all terms
4. Precision and Clarity
Templates are:
- Unambiguous (one interpretation)
- Specific (exact requirements)
- Complete (no missing information)
- Testable (verifiable success)
Working with Specifications
Specifications define WHAT to generate; templates define HOW to generate it.
Specification Requirements
Good specs for template system:
- Clear file naming patterns with placeholders
- Explicit structure requirements
- Quality standards defined
- Success criteria measurable
- Template parameter mappings provided
Spec-Template Relationship
Specification (example_spec.md)
↓
Defines: naming, structure, quality standards
↓
Template (web-research-generator.md)
↓
Defines: process, steps, agent behavior
↓
Orchestrator
↓
Combines spec + template + parameters
↓
Instantiated Agent Task
↓
Generated Artifact
Parameter Files
Optional JSON files provide additional parameters:
Structure
{
"PROJECT_NAME": "Project name here",
"PROJECT_DESCRIPTION": "Description",
"MIN_TECHNIQUES": 3,
"URL_STRATEGY": {
"foundation": ["url1", "url2"],
"intermediate": ["url3"],
"advanced": ["url4", "url5"]
},
"CUSTOM_PARAMETER": "value"
}
Usage
/infinite-templated template_name spec.md output_dir count params.json
Parameters from file merged with auto-generated parameters.
URL Strategy (for web-research-generator)
Progressive learning approach:
{
"URL_STRATEGY": {
"foundation": [
"https://example.com/getting-started",
"https://example.com/basics"
],
"intermediate": [
"https://example.com/advanced-guide",
"https://example.com/api-docs"
],
"advanced": [
"https://example.com/expert-techniques",
"https://example.com/optimization"
]
}
}
Orchestrator assigns URLs based on iteration sophistication.
Best Practices
When Creating Templates
- Start simple: 3 steps, add complexity as needed
- Be specific: "Generate HTML file" > "create output"
- Show examples: Concrete examples clarify instructions
- Test mentally: Walk through as if you're the agent
- Document everything: All parameters in reference table
- Follow spec: Use
specs/template_spec.mdas guide
When Using Templates
- Choose right template: Match template to task type
- Provide parameters: Required parameters must be provided
- Use parameter files: Complex configs in JSON files
- Check existing iterations: Avoid duplication
- Review outputs: Spot-check for quality
When Modifying System
- Read existing code: Understand current patterns
- Maintain compatibility: Don't break existing templates
- Update documentation: Keep docs in sync
- Test thoroughly: Verify templates still work
- Follow conventions: Parameter naming, file structure, etc.
Common Patterns
Creating Visualization Series
# Generate 20 visualizations with web learning
/infinite-templated web-research-generator specs/viz_spec.md viz_output 20 params/d3_urls.json
Quality Assurance Pipeline
# 1. Generate artifacts
/infinite-templated code-generator specs/component_spec.md components 10
# 2. Analyze quality
/infinite-templated analyzer specs/analysis_criteria.md reports/analysis.md 1
# 3. Validate compliance
/infinite-templated validator specs/validation_rules.md reports/validation.md 1
Progressive Learning Campaign
# Infinite mode with progressive URL difficulty
/infinite-templated web-research-generator specs/learning_spec.md output infinite params/progressive_urls.json
Troubleshooting
Template Not Found
Error: "Template {{name}} not found"
Solution:
- Check
.claude/templates/directory - Verify file name matches (kebab-case)
- List available templates
Missing Parameters
Error: "Required parameter {{PARAM}} not provided"
Solution:
- Check parameter reference table in template
- Provide via parameter file
- Check if parameter should be auto-generated
Instantiation Failure
Error: "Failed to substitute parameters"
Solution:
- Verify parameter file is valid JSON
- Check for circular parameter references
- Ensure all required parameters provided
Agent Execution Failure
Error: Agent fails during execution
Solution:
- Review agent's instantiated task
- Check if instructions are ambiguous
- Verify all required files/resources exist
- Update template to be more explicit
File Naming Conventions
- Templates:
kebab-case.md(e.g.,web-research-generator.md) - Commands:
kebab-case.md(e.g.,infinite-templated.md) - Specs:
snake_case.md(e.g.,example_spec.md) - Parameters:
UPPER_SNAKE_CASE(e.g.,WEB_URL,OUTPUT_DIR)
Development Workflow
Adding New Template Type
- Design template following
specs/template_spec.md - Create template file in
.claude/templates/ - Test with
/infinite-templated - Document in
docs/template_guide.md - Add example to
examples/template_usage.md - Update README.md available templates section
Extending Orchestrator
- Read
.claude/commands/infinite-templated.md - Understand 6-phase workflow
- Identify extension point
- Implement changes
- Test with existing templates
- Update documentation
Creating Domain-Specific System
- Clone this variant as starting point
- Create domain-specific templates
- Create domain-specific specs
- Customize parameter files
- Test workflow end-to-end
- Document domain-specific usage
Key Differences from Other Variants
vs. Original Infinite Loop
- Original: Agent instructions hardcoded in orchestrator
- This: Agent instructions in reusable templates
vs. Web-Enhanced Loop
- Web-Enhanced: Web learning built into orchestrator
- This: Web learning as one template option among many
vs. Pipeline Variant
- Pipeline: Sequential stages with fixed workflow
- This: Parallel agents with pluggable task templates
Unique Value Proposition
Maximum flexibility through template pluggability while maintaining maximum clarity through structured, explicit instructions based on prompt engineering best practices.
Resources
- Anthropic Documentation: https://docs.claude.com/en/docs/build-with-claude/prompt-engineering/be-clear-and-direct
- Template Spec:
specs/template_spec.md - Template Guide:
docs/template_guide.md - Usage Examples:
examples/template_usage.md - Base Template:
.claude/templates/base-template.md
Quick Reference
Command Syntax
/infinite-templated <template> <spec> <output_dir> <count> [params]
/create-template <name> <category> <description>
Template Sections (Required)
- Metadata header
- Template overview
- Agent role definition
- Task context
- Execution instructions (3-7 steps)
- Output specifications
- Template parameters reference
- Example usage
- Validation checklist
- Notes and best practices
- Footer
Parameter Syntax
- In templates:
{{PARAMETER}} - Naming:
UPPER_SNAKE_CASE - Types: string, number, path, url, list, object, glob
Template Categories
- generation
- analysis
- quality-assurance
- research
- testing
- documentation
Remember: Templates are contracts. Write them as if instructing a brilliant but completely uninformed colleague. Be explicit, provide context, show examples, and define success clearly.