name: doc-generate description: Generate documentation from code including API docs, README sections, and CLAUDE.md files. Use when documenting APIs, creating setup guides, or updating project documentation. argument-hint: [type] allowed-tools: Bash, Read, Glob, Grep, Write, Edit
Documentation Generator
Generate various types of documentation from code analysis.
Arguments
$0: Documentation type -api,readme,claude,setup,all(required)$1: Output path (optional - defaults to appropriate location)
Documentation Types
1. API Documentation (api)
Generate API endpoint documentation from code.
FastAPI Projects:
# FastAPI has built-in OpenAPI generation
curl http://localhost:8000/openapi.json > docs/openapi.json
# Or extract from code
grep -rn "@router\.\|@app\." --include="*.py" app/routes/
Template:
# API Documentation
## Base URL
`http://localhost:8000/v1`
## Authentication
All endpoints require JWT token in Authorization header:
`Authorization: Bearer <token>`
## Endpoints
### [Resource Name]
#### GET /resource
**Description:** Get list of resources
**Auth Required:** Yes
**Roles:** admin, staff
**Query Parameters:**
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| limit | int | No | Max items (default: 100) |
| offset | int | No | Skip items (default: 0) |
**Response:**
```json
{
"items": [],
"total": 0
}
**Next.js API Routes:**
```bash
# Find all API routes
find app/api -name "route.ts" -o -name "route.js"
2. README Documentation (readme)
Generate or update README.md sections.
Template:
# Project Name
## Overview
[Auto-generated from package.json/pyproject.toml description]
## Tech Stack
- **Framework:** [Detected framework]
- **Database:** [Detected database]
- **Testing:** [Detected test framework]
## Prerequisites
- Node.js >= 18 / Python >= 3.12
- [Database] installed and running
- Environment variables configured
## Quick Start
### Installation
```bash
[Package manager] install
Development
[Start command]
Testing
[Test command]
Project Structure
[Auto-generated directory tree]
Environment Variables
See .env.example for required variables.
API Documentation
See docs/api.md for API reference.
Contributing
[Standard contributing guidelines]
License
[License from package.json/pyproject.toml]
### 3. CLAUDE.md Documentation (`claude`)
Generate context file for Claude Code.
**Template:**
```markdown
# [Project Name]
## Project Overview
[Brief description of the project]
## Tech Stack
- **Language:** [Python/TypeScript]
- **Framework:** [FastAPI/Next.js/etc]
- **Database:** [MongoDB/PostgreSQL]
- **Package Manager:** [npm/pnpm/uv]
## Development Commands
### Start Development Server
```bash
[Start command]
Run Tests
[Test command]
Lint & Format
[Lint command]
Build
[Build command]
Project Structure
[Directory tree of important folders]
Key Files
[config file]- [Description][main entry]- [Description]
Environment Variables
Required variables (see .env.example):
VAR_NAME- [Description]
Testing Strategy
- Unit tests:
[path] - Integration tests:
[path] - E2E tests:
[path]
API Patterns
[Key patterns used in the codebase]
Common Issues
- [Issue]: [Solution]
Important Instructions
- [Key instruction 1]
- [Key instruction 2]
### 4. Setup Guide (`setup`)
Generate detailed setup instructions.
**Template:**
```markdown
# Setup Guide
## Prerequisites
### Required Software
- [ ] [Runtime] version X.X+
- [ ] [Database] version X.X+
- [ ] [Package manager]
### Verify Installation
```bash
[version check commands]
Installation Steps
1. Clone Repository
git clone [repo-url]
cd [project-name]
2. Install Dependencies
[install command]
3. Configure Environment
cp .env.example .env.local
# Edit .env.local with your settings
4. Setup Database
[database setup commands]
5. Run Migrations
[migration command]
6. Seed Data (Optional)
[seed command]
7. Start Development Server
[start command]
8. Verify Setup
Open http://localhost:[port] in your browser.
Troubleshooting
Common Issues
[Issue 1]
Symptom: [Description] Solution: [Fix]
[Issue 2]
Symptom: [Description] Solution: [Fix]
## Generation Process
### 1. Analyze Project
```bash
# Detect project type
if [ -f "pyproject.toml" ]; then
PROJECT_TYPE="python"
elif [ -f "package.json" ]; then
PROJECT_TYPE="node"
fi
# Extract metadata
# Python: pyproject.toml
# Node: package.json
# Find key files
ls -la
find . -name "*.md" -maxdepth 2
2. Extract Information
From package.json:
- name, description, version
- scripts (start, test, build)
- dependencies, devDependencies
From pyproject.toml:
- name, description, version
- dependencies
- scripts/commands
From code:
- Route definitions
- Model definitions
- Configuration patterns
3. Generate Output
Write documentation to appropriate location:
- API docs →
docs/api.md - README →
README.md - CLAUDE.md →
CLAUDE.md - Setup →
docs/setup.md
Output Format
Documentation Generation: [project-name]
Type: [api/readme/claude/setup/all]
Analyzing project...
Project type: [type]
Framework: [framework]
Database: [database]
Extracting information...
Routes found: X
Models found: Y
Config files: Z
Generating documentation...
Writing: [output-path]
Documentation generated successfully!
Files created:
- [file1]
- [file2]