English | 中文
Reverse-engineer business logic from code. Generate professional documentation covering the entire software delivery lifecycle.
Documentation drift is entropy, not negligence. Code has CI/lint/compiler errors as feedback loops — documentation has none, so it inevitably rots. code2doc is the solution: treat code as the single source of truth, and continuously generate or calibrate documentation.
ClawHub: https://clawhub.ai/suifei/code-to-doc-generator
Skillhub:https://skillhub.cn/skills/code-to-doc-generator
Given any code repository (web, backend services, mobile, desktop), code2doc can reverse-engineer and generate 12 standard software delivery documents:
| Phase | Document Type | Target Audience |
|---|---|---|
| Initiation | BRD (Business Requirements) · MRD (Market Requirements) | Executives, Investors |
| Requirements | PRD (Product Requirements) | Product Managers, Tech Leads |
| Architecture | HLD (High-Level Design) · DDD (Domain-Driven Design) | Architects, Tech Leads |
| Implementation | LLD (Low-Level Design) · Coding Guidelines | Developers |
| Verification | Test Documents (BDD/SIT/E2E/UAT) | QA Engineers |
| Operations | Ops Manual · Admin Quick Reference · SLI/SLO Monitoring | Ops Staff, SRE |
| Release | CI/CD Pipeline Documentation | DevOps Engineers |
- Code as Truth: All content is extracted directly from code. Inferences are marked with
〔INFER〕, code facts are traced with〔FACT|file:line〕 - Audience-Adaptive: Ops manuals avoid technical jargon; HLD/LLD retain precise engineering language; BRD/MRD are fully business-oriented for executives
- Reverse Sync: Run
Reverse Sync Modeafter code changes to automatically detect documentation drift and calibrate - Rigorous Structure: Ops documents require 🔗 prerequisite dependency chains + 📊 impact tracking matrices (including underlying algorithm/strategy names)
- Any Tech Stack: Go · Python · Node.js · Java · Swift · Kotlin · Flutter · React · Vue · Electron
Claude Code is Anthropic's official CLI tool with native skill format support.
Option A: Project-Level (current project only)
# Run in project root
mkdir -p .claude/skills
git clone https://github.com/suifei/code2doc .claude/skills/code2docAdd to your project's CLAUDE.md:
## Skills
@.claude/skills/code2doc/SKILL.mdOption B: Global (all projects)
mkdir -p ~/.claude/skills
git clone https://github.com/suifei/code2doc ~/.claude/skills/code2docAdd to ~/.claude/CLAUDE.md:
## Skills
@~/.claude/skills/code2doc/SKILL.mdUsage:
# Generate an operations manual
> Generate operations manual
# Generate HLD
> Write HLD for me
# Reverse sync — code changed but docs are out of date
> Sync documentation
OpenCode supports the same skill directory structure as Claude Code.
# Clone to OpenCode's skills directory
mkdir -p ~/.opencode/skills
git clone https://github.com/suifei/code2doc ~/.opencode/skills/code2docRegister in ~/.opencode/config.toml:
[[skills]]
path = "~/.opencode/skills/code2doc/SKILL.md"Or via the OpenCode UI: Settings → Skills → Add from path
Usage: Type /code2doc in the chat or directly describe your documentation needs.
Cursor loads rules from the .cursor/rules/ directory (.mdc format).
# In project root
mkdir -p .cursor/rules
# Convert SKILL.md to Cursor rules format
curl -fsSL https://raw.githubusercontent.com/suifei/code2doc/main/SKILL.md \
-o .cursor/rules/code2doc.mdcOr manually:
- Open Cursor →
Cursor Settings→Rules for AI - Paste the contents of
SKILL.mdinto theUser Rulesarea - Request a document type directly in the chat:
Generate HLD for this project
Global rules (all projects):
Cursor Settings → General → Rules for AI → Paste SKILL.md content
Cline and RooCode support custom System Prompts.
- Open VSCode → Click the Cline/RooCode icon in the sidebar
- Click the settings gear →
Custom Instructions - Paste the full contents of
SKILL.md - Click save
Usage:
# Enter directly in the Cline chat
Generate operations manual
# Or specify modules
Generate LLD for user and channel modules
Continue supports custom slash commands via config.json.
Edit ~/.continue/config.json:
{
"customCommands": [
{
"name": "code2doc",
"description": "Generate project documentation from code",
"prompt": "{{{ input }}}\n\n---\n{{{ read_file '.claude/skills/code2doc/SKILL.md' }}}"
}
]
}Install the skill file:
mkdir -p .claude/skills
git clone https://github.com/suifei/code2doc .claude/skills/code2docUsage:
/code2doc Generate PRD for this project
Windsurf loads instructions via .windsurfrules files or global rules.
Project-level:
# Create rules file in project root
curl -fsSL https://raw.githubusercontent.com/suifei/code2doc/main/SKILL.md \
-o .windsurfrulesGlobal:
Windsurf Settings→AI Rules- Paste the contents of
SKILL.md
Usage:
Generate HLD
Use the contents of SKILL.md as a System Prompt. Works with any tool that supports custom System Prompts:
- ChatGPT / OpenAI API: Paste into System Message
- API calls:
import anthropic
with open("SKILL.md", "r") as f:
skill_content = f.read()
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-opus-4-5",
max_tokens=8192,
system=skill_content,
messages=[
{"role": "user", "content": "Generate operations manual"}
]
)code2doc/
├── SKILL.md # Main skill file (4-round workflow + quality checks)
└── references/
├── document-types.md # Section structure templates for 12 document types
├── document-structure.md # Formatting specs for ops/admin manuals
├── analysis-dimensions.md # Seven analysis dimensions (ops documents)
├── exploration-strategy.md # Code exploration strategy (scripts + high-info locations)
└── reverse-sync.md # Reverse sync protocol (documentation drift calibration)
User specifies document type
│
▼
Round 1: Identify project type & entry points
(Read root dir → Identify tech stack → Existing docs → Initial module list)
│
▼
Round 2: Structural scan & information skeleton extraction
(Routes/menus → i18n strings → Data models → Permission rules → Business rules)
│
▼
Round 3: Per-module deep analysis
(Analysis dimensions vary by doc type: steps/state impact/business rules/dependencies...)
│
▼
Round 4: Document generation
(Template skeleton → Fill content → FACT/INFER annotations → Save)
│
▼
Post-completion: Documentation sync rule
(Search related docs → Choose one: Consistent/Update/Adjudicate)
Code changed but docs didn't keep up? Use reverse sync:
Code changed but docs are out of date
The skill automatically enters Practice-as-Truth Reverse Sync mode:
- Build artifact inventory (distinguish PRACTICE vs DESCRIPTION)
- Full code review, extract FACTS + OBSERVATIONS
- Diff comparison (Consistent / Drifted / Missing / Zombie)
- Write back revisions
- Generate
OBSERVATIONS.md(issue tracking)
| Check | Standard |
|---|---|
| Audience Fit | Language depth matches target readers (ops ≠ dev ≠ QA) |
| Annotation Completeness | Inferences have 〔INFER〕, code facts have 〔FACT|file:line〕; zero annotations = execution failure |
| Flowcharts | Multi-step operations / decision branches include Mermaid diagrams |
| Unambiguous Terminology | Technical terms are translated for the audience; BRD/MRD/PRD must not use raw terms like API/Token |
| Prerequisite Dependencies | Each chapter of ops documents has 🔗 dependency chains |
| Impact Matrix | Each chapter of ops documents has 📊 matrix with strategy names in column 4 |
| No "TBD" Promises | Uncertain items are resolved (pick one of three options); "follow up later" is prohibited |
MIT © suifei