Write code documentation developers actually read: pick the right doc type (docstring, comment, ADR, README), document WHY over WHAT, and lead with working examples. Triggers when writing or reviewing docstrings, inline comments, READMEs, ADRs, or API docs for a codebase.
./install.sh code-documentationname: "code_documentation" description: "Write code documentation developers actually read: pick the right doc type (docstring, comment, ADR, README), document WHY over WHAT, and lead with working examples. Triggers when writing or reviewing docstrings, inline comments, READMEs, ADRs, or API docs for a codebase."
Code tells a reader what the software does right now. Documentation tells them why it does it that way, how to use it, and which decisions shaped it. This skill turns an agent that "adds comments" into one that writes docs a developer will open, trust, and keep.
Choosing wrong is the most common docs failure. Use scope and question:
Rule of thumb: stable, broad-impact knowledge (API contracts, architecture) goes in versioned docs next to the code. Code-coupled details (side effects, hacks) stay in comments. One ADR covers one decision, never a bundle.
Developers skim prose and read examples. Every docstring on a public function, every README usage section, every API reference gets a runnable example.
Python docstring example (Google style, doctest-ready):
python
def retry(fetch, max_attempts=3, delay=0.5):
"""Call `fetch` until it succeeds, with delays between attempts.
Args:
fetch: Zero-argument callable that performs the request.
max_attempts: How many total tries before giving up.
delay: Seconds to wait between attempts.
Returns:
Whatever `fetch` returns on success.
Raises:
The last exception from `fetch` if every attempt fails.
Example:
>>> import functools, requests
>>> fetch = functools.partial(requests.get, "https://api.example.com/data")
>>> response = retry(fetch, max_attempts=5, delay=0.5)
"""
Good comment: "Retry window must stay under 30s because the payment provider times out at 31s (see ADR-0017)." That knowledge is not in the code anywhere.
Bad comment: i = i + 1 # increment i by 1. It restates the code and adds nothing. If a block needs a paragraph of prose to make sense, extract it into a well-named function first.
Format for deferred work: // TODO(username): description - issue#123. A TODO without an owner and an issue is litter.
Write the ADR the same day the decision is made. Retrofitting ADRs is slower and less accurate, same as any docs.
Structure (Michael Nygard's format, see references/adr-template.md):
Keep it short enough that a person and an agent can read the whole record before changing the code it describes. An ADR index at the top of the docs folder (number, title, status) makes retrieval cheap.
A README that does not get someone running in five minutes is a design review waiting to happen.
API docs follow the same discipline: endpoint, method, auth at a glance; realistic request/response examples; error codes with causes and resolution steps; rate limits and pagination stated up front.
When asked to document code, deliver in this order:
bin/check_docstrings.py on the touched files showing no public API lacks a docstring. Date anything that can go stale.bin/check_docstrings.py <files> before claiming coverage is complete. Doctest-marked examples should pass under python3 -m doctest where practical.publisher key 2e43c913833850e6d80f939677e3de76e806d47785c0f1caaca90f9d18c98e1e
No ratings yet — be the first to rate it.