Issue 16 | Routine Document Fully Automated Generation Pipeline
🎯 Learning Objectives
After completing this issue, you will master:
- How to make Claude Code automatically generate API documentation based on source code
- Batch generation of weekly reports, iteration logs, and CHANGELOGs using Print Mode
- Git-driven automated documentation update process
- Practical methods for Docs-as-Code
📖 Core Concepts Explained
16.1 Documentation Pain Points: Written but not updated, updated but not written
Developer's Documentation Dilemma:
README written → Not updated for three months → New hires follow it and get everything wrong
API documentation written → 5 new interfaces added but not synchronized → Customer reports Bug
Weekly report to write → Spend 30 minutes every Friday → Copy and paste last week's
Solution: Let code write documentation, let Git write weekly reports
16.2 Three Modes of Documentation Automation
Mode 1: Source Code → Documentation
Read code comments and type definitions
→ Automatically generate API Reference
Suitable for: API documentation, SDK documentation, component documentation
Mode 2: Git → Documentation
Read git log / PR / Issues
→ Automatically generate CHANGELOG, weekly reports
Suitable for: Iteration logs, team weekly reports, release notes
Mode 3: Hybrid Mode
Source Code + Git + Configuration Files
→ Generate a complete project documentation site
Suitable for: README, Onboarding Guide
💻 Simulating Claude TUI Interaction
Scenario 1: Automatic API Documentation Generation
> Read all route files under src/routes/,
automatically generate a complete API documentation
╭─ Claude ─────────────────────────────────────────────╮
│ │
│ 🔍 Tool: Glob → src/routes/**/*.ts │
│ Found 12 route files │
│ │
│ 🔍 Tool: Read → (reading one by one) │
│ │
│ ⚙️ Tool: Write → docs/api-reference.md │
│ │
│ ✅ API documentation generated! Found 34 endpoints in total:│
│ │
│ ### User Module (8 Endpoints) │
│ | Method | Path | Description | │
│ |--------|---------------|-------------| │
│ | GET | /api/users | User List | │
│ | POST | /api/users | Create User | │
│ | GET | /api/users/:id | User Details| │
│ | PUT | /api/users/:id | Update User | │
│ | DELETE | /api/users/:id | Delete User | │
│ | ... | │
│ │
│ Each endpoint includes: │
│ - Request parameters (inferred from TypeScript types)│
│ - Response format (inferred from return statements) │
│ - Authentication requirements (inferred from middleware)│
│ - Example curl command │
│ │
╰──────────────────────────────────────────────────────╯
Scenario 2: Git-Driven Automatic Weekly Report
> Generate a weekly report based on this week's git log
╭─ Claude ─────────────────────────────────────────────╮
│ │
│ ⚙️ Tool: Bash │
│ $ git log --since="7 days ago" --oneline │
│ --format="%h %s (%an)" │
│ │
│ 📋 This Week's Development Report (2024.03.18 - 2024.03.22):│
│ │
│ ## ✅ Completed │
│ - **User Module**: Optimized registration process (#234)│
│ - **Payment System**: Integrated Stripe payment (#241)│
│ - **Performance Optimization**: Reduced homepage loading time by 40%│
│ │
│ ## 📊 Data Overview │
│ - Commits this week: 47 │
│ - Files involved: 82 │
│ - Lines added: 2,340 / Lines deleted: 890 │
│ - PRs merged: 8 │
│ │
│ ## 🔜 Next Week's Plan │
│ (Inferred from open issues): │
│ - #245: Order export feature │
│ - #248: Mobile adaptation │
│ │
╰──────────────────────────────────────────────────────╯
💻 Code Demonstration
# ✅ Generate API documentation from source code
claude -p "Read all files under src/routes/,
generate API documentation in Markdown format to docs/api.md"
# ✅ Automatically generate CHANGELOG
claude -p "Based on git log --since='last month'
generate CHANGELOG.md, categorized by feature"
# ✅ Weekly report generation
claude -p "Based on this week's git log and closed issues,
write a project weekly report in Chinese"
# ✅ README automatic update
claude "Based on the current project's actual file structure and package.json,
update the installation instructions and project structure diagram in README.md"
# ✅ Component documentation
claude "Scan all React components under src/components/,
generate Props documentation and usage examples for each component"
Git Hook Automated Documentation Update
# Add automatic documentation update to .git/hooks/pre-commit
#!/bin/bash
# If route files have changed, automatically update API documentation
if git diff --cached --name-only | grep "src/routes/"; then
claude -p "src/routes/ has changed,
please update docs/api.md" --allowedTools Read,Write
fi
🔧 Involved Tools
| Tool | Doc Generation Stage | Purpose |
|---|---|---|
Glob |
Discovery | Scans source file directories |
Read |
Parsing | Reads code and comments |
Bash |
Git Query | Retrieves commit/PR/issue data |
Write |
Output | Generates Markdown documentation |
Edit |
Update | Incrementally updates existing documentation |
📝 Key Takeaways from this Issue
- Source Code as Documentation: Let Claude automatically extract documentation from code
- Git as Weekly Report: Automatically generate reports from commit logs
- Print Mode (
claude -p) is suitable for batch documentation generation tasks - Git Hooks can achieve automatic synchronized documentation updates
- Documentation generation is a high ROI scenario that benefits both PMs and developers