generate-docs
You are the orchestrator for a documentation-generation pipeline. Coordinate five phases —
Bootstrap → Explore → Generate → Verify → Context Update — in an iterative loop until every
document meets grade A on every rubric dimension, or the retry budget is exhausted.
Detailed instructions for each phase live in references/. Read the relevant reference file when you
reach that phase (progressive disclosure — don't load them all up front).
| Phase |
What it does |
Read |
| 0 — Bootstrap |
Detect/back-up/create CLAUDE.md; note AGENTS.md |
references/context-files.md |
| 1 — Explore |
Scan the codebase across 8 domains → docs/_exploration_report.md |
references/exploration.md |
| 2 — Generate |
Write ~15 docs in docs/ with Mermaid diagrams |
references/generation.md |
| 3 — Verify |
Grade every doc A–F against the source → docs/_verification_report.md |
references/verification.md + references/grading-rubric.md |
| 4 — Context Update |
Update CLAUDE.md + write AGENTS.md (progressive disclosure) |
references/context-files.md |
Configuration
- Max retries: the first argument, if given (e.g.
generate-docs 5). If blank or non-numeric,
default to 3.
- Output directory:
docs/ at the project root.
- Passing grade: A on every document and every rubric dimension.
- Completion: when ALL docs score A across ALL dimensions, or max retries is reached.
How to run the phases (any harness)
This skill is harness-agnostic. Each phase is a batch of independent work that parallelizes cleanly:
- If your harness supports subagents / parallel tasks (e.g. a Task tool, an agent-spawn
primitive, or a workflow engine): dispatch the phase's work as parallel subagents — 8 explorers in
Phase 1, up to 15 writers in Phase 2, 1 verifier in Phase 3. Give each subagent the matching
references/ file as its instructions, plus its specific brief/doc. Prefer read-only tools for
explorers and verifiers.
- If your harness has no subagents: perform each phase's work yourself, sequentially, following
the same
references/ files. The output is identical; only the wall-clock time differs.
Whichever mode you use, the phase boundaries, working files, and grading are the same.
Iteration loop
Phase 0: Bootstrap (run once)
iteration = 0
max_retries = first argument or 3
WHILE iteration < max_retries:
iteration += 1
IF iteration == 1:
Run Phase 1 (Explore)
Run Phase 2 (Generate ALL docs)
ELSE:
Run Phase 2 ONLY for docs that scored below A,
using the verifier's feedback (revision mode). Preserve passing docs.
Run Phase 3 (Verify)
IF verdict == PASS:
Run Phase 4 (Context Update); BREAK → success
IF iteration == max_retries:
Run Phase 4 (Context Update, even on partial pass); BREAK → partial success
Print the summary table.
Final output
When the loop ends, print a summary to the console:
📚 Documentation Generation Report
Iteration: {n} / {max_retries}
Verdict: {PASS ✅ | FAIL ❌}
CLAUDE.md: {Created ✨ | Updated 🔄 | Unchanged ─}
AGENTS.md: {Created ✨ | Updated 🔄 | Unchanged ─}
Document CMP ACC CLR DIA COV Overall
README.md ...
architecture.md ...
tech-stack.md ...
api-reference.md ...
database-schema.md ...
frontend-backend.md ...
services.md ...
workflows-and-triggers.md ...
devops.md ...
glossary.md ...
error-catalog.md ...
testing-strategy.md ...
environment-setup.md ...
coding-conventions.md ...
security.md ...
Docs generated: docs/ (15 files)
Context updated: CLAUDE.md, AGENTS.md
SpecKit-ready: docs/ structure compatible with /speckit.analyze
On FAIL, also list the specific failing dimensions and the verifier's feedback for each doc.
Critical rules
- Never invent information. Document only what actually exists in the codebase.
- Always include Mermaid diagrams where the doc table marks them "Required".
- Verify against code, not just the exploration report. The verifier reads actual source files.
- On retries, only regenerate failing docs — never the whole set.
- Preserve passing docs across iterations — do not overwrite docs that already scored A.
- The exploration and verification reports are working files (
docs/_*.md) — don't delete them.
- Be honest about gaps. Flag uncertainties with
⚠️ rather than guessing.
- CLAUDE.md stays under ~200 lines total; the auto-generated section under 80. Use progressive
disclosure — point to docs, don't duplicate their content.
- Never delete human-written CLAUDE.md content. Only manage the marked auto-generated section.
- AGENTS.md is tool-agnostic — no Claude-specific syntax; keep it under 120 lines.
- Structure for AI agents. Explicit headings, tables, and "Read when" triggers so SpecKit,
Cursor, Copilot, and other tools can extract context efficiently.
1---2name: generate-docs3description: Generates a complete, verified documentation suite for a codebase and wires it into AI-agent context files. Runs a multi-phase explore → generate → verify loop: scans the repo, writes ~15 docs in docs/ (architecture, API reference, database schema, services, glossary, error catalog, security, and more) with Mermaid diagrams, grades every doc A–F on 5 dimensions against the actual source code, and regenerates failing docs until all pass. Then updates CLAUDE.md (progressive-disclosure section) and creates AGENTS.md for cross-tool compatibility. Use when the user asks to document a codebase, generate or refresh project documentation, create a docs/ suite, or bootstrap/update CLAUDE.md or AGENTS.md context files. Harness-agnostic — works with or without subagents.4license: MIT5---67# generate-docs89You are the **orchestrator** for a documentation-generation pipeline. Coordinate five phases —10**Bootstrap → Explore → Generate → Verify → Context Update** — in an iterative loop until every11document meets grade **A** on every rubric dimension, or the retry budget is exhausted.1213Detailed instructions for each phase live in `references/`. Read the relevant reference file when you14reach that phase (progressive disclosure — don't load them all up front).1516| Phase | What it does | Read |17|-------|--------------|------|18| 0 — Bootstrap | Detect/back-up/create CLAUDE.md; note AGENTS.md | `references/context-files.md` |19| 1 — Explore | Scan the codebase across 8 domains → `docs/_exploration_report.md` | `references/exploration.md` |20| 2 — Generate | Write ~15 docs in `docs/` with Mermaid diagrams | `references/generation.md` |21| 3 — Verify | Grade every doc A–F against the source → `docs/_verification_report.md` | `references/verification.md` + `references/grading-rubric.md` |22| 4 — Context Update | Update CLAUDE.md + write AGENTS.md (progressive disclosure) | `references/context-files.md` |2324## Configuration2526- **Max retries**: the first argument, if given (e.g. `generate-docs 5`). If blank or non-numeric,27 default to **3**.28- **Output directory**: `docs/` at the project root.29- **Passing grade**: **A** on every document and every rubric dimension.30- **Completion**: when ALL docs score A across ALL dimensions, or max retries is reached.3132## How to run the phases (any harness)3334This skill is harness-agnostic. Each phase is a batch of independent work that parallelizes cleanly:3536- **If your harness supports subagents / parallel tasks** (e.g. a Task tool, an agent-spawn37 primitive, or a workflow engine): dispatch the phase's work as parallel subagents — 8 explorers in38 Phase 1, up to 15 writers in Phase 2, 1 verifier in Phase 3. Give each subagent the matching39 `references/` file as its instructions, plus its specific brief/doc. Prefer read-only tools for40 explorers and verifiers.41- **If your harness has no subagents**: perform each phase's work yourself, sequentially, following42 the same `references/` files. The output is identical; only the wall-clock time differs.4344Whichever mode you use, the phase boundaries, working files, and grading are the same.4546## Iteration loop4748```49Phase 0: Bootstrap (run once)5051iteration = 052max_retries = first argument or 35354WHILE iteration < max_retries:55 iteration += 15657 IF iteration == 1:58 Run Phase 1 (Explore)59 Run Phase 2 (Generate ALL docs)60 ELSE:61 Run Phase 2 ONLY for docs that scored below A,62 using the verifier's feedback (revision mode). Preserve passing docs.6364 Run Phase 3 (Verify)6566 IF verdict == PASS:67 Run Phase 4 (Context Update); BREAK → success68 IF iteration == max_retries:69 Run Phase 4 (Context Update, even on partial pass); BREAK → partial success7071Print the summary table.72```7374## Final output7576When the loop ends, print a summary to the console:7778```79📚 Documentation Generation Report80Iteration: {n} / {max_retries}81Verdict: {PASS ✅ | FAIL ❌}82CLAUDE.md: {Created ✨ | Updated 🔄 | Unchanged ─}83AGENTS.md: {Created ✨ | Updated 🔄 | Unchanged ─}8485Document CMP ACC CLR DIA COV Overall86README.md ...87architecture.md ...88tech-stack.md ...89api-reference.md ...90database-schema.md ...91frontend-backend.md ...92services.md ...93workflows-and-triggers.md ...94devops.md ...95glossary.md ...96error-catalog.md ...97testing-strategy.md ...98environment-setup.md ...99coding-conventions.md ...100security.md ...101102Docs generated: docs/ (15 files)103Context updated: CLAUDE.md, AGENTS.md104SpecKit-ready: docs/ structure compatible with /speckit.analyze105```106107On FAIL, also list the specific failing dimensions and the verifier's feedback for each doc.108109## Critical rules1101111. **Never invent information.** Document only what actually exists in the codebase.1122. **Always include Mermaid diagrams** where the doc table marks them "Required".1133. **Verify against code, not just the exploration report.** The verifier reads actual source files.1144. **On retries, only regenerate failing docs** — never the whole set.1155. **Preserve passing docs** across iterations — do not overwrite docs that already scored A.1166. **The exploration and verification reports are working files** (`docs/_*.md`) — don't delete them.1177. **Be honest about gaps.** Flag uncertainties with `⚠️` rather than guessing.1188. **CLAUDE.md stays under ~200 lines total; the auto-generated section under 80.** Use progressive119 disclosure — point to docs, don't duplicate their content.1209. **Never delete human-written CLAUDE.md content.** Only manage the marked auto-generated section.12110. **AGENTS.md is tool-agnostic** — no Claude-specific syntax; keep it under 120 lines.12211. **Structure for AI agents.** Explicit headings, tables, and "Read when" triggers so SpecKit,123 Cursor, Copilot, and other tools can extract context efficiently.