Documentation Generation
Automatically generate comprehensive, up-to-date documentation for your codebase using Gemini CLI's AI capabilities.
Why AI-Generated Documentation?
Documentation debt is one of the most universal problems in software engineering. Code gets written fast, documentation gets deferred, and eventually the two drift so far apart that the docs are more harmful than helpful. Teams that try to fix this manually face a brutal tradeoff: spend engineering time writing docs, or spend it shipping features.
Gemini CLI eliminates this tradeoff. Because it can read source code directly and understands the semantics of what functions do, it generates documentation that is accurate, detailed, and consistent — without requiring a human to write a single word. A single command can document an entire module; a shell script can document an entire codebase overnight.
More importantly, generated docs stay current. Because generating them is so cheap, you can regenerate the entire documentation set on every release, on every PR merge, or even on every commit. The docs are always exactly as current as the code.
Quick Examples
README Generation
gemini "Generate a comprehensive README for this project" . > README.md
API Documentation
gemini "Generate API documentation from this code" < api.js > docs/api.md
Code Comments
gemini "Add comprehensive JSDoc comments" < functions.js
API Documentation Generation
API documentation is the most high-value documentation you can write — it is what developers consult every time they integrate with your service. Gemini CLI can generate OpenAPI specs, Postman collections, Markdown reference pages, and inline code comments from your route and handler files.
Generate an OpenAPI specification
Feed your Express, Fastify, or Hono route files to Gemini CLI and get a complete OpenAPI 3.0 YAML file that you can import into Swagger UI, Redoc, or Postman.
# Generate OpenAPI spec from Express routes
gemini "Generate an OpenAPI 3.0 YAML specification from these Express route files. Include path parameters, request bodies with JSON Schema, response schemas for 200/400/401/404/500. Mark endpoints requiring auth with BearerAuth." \
src/routes/users.ts src/routes/orders.ts src/routes/products.ts \
> docs/openapi.yaml
# Serve the spec with Swagger UI
npx @redocly/cli preview-docs docs/openapi.yaml
Generate Markdown API reference
For documentation sites built with Docusaurus, VitePress, or plain Markdown, generate human-readable API reference pages directly:
# Generate Markdown API reference
gemini "Generate API documentation from this code" < api.js > docs/api.md
# Bulk-generate docs for all route files
for file in src/routes/*.ts; do
name=$(basename "$file" .ts)
gemini "Generate Markdown API docs. Include: endpoint URL, method, auth required, request parameters with types, response schema, and a curl example for each endpoint." \
< "$file" > "docs/api/$name.md"
done
Generate TypeScript SDK documentation
# Generate TypeDoc-compatible JSDoc for a TypeScript SDK
gemini "Add TypeDoc comments to every exported class, interface, and function. Include @example blocks showing real usage. Follow the TypeDoc @param and @returns tag conventions." \
< src/sdk/client.ts > src/sdk/client.documented.ts
# Then generate HTML docs
npx typedoc src/sdk/client.documented.ts --out docs/sdk
README Generation
A good README is the front door of your project. It needs to explain what the project does, how to install it, how to use it, and where to get help. Gemini CLI generates READMEs that follow community conventions and include all the sections that make a project professional and approachable.
Generate a comprehensive README
# Generate from the project root (reads package.json, src/, etc.)
gemini "Generate a comprehensive README for this project" . > README.md
# More specific prompt for an npm library
gemini "Generate a README for this npm library. Sections: Description, Installation, Quick Start (with code example), API Reference (link to docs), Contributing, License. Target audience: intermediate JavaScript developers." \
. > README.md
The generated README includes the project name, description, installation command, usage examples, and links to further documentation — everything a developer needs to evaluate and start using the library in under 5 minutes.
Generate component-level READMEs
For monorepos with multiple packages, generate individual READMEs for each package:
for pkg in packages/*/; do
gemini "Generate a concise README for this package. Include: purpose, exports, and a usage example." \
< "$pkg/src/index.ts" > "$pkg/README.md"
done
Code Comment Generation
Inline code comments and documentation blocks (JSDoc, docstrings, XML docs) are essential for developer experience when using a library or maintaining a codebase. Gemini CLI can add or improve comments without changing any of the code's behavior.
Add JSDoc to a JavaScript/TypeScript file
# Add JSDoc to every exported function
gemini "Add comprehensive JSDoc comments" < functions.js
# More specific — include @example tags
gemini "Add JSDoc comments to every exported function. Include: @description, @param (with type and description), @returns (with type and description), and an @example block showing a realistic usage scenario." \
< src/utils/dateHelpers.ts
Before
export function formatDate(date, locale) {
return new Intl.DateTimeFormat(locale).format(date)
}
After
/**
* Formats a Date object as a localized string.
* @param date - The date to format
* @param locale - BCP 47 language tag (e.g., "en-US")
* @returns Localized date string
* @example formatDate(new Date(), "en-GB") // "12/04/2026"
*/
export function formatDate(date: Date, locale: string): string {
return new Intl.DateTimeFormat(locale).format(date)
}
Add Python docstrings
# Add Google-style docstrings to Python functions
gemini "Add Google-style docstrings to every function and class in this file. Include Args, Returns, Raises, and Example sections where applicable." \
< src/data_processor.py
Changelog Automation
Changelogs communicate what changed between releases to your users and teammates. Writing them manually by reviewing git history is tedious. Gemini CLI can generate a well-structured changelog directly from your commit history, following the Keep a Changelog convention and suggesting a semantic version bump based on the nature of the changes.
Generate a CHANGELOG from git history
# Generate changelog for all commits since v1.0.0
git log --oneline v1.0.0..HEAD | gemini "Generate a CHANGELOG in Keep a Changelog format. Group commits into Added, Changed, Fixed, and Removed sections. Suggest the next semantic version based on the changes."
# For conventional commits, extract PR descriptions too
git log --format="%s%n%b" v1.0.0..HEAD | gemini "Generate a user-facing CHANGELOG from these conventional commits. Translate technical commit messages into plain English benefits for end users."
The "user-facing" framing is key: instead of "fix: resolve null pointer in auth middleware", the changelog reads "Fixed: Users could no longer be logged out unexpectedly in certain browsers." This is the kind of writing that users actually find useful.
Automate changelog generation in CI
#!/bin/bash
# run on every release tag push
PREV_TAG=$(git describe --tags --abbrev=0 HEAD~1)
CURR_TAG=$(git describe --tags --abbrev=0)
echo "## [$CURR_TAG] - $(date +%Y-%m-%d)" > new-section.md
git log --oneline "$PREV_TAG".."$CURR_TAG" | \
gemini "Convert to Keep a Changelog format. Add, Changed, Fixed, Removed sections." \
>> new-section.md
cat new-section.md CHANGELOG.md > CHANGELOG.tmp && mv CHANGELOG.tmp CHANGELOG.md
Documentation Types
Technical Documentation
- • API references
- • Function documentation
- • Code architecture guides
- • Installation instructions
User Documentation
- • User guides and tutorials
- • Getting started guides
- • FAQ sections
- • Troubleshooting guides
Automation Scripts
Batch Documentation Generator
#!/bin/bash
# generate-docs.sh
mkdir -p docs
find src -name "*.js" -o -name "*.ts" | while read file; do
echo "Documenting $file..."
docfile="docs/$(basename "$file" .js).md"
gemini "Generate comprehensive documentation" < "$file" > "$docfile"
done
echo "Documentation generated in docs/ directory"
Frequently Asked Questions
Can Gemini CLI generate JSDoc comments for an entire codebase?
Yes. Use a shell loop to process every file:find src -name '*.ts' | while read f; do gemini "Add JSDoc comments to every exported function. Include @param, @returns, and @example tags." < "$f" > "$f.tmp" && mv "$f.tmp" "$f"; doneRun your doc generator (TypeDoc, JSDoc) afterward to produce HTML output.
How do I keep generated documentation up to date as code changes?
Add a documentation generation step to your CI/CD pipeline. On every merge to main, run a script that pipes changed files (fromgit diff) to Gemini CLI and regenerates only the affected documentation pages. This keeps docs in sync without a full regeneration on every commit.
What is the best prompt for generating an OpenAPI spec from Express routes?
Use:gemini "Generate an OpenAPI 3.0 YAML specification from these Express route files. Include path parameters, request bodies with JSON Schema, and response schemas. Mark endpoints that require authentication with a BearerAuth security scheme." src/routes/*.ts > openapi.yaml
Can Gemini CLI generate a CHANGELOG from git history?
Yes. Run:git log --oneline v1.0.0..HEAD | gemini "Generate a CHANGELOG in Keep a Changelog format. Group commits into Added, Changed, Fixed, and Removed sections. Use semantic versioning to suggest the next version number based on the nature of the changes."
How do I generate documentation in a language other than English?
Simply specify the target language in your prompt:gemini "Generate README in Japanese. Follow standard Japanese technical writing conventions." . > README.ja.mdGemini CLI supports all major languages. For multilingual documentation, run the same prompt multiple times with different language instructions and save to different files.