Code Documentation Skill
Create clear, concise, and informative, accurate, idiomatic, and useful documentation — not boilerplate. Every piece of documentation you write should help the next developer understand why, not just what.
Step 1: Detect Context and Scope
Before writing anything, scan the existing code and any existing docs to detect:
- Style already in use — check for: Google style, NumPy/Sphinx style, reStructuredText, or no style
- Existing doc coverage — are some things documented? Mimic that style exactly.
- Project type — library/package, application, CLI tool, API server, etc.
- Audience — internal tool vs public-facing API (affects verbosity)
If no style exists, default to Google style docstrings.
Always announce your detected style to the user before writing, e.g.:
"I can see you're using Google-style docstrings — I'll match that throughout."
Step 2: Determine Scope
Ask or infer which documentation type(s) are needed. See the full guidance in:
references/inline-docs.md — docstrings and inline comments
references/readme-and-api.md — README files and API reference docs
references/architecture.md — high-level architecture and design docs
For multi-type requests (e.g. "document this whole project"), tackle in this order:
- Inline docs first (they inform everything else)
- API reference
- README
- Architecture doc
Step 3: Write Documentation
Universal rules (apply to all doc types)
- Document intent, not mechanics. If the code says
i += 1, don't write # increment i.
- Keep it current. If you see a comment that contradicts the code, fix the comment.
- Don't over-document. Private helpers and obvious one-liners rarely need docs.
Focus effort on: public APIs, complex logic, non-obvious side effects, error conditions.
- Be consistent. Use the same style, tense, and voice throughout a file.
- Examples > prose for complex APIs. A 3-line usage example beats a paragraph of explanation.
What to always include in function/method docs
| Element |
Python (Google) |
| One-line summary |
First line of docstring |
| Parameters |
Args: block |
| Return value |
Returns: block |
| Exceptions/errors |
Raises: block |
| Usage example |
Example: block |
Only include sections that apply — don't add empty Raises: if nothing is raised.
Step 4: Output Format
- Inline docs: Output the full modified file (or clearly-delimited diff if file is large).
Never output just the docstring in isolation — always show it in context.
- README: Output as Markdown. See
references/readme-and-api.md for structure.
- API reference: Output as Markdown table or structured Markdown. See
references/readme-and-api.md.
- Architecture doc: Output as Markdown with diagrams (Mermaid) where helpful. See
references/architecture.md.
Step 5: Offer Follow-ups
After completing documentation, offer at least one relevant next step, e.g.:
- "Want me to generate an API reference from these docstrings?"
- "Should I write a README for this module next?"
- "Want me to add usage examples to the more complex functions?"
1---2name: code-documentation3description: Generates and improves code documentation for Python projects. Use this skill whenever the user asks to document code, add docstrings, add type hints, or improve existing comments. Trigger even for partial requests like "document this function", "add comments to my file", "write a README for this project", or "explain what this module does". Also trigger when the user shares code and asks "what does this do?" in a way that implies they want documented output rather than a one-line explanation.4---56# Code Documentation Skill78Create clear, concise, and informative, accurate, idiomatic, and useful documentation — not boilerplate. Every piece of documentation you write should help the next developer understand *why*, not just *what*.910---1112## Step 1: Detect Context and Scope1314Before writing anything, scan the existing code and any existing docs to detect:15161. **Style already in use** — check for: Google style, NumPy/Sphinx style, reStructuredText, or no style172. **Existing doc coverage** — are some things documented? Mimic that style exactly.183. **Project type** — library/package, application, CLI tool, API server, etc.194. **Audience** — internal tool vs public-facing API (affects verbosity)2021If no style exists, default to **Google style docstrings**.2223**Always announce your detected style** to the user before writing, e.g.:24> "I can see you're using Google-style docstrings — I'll match that throughout."2526---2728## Step 2: Determine Scope2930Ask or infer which documentation type(s) are needed. See the full guidance in:31- `references/inline-docs.md` — docstrings and inline comments32- `references/readme-and-api.md` — README files and API reference docs33- `references/architecture.md` — high-level architecture and design docs3435For multi-type requests (e.g. "document this whole project"), tackle in this order:361. Inline docs first (they inform everything else)372. API reference383. README394. Architecture doc4041---4243## Step 3: Write Documentation4445### Universal rules (apply to all doc types)4647- **Document intent, not mechanics.** If the code says `i += 1`, don't write `# increment i`.48- **Keep it current.** If you see a comment that contradicts the code, fix the comment.49- **Don't over-document.** Private helpers and obvious one-liners rarely need docs.50 Focus effort on: public APIs, complex logic, non-obvious side effects, error conditions.51- **Be consistent.** Use the same style, tense, and voice throughout a file.52- **Examples > prose** for complex APIs. A 3-line usage example beats a paragraph of explanation.5354### What to always include in function/method docs5556| Element | Python (Google) |57|---|---|58| One-line summary | First line of docstring |59| Parameters | `Args:` block |60| Return value | `Returns:` block |61| Exceptions/errors | `Raises:` block |62| Usage example | `Example:` block |6364Only include sections that apply — don't add empty `Raises:` if nothing is raised.6566---6768## Step 4: Output Format6970- **Inline docs**: Output the full modified file (or clearly-delimited diff if file is large).71 Never output just the docstring in isolation — always show it in context.72- **README**: Output as Markdown. See `references/readme-and-api.md` for structure.73- **API reference**: Output as Markdown table or structured Markdown. See `references/readme-and-api.md`.74- **Architecture doc**: Output as Markdown with diagrams (Mermaid) where helpful. See `references/architecture.md`.7576## Step 5: Offer Follow-ups7778After completing documentation, offer at least one relevant next step, e.g.:79- "Want me to generate an API reference from these docstrings?"80- "Should I write a README for this module next?"81- "Want me to add usage examples to the more complex functions?"