Automate Docs Generation
Turn source code into maintained documentation. OpenCode reads your modules, extracts the public API, and writes reference docs you can drop straight into your docs site.
When to use this recipe
- Your API reference always lags behind the code.
- You onboarding docs need to reflect current module structure.
- You want consistent formatting across many doc pages.
Prerequisites
- A codebase with typed functions/classes (TypeScript, Go, etc.) for accuracy.
- OpenCode configured in the project.
Steps
-
Point at the source
Tell OpenCode which modules to document and the output location.
Document every exported function in
src/services/. For each, write a section with signature, parameters, return type, and a one-line example. Output todocs/reference/services.mdx. -
Set the format
Specify frontmatter and structure so the output matches your docs system.
--- title: Services Reference description: API reference for the services module. --- -
Review for accuracy
OpenCode may infer behavior that isn’t true — verify each description against the code, especially edge cases.
-
Wire into the build
Add the generated page to your sidebar/docs pipeline so it’s published.
-
Schedule refreshes
Re-run the same prompt after major changes to keep the docs in sync.
Key prompt
Read every exported symbol in
src/services/and generate a Markdown reference. Include the signature, parameter descriptions, return type, and a concrete example for each. Do not invent behavior — if unsure, mark it as “needs review”.
Common pitfalls
- Hallucinated behavior: Always cross-check generated descriptions against the actual implementation.
- Stale docs: Generated docs rot fast — treat the prompt as part of your release process.
- Private internals: Explicitly exclude internal/non-exported symbols to avoid leaking implementation details.
Related recipes
- slide-generation —
reason.doc.to-slide - explore-unfamiliar-codebase —
reason.doc.to-explore - custom-skill —
reason.doc.to-skill
Related docs
Next up
- slide-generation —
next.doc.to-slide