Claude Code Sub-Agents: Agentic Programming for the Masses
Seven AI agents working together, extracting diagrams, generating images, and producing documents. No debugging. No Stack Overflow searches. Just natural language instructions orchestrating a sophisticated pipeline. This is the power of Claude Code sub-agents.
What You'll Learn
- 1. What Claude Code sub-agents are and how they differ from traditional code
- 2. The Agent Orchestra architecture pattern
- 3. How to define agents using natural language markdown files
- 4. Comparison with CrewAI and AutoGen frameworks
- 5. Building a real-world documentation pipeline
The Paradigm Shift
Picture this: A complete documentation pipeline that extracts Mermaid diagrams from markdown, generates images, and produces Word and PDF documents. It handles UTF-8 errors automatically. It retries failed operations. And it was built without writing a single line of traditional code.
This represents a significant shift in how we develop software. Instead of programming,
you describe what you want. Instead of debugging, the system self-heals. Instead of
Stack Overflow, you have intelligent agents living in a simple .claude/agents/ folder.
What Are Claude Code Sub-Agents?
Claude Code's sub-agent system goes beyond traditional code completion. Sub-agents are specialized AI workers defined in simple markdown files with natural language instructions. Each agent becomes an expert at one specific task.
Think of it as hiring a team of specialists who never sleep, never complain, and always follow instructions perfectly.
How Sub-Agents Work
Sub-agents live in your project's .claude/agents/ directory as simple markdown files.
Each file defines an agent with a specific role and capabilities:
- Natural Language Definition - Agents are created using plain English instructions, not code
- Tool Integration - Each agent can access specific tools (file operations, command execution, API calls)
- Orchestration - Agents coordinate with each other to complete complex workflows
- Context Awareness - Agents understand project structure and make intelligent decisions
---
name: workflow-orchestrator
description: Main coordinator for documentation pipeline
tools: Read, Write, Bash, Glob, Task
---
You are the Workflow Orchestrator for the documentation pipeline.
## Primary Responsibilities
1. **Workflow Planning and Execution**
- Analyze input files and create execution plan
- Determine optimal processing sequence
- Manage dependencies between tasks
2. **Agent Coordination**
- Invoke specialized agents in proper sequence
- Pass context and results between agents
- Handle parallel processing where possible
3. **Error Recovery**
- Implement retry logic for transient failures
- Activate fallback agents when needed
- Ensure pipeline continues despite individual failures The Agent Orchestra Architecture
The most powerful pattern for sub-agents is the Agent Orchestra. One conductor (the orchestrator) manages the entire workflow while specialized agents handle specific tasks.
The Four Layers
Orchestration Layer
Manages the workflow with the orchestrator controlling everything
Content Processing
Handles extraction, transformation, and sanitization of content
Generation Layer
Creates the final outputs (images and documents)
Infrastructure
Maintains the file system and organization
The Magnificent Seven: A Real Example
Here's a complete agent orchestra for documentation processing:
The Seven Agents
| Agent | Role |
|---|---|
| workflow-orchestrator | Project Manager - coordinates all other agents |
| mermaid-extractor | Detective - scans markdown and extracts diagrams |
| image-generator | Artist - converts Mermaid code to PNG images |
| markdown-rebuilder | Editor - replaces code blocks with image links |
| pandoc-converter | Publisher - generates PDFs and Word documents |
| utf-sanitizer | Problem Solver - fixes UTF-8 encoding errors |
| file-organizer | Office Manager - maintains directory structure |
The Workflow Sequence
Here's how the agents collaborate to transform markdown into professional documents:
- User Request triggers the entire pipeline
- Workflow Orchestrator takes control and manages the flow
- File Organizer sets up the directory structure first
- Mermaid Extractor finds all diagrams in markdown files
- Image Generator converts diagrams to PNG images
- Markdown Rebuilder replaces code blocks with image links
- Pandoc Converter attempts document generation
- Decision point checks for UTF-8 errors
- UTF Sanitizer cleans problematic characters if needed
- File Organizer performs final cleanup
Comparison: Claude Code vs CrewAI vs AutoGen
How does Claude Code compare to other popular agent frameworks?
| Feature | Claude Code | CrewAI | AutoGen |
|---|---|---|---|
| Definition Language | Natural Language (Markdown) | Python | Python |
| Learning Curve | Low | Medium | High |
| Programming Required | No | Yes | Yes |
| Accessibility | Anyone | Developers | Researchers |
| Self-Healing | Built-in | Custom code | Custom code |
The fundamental difference is accessibility. While CrewAI and AutoGen require programming knowledge and complex setup, Claude Code democratizes AI orchestration. A business analyst can create a data processing pipeline, a technical writer can build a documentation system, and a developer can prototype complex workflows - all without writing traditional code.
The Key Differentiator
Claude Code represents a paradigm shift: from "code that calls AI" to "AI that occasionally executes code." This natural language approach to automation makes sophisticated AI orchestration available to anyone who can clearly describe what they want to accomplish.
"Just as spreadsheets were a way for ordinary people to interact with computers and perform computing tasks without mastering programming, Claude Code sub-agents might be the VisiCalc of agentic development."
Getting Started
Ready to build your own agent orchestra? Here's the minimal setup:
# Create the agents directory
mkdir -p .claude/agents
# Create your first agent
cat > .claude/agents/my-first-agent.md << 'EOF'
---
name: my-first-agent
description: My first Claude Code sub-agent
tools: Read, Write, Bash
---
You are a helpful assistant that [describe what it does].
## Responsibilities
1. [First task]
2. [Second task]
## Behavior
- Always [expected behavior]
- Never [things to avoid]
EOF Then invoke it in Claude Code:
# In Claude Code
> Use my-first-agent to [describe your task] Next Steps
You now understand the fundamentals of Claude Code sub-agents. In the next guide, we'll build a complete documentation pipeline step by step, showing you exactly how to create and orchestrate multiple agents for real-world automation.
Ready to Orchestrate?
Explore existing skills that use sub-agents, or continue to the next guide to build your own documentation pipeline.