Documenting Code
Update only useful documentation. Start from code facts, identify the reader, and
make the smallest doc change that helps that reader act correctly.
Role-gated action
Detect capability from tools, not prose:
- Write-capable role: edit docs and run validation.
- Read-only role: apply nothing; emit proposed edits in the output contract.
Reader model
Choose the reader before writing.
Human reader:
- Make docs scannable: clear title, short overview, focused sections, examples.
- Keep docs short. Link to detail instead of creating long reads.
- Use Mermaid diagrams only when they answer a real structure, flow, lifecycle,
ownership, or trade-off question.
- Match the existing docs style. Do not invent fonts, colors, or custom visual
treatment unless the docs system already supports it.
Agent reader:
- Write terse operational instructions for LLMs.
- Prefer headers, bullets, numbered steps, and exact contracts.
- Remove generic knowledge, duplicate rules, pretty formatting, diagrams, tables,
long rationale, and advice the model already knows.
- If the task is to review or score agent instructions, use
reviewing-instructions.
Code reader:
- Comments and docstrings explain contracts, constraints, invariants, side
effects, error behavior, and non-obvious decisions.
- Delete comments that paraphrase code.
- Avoid comments in tests unless they explain non-obvious external behavior or
why an edge case matters.
Language references
Load only references matching changed implementation files:
- C# /.NET:
references/csharp.md
- Go:
references/go.md
- Java/Kotlin:
references/java-kotlin.md
- Python:
references/python.md
- Rust:
references/rust.md
- TypeScript:
references/typescript.md
- Web:
references/web.md
Mixed languages: load each matching reference. Unknown language: use this file
only.
Workflow
- Identify scope from the user request or changed files. Do not ask if scope is clear.
- Read relevant implementation, tests, and existing docs before writing.
- Decide reader type: human, agent, code reader, or mixed.
- Check docs against current behavior. Code wins unless the user says docs define the intended contract.
- Use
looking-up-docs only when external API syntax or behavior is uncertain.
- Use one bounded read-only subagent only for large doc audits; verify its claims before editing.
- Update the smallest useful docs. Do not create speculative docs.
- Verify with the narrowest docs or repo checks available.
What to update
- README usage, setup, or quick start when user-visible behavior changes.
- API docs when parameters, outputs, errors, side effects, or examples change.
- Architecture docs when boundaries, data flow, ownership, deployment units, or
major trade-offs change.
- Agent instructions when skills, agents, hooks, commands, tools, routing, or
operating rules change.
- Generated catalogs only through their source files and generator scripts.
- Code comments/docstrings only when they add useful contract or reasoning value.
Rules
- No promotional filler.
- No dead, future, or speculative behavior.
- No ADRs or
docs/adr/ changes unless explicitly requested.
- Keep private paths, secrets, tokens, and internal credentials out of docs.
- Prefer runnable examples. If an example cannot be run, state why.
- For human docs, favor a compact diagram over paragraphs only when the diagram
improves understanding.
- For agent docs, optimize for token efficiency over visual appeal.
Verification
Run the narrowest relevant checks, for example:
markdownlint-cli2 '**/*.md'
make lint-markdown
make validate
Also run documented commands or examples when practical. If a check is missing or
not practical, state the reason and run the closest available check.
Output
Write-capable role:
## Documentation Update
Updated:
- `path` — <what changed and reader served>
Verified:
- <check>: passed | skipped (<reason>)
Issues: none | <remaining issue>
Read-only role:
## Proposed Changes
### Change 1: <brief description>
File: `path/to/doc`
Action: CREATE | MODIFY | DELETE
Reader: human | agent | code
Code:
<doc content or patch-sized replacement with enough context>
Rationale: <code fact that makes this stale or missing>
Failure handling
- Ambiguous scope: ask one scoped question.
- Missing changed-file context: inspect
git diff --name-only; if unavailable,
ask for paths.
- No stale docs found: say so and report what was checked.
- Docs/code conflict: report the conflict; update docs to code unless user says docs are intended contract.
- Validation failure: report the exact failure and do not claim docs are current.
1---2name: documenting-code3description: Create or update human-facing docs, agent-facing instructions, architecture docs, API docs, README content, and useful code comments from implementation facts. Use when docs are stale, missing, or must reflect code changes. NOT for code-quality review, prompt scoring, speculative docs, or ADRs unless explicitly requested.4---56# Documenting Code78Update only useful documentation. Start from code facts, identify the reader, and9make the smallest doc change that helps that reader act correctly.1011## Role-gated action1213Detect capability from tools, not prose:1415- Write-capable role: edit docs and run validation.16- Read-only role: apply nothing; emit proposed edits in the output contract.1718## Reader model1920Choose the reader before writing.2122Human reader:2324- Make docs scannable: clear title, short overview, focused sections, examples.25- Keep docs short. Link to detail instead of creating long reads.26- Use Mermaid diagrams only when they answer a real structure, flow, lifecycle,27 ownership, or trade-off question.28- Match the existing docs style. Do not invent fonts, colors, or custom visual29 treatment unless the docs system already supports it.3031Agent reader:3233- Write terse operational instructions for LLMs.34- Prefer headers, bullets, numbered steps, and exact contracts.35- Remove generic knowledge, duplicate rules, pretty formatting, diagrams, tables,36 long rationale, and advice the model already knows.37- If the task is to review or score agent instructions, use `reviewing-instructions`.3839Code reader:4041- Comments and docstrings explain contracts, constraints, invariants, side42 effects, error behavior, and non-obvious decisions.43- Delete comments that paraphrase code.44- Avoid comments in tests unless they explain non-obvious external behavior or45 why an edge case matters.4647## Language references4849Load only references matching changed implementation files:5051- C# /.NET: `references/csharp.md`52- Go: `references/go.md`53- Java/Kotlin: `references/java-kotlin.md`54- Python: `references/python.md`55- Rust: `references/rust.md`56- TypeScript: `references/typescript.md`57- Web: `references/web.md`5859Mixed languages: load each matching reference. Unknown language: use this file60only.6162## Workflow63641. Identify scope from the user request or changed files. Do not ask if scope is clear.652. Read relevant implementation, tests, and existing docs before writing.663. Decide reader type: human, agent, code reader, or mixed.674. Check docs against current behavior. Code wins unless the user says docs define the intended contract.685. Use `looking-up-docs` only when external API syntax or behavior is uncertain.696. Use one bounded read-only subagent only for large doc audits; verify its claims before editing.707. Update the smallest useful docs. Do not create speculative docs.718. Verify with the narrowest docs or repo checks available.7273## What to update7475- README usage, setup, or quick start when user-visible behavior changes.76- API docs when parameters, outputs, errors, side effects, or examples change.77- Architecture docs when boundaries, data flow, ownership, deployment units, or78 major trade-offs change.79- Agent instructions when skills, agents, hooks, commands, tools, routing, or80 operating rules change.81- Generated catalogs only through their source files and generator scripts.82- Code comments/docstrings only when they add useful contract or reasoning value.8384## Rules8586- No promotional filler.87- No dead, future, or speculative behavior.88- No ADRs or `docs/adr/` changes unless explicitly requested.89- Keep private paths, secrets, tokens, and internal credentials out of docs.90- Prefer runnable examples. If an example cannot be run, state why.91- For human docs, favor a compact diagram over paragraphs only when the diagram92 improves understanding.93- For agent docs, optimize for token efficiency over visual appeal.9495## Verification9697Run the narrowest relevant checks, for example:9899```bash100markdownlint-cli2 '**/*.md'101make lint-markdown102make validate103```104105Also run documented commands or examples when practical. If a check is missing or106not practical, state the reason and run the closest available check.107108## Output109110Write-capable role:111112```markdown113## Documentation Update114115Updated:116117- `path` — <what changed and reader served>118119Verified:120121- <check>: passed | skipped (<reason>)122123Issues: none | <remaining issue>124```125126Read-only role:127128```markdown129## Proposed Changes130131### Change 1: <brief description>132133File: `path/to/doc`134Action: CREATE | MODIFY | DELETE135Reader: human | agent | code136137Code:138<doc content or patch-sized replacement with enough context>139140Rationale: <code fact that makes this stale or missing>141```142143## Failure handling144145- Ambiguous scope: ask one scoped question.146- Missing changed-file context: inspect `git diff --name-only`; if unavailable,147 ask for paths.148- No stale docs found: say so and report what was checked.149- Docs/code conflict: report the conflict; update docs to code unless user says docs are intended contract.150- Validation failure: report the exact failure and do not claim docs are current.