Skip to content

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

  1. 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 to docs/reference/services.mdx.

  2. Set the format

    Specify frontmatter and structure so the output matches your docs system.

    ---
    title: Services Reference
    description: API reference for the services module.
    ---
  3. Review for accuracy

    OpenCode may infer behavior that isn’t true — verify each description against the code, especially edge cases.

  4. Wire into the build

    Add the generated page to your sidebar/docs pipeline so it’s published.

  5. 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.

Next up