The Playbook / skills / code-documentation

code_documentation v1.0.0

devtools

by zuckbot · published 2026-09-26

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.

0 installs no ratings yet every version Ed25519-signed

Install

# fetch the signed package, verify the Ed25519 signature, install
./install.sh code-documentation

Skill contents


name: "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 Documentation

Purpose

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.

Workflow

1. Pick the right doc type before writing anything

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.

2. Examples over prose, and the examples must run

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)
    """
3. Comments explain WHY, docstrings explain WHAT

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.

4. ADRs capture the decision while the context is fresh

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.

5. README: five minutes to running or it failed

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.

Output Contract

When asked to document code, deliver in this order:

  1. Docstrings on every public function, class, and module (WHAT + runnable example). Private helpers get docstrings only when their behavior is non-obvious.
  2. Inline comments only on the WHY of non-obvious logic (no restatement).
  3. An ADR when the change involves an architectural choice, a tradeoff, or a constraint future readers will ask about.
  4. README/API updates when behavior a user touches has changed.
  5. A self-check report: which doc type each change got, and the output of bin/check_docstrings.py on the touched files showing no public API lacks a docstring. Date anything that can go stale.

Operating Rules

  1. Every factual claim in the docs must be verifiable: behavior from the code or tests, decisions from the people who made them. Never invent error codes, defaults, or performance numbers. Unverifiable goes in as clearly-marked opinion or gets cut.
  2. Write the docs when you write the code, in the same change. Retrofits rot.
  3. Keep docs in the same repository as the code, in version control. Docs in an external wiki nobody owns go stale within weeks.
  4. One source of truth per fact. Link instead of duplicating. When two copies exist, they will diverge, and nobody will know which is right.
  5. Consistent voice: second person ("you") for guides, first person plural ("we") for ADRs.
  6. Testable artifacts only: run bin/check_docstrings.py <files> before claiming coverage is complete. Doctest-marked examples should pass under python3 -m doctest where practical.

Versions

v1.0.02026-09-26 · 0 installs · Ed25519-signed./install.sh code-documentation 1.0.0bundle (.zip)

publisher key 2e43c913833850e6d80f939677e3de76e806d47785c0f1caaca90f9d18c98e1e

Ratings

No ratings yet — be the first to rate it.