Skip to content

commandDocumentation

Generate API Docs

Builds API reference pages from your source code in the docs format and folder your project already uses.

npx workspacetemplates add generate-api-docs --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/generate-api-docs.md15 lines · 1.3 KBFile
---
description: Builds API reference pages from your source code in the docs format and folder your project already uses.
argument-hint: "[module, folder or route file]"
---

Generate API reference documentation for: $ARGUMENTS (folder, module or route file; whole public API if empty).

1. Find the existing docs format first: look in docs/, a docs site config (mkdocs.yml, docusaurus, typedoc, sphinx), or an openapi file. Match its folder, front matter, heading levels and page layout. If nothing exists, use one Markdown page per module.
2. Enumerate the public surface. For web services: every route with method, path, auth requirement, path and query parameters, request body and response shapes. For libraries: exported functions and types with signatures.
3. Take descriptions from existing doc comments. Where there are none, write a plain description from the code and mark it `(inferred)`.
4. Document errors: status codes or exceptions and when each occurs, read from the handler code.
5. Include one runnable example per entry, such as a curl command or a short code call, using realistic values.
6. Compare with the pages already there. Update changed entries and list entries that no longer exist in code; do not delete them.

Show a summary of pages created and updated and the list of inferred items, then ask before writing files.

What it does

Reference docs written by hand fall behind the code within a sprint. This command reads the public surface, whether routes or exported functions, and writes pages in the style of the documentation you already have.

Every entry comes from the source: names, parameters, types and error cases. Anything the code does not make clear is flagged for you instead of guessed, and existing pages are updated rather than duplicated.

Example

you › /generate-api-docs src/routes/orders

agent › Plan: update docs/api/orders.md (3 endpoints changed), add DELETE /orders/{id}. 5 descriptions marked (inferred). 1 documented endpoint, GET /orders/export, no longer exists in code. Write the pages?

Questions

Which doc formats can it produce?
Whatever your project already uses, such as Markdown pages, OpenAPI YAML or doc-site files. It starts with Markdown if there is nothing yet.
Will it remove pages for deleted endpoints?
No. It lists them for you to decide.
  • Document Function

    CommandDocumentation

    Free
  • Explain Error

    CommandDocumentation

    Free
  • Repository Code Tour

    CommandDocumentation

    Free
  • Update README

    CommandDocumentation

    Free