Sub-Agents in Claude Code
Running Sub-Agents in Claude Code for Automated Documentation
Claude Code supports sub-agents, which are separate agent loops with fresh token contexts. Each sub-agent is dispatched to accomplish a specific goal and then reports back when finished.
In June, I documented how these operate by tracing and intercepting Claude Code’s API calls.
Recently, I discovered you can intentionally prompt Claude Code to use sub-agents simply by asking it to do so.
---
Example: Documenting Template Contexts in a Project
I ran the following in Claude Code against a fresh checkout of simonw/datasette at commit `ec38ad37689f3c14d307770977a17aed5efc5cb9` — no custom instructions added:
> Write markdown documentation for the context passed to each of the templates in this project. Use sub-agents.
---
Output Snippet
Below is part of what Claude Code produced:
⏺ I'll help you write Markdown documentation for the context passed to each template in this project.
First, I'll explore the codebase to understand the template structure and then use sub-agents to document them comprehensively.
⏺ Search(pattern: "**/*.html")
⎿ Found 47 files (ctrl+o to expand)
⏺ Search(pattern: "render.*template|render_template")
⎿ Found 16 files (ctrl+o to expand)
[...]
⏺ Now let me launch sub-agents to analyze different template contexts in parallel:
⏺ Task(Document index template context)
⎿ Done (12 tool uses · 86.4k tokens · 1m 13s)
⏺ Task(Document database template context)
⎿ Done (15 tool uses · 55.4k tokens · 1m 41s)
⏺ Task(Document table template context)
⎿ Done (14 tool uses · 85.2k tokens · 1m 44s)
⏺ Task(Document query/row template contexts)
⎿ Done (17 tool uses · 78.7k tokens · 1m 55s)
⏺ Task(Document special template contexts)
⎿ Done (26 tool uses · 116.1k tokens · 1m 50s)
Key points:
- Sub-agents ran in parallel, improving speed.
- Each agent focused on a specific subset of templates.
- Process completed in just a few minutes.
- Result: a very comprehensive `template_contexts.md` file.
---
Why Parallel Sub-Agent Analysis Matters
Using sub-agents to break down complex tasks:
- Accelerates documentation for large codebases.
- Enables systematic scanning of multiple contexts.
- Reduces risk of missing parameters.
- Improves maintainability.
---
Integrating AI-Powered Publishing Workflows
For teams creating or maintaining technical documentation, agent-based automation pairs well with modern multi-platform publishing tools.
Example: AiToEarn
- Create: AI-assisted drafting of docs, guides, or technical blogs.
- Publish: Distribute content to multiple platforms in one step — including GitHub Pages, Dev.to, Douyin, Kwai, WeChat, Bilibili, Xiaohongshu (Rednote), Facebook, Instagram, LinkedIn, Threads, YouTube, Pinterest, and X (Twitter).
- Analyze: Built-in analytics and AI model rankings.
- Monetize: Opportunities to generate revenue from your technical content.
Benefits for Documentation Teams:
- Streamlined work — one workflow for drafting, publishing, and tracking.
- Wide reach — maximize visibility across developer and social channels.
- Consistent quality — AI ensures completeness and clarity in produced content.
- Faster iteration — analytics inform immediate improvements.
---
In summary:
Prompting Claude Code to use sub-agents can turn a documentation task that might take hours into one completed in minutes — while tools like AiToEarn can help you push that content to audiences everywhere, efficiently and with measurable impact.