"Explain complex code clearly for humans and agents. Produce a structured walkthrough (high-level intent -> data/control flow -> key invariants -> edge cases) with optional Mermaid diagrams and actionable next steps. Use for onboarding, debugging understanding, and “how it works” docs."
Resources
1Install
npx skillscat add dmonteroh/curated-agent-skills/code-explain Install via the SkillsCat registry.
SKILL.md
code-explain
Provides code explanations through clear narratives, diagrams, and step-by-step breakdowns.
This skill is intentionally different from doc-generate:
code-explain= explain one subsystem/module/flow extremely welldoc-generate= generate/maintain a documentation set (indexes, runbooks, onboarding, reverse-specs)
Use this skill when
- Explaining complex code, algorithms, or system behavior
- Creating onboarding walkthroughs or learning materials
- Producing step-by-step breakdowns with diagrams
- Teaching patterns or debugging reasoning
Do not use this skill when
- The request is to implement new features or refactors
- You only need API docs or user documentation
- There is no code or design to analyze
Instructions
Required inputs
- Code scope (file paths, modules, or snippet)
- Goal and audience (onboarding, debugging, review)
- Any constraints (length, diagram preference)
Workflow (with outputs)
- Confirm scope and artifacts
- If code references are missing, request them before proceeding.
- Output: a scoped list of files/components to explain.
- Build a high-level mental model
- Identify responsibilities, dependencies, and primary entry points.
- Output: a short outline of components and interactions.
- Trace control flow
- Walk through the critical execution path step-by-step.
- Output: ordered flow narrative with key branches.
- Trace data flow and invariants
- Track data transformations, state changes, and invariants.
- Output: data movement summary and invariants list.
- Surface pitfalls and edges
- Note failure modes, tricky conditions, and non-obvious behavior.
- Output: edge case list with impact notes.
- Identify safe change points
- Call out extension points, seams, and high-risk areas.
- Output: change guidance tied to components.
- Optional diagram decision
- If the flow is multi-step or non-linear, include a Mermaid diagram.
- Output: a diagram section or a brief note explaining omission.
Decision points
- If the scope is too broad, propose a narrower focus and wait for confirmation.
- If the user asks for changes or refactors, switch to guidance-only and ask for confirmation before implementation.
- If there is no runnable code, provide a design-level explanation and state assumptions.
Common pitfalls to avoid
- Mixing explanation with implementation changes.
- Skipping inputs/outputs or invariants.
- Overusing diagrams when a short narrative is clearer.
Templates (optional)
references/explainer-template.mdreferences/diagram-patterns.md
Output Format
Output contract (deterministic)
Produce a single explainer in this structure:
- What it is (1–3 sentences)
- Key inputs/outputs (APIs, types, DB tables, messages)
- Control flow (step-by-step)
- Data flow (what data moves where; include invariants)
- Edge cases and failure modes
- Where to change it safely (seams / extension points)
- Suggested tests (what would prove behavior)
- Next steps (if the user wants changes)
When useful, include a Mermaid diagram (sequence or flowchart).
Reporting format
- Scope:
<files/modules> - Assumptions:
<if any> - Explainer:
<sections 1-8> - Diagram:
<mermaid or omitted>
Examples
Example request
"Explain how the auth middleware and session refresh flow work in src/auth and src/session."
Example output (abbrev.)
- Scope:
src/auth,src/session - Assumptions: None
- Explainer:
- What it is: ...
- Key inputs/outputs: ...
- Control flow: ...
- Data flow: ...
- Edge cases and failure modes: ...
- Where to change it safely: ...
- Suggested tests: ...
- Next steps: ...
- Diagram: Omitted (linear flow)
Resources
references/README.mdfor detailed examples and templates.