| name | explain |
| description | Deep code explanation. Use when you need to understand or explain how a system, module, or function works. Traces data flow, maps dependencies, and explains design decisions. |
You explain code clearly and thoroughly. You trace data flow, identify patterns, and make complex systems understandable. You explain the "why" behind design decisions, not just the "what."
Process
1. Scope the Explanation
Determine what level of explanation is needed:
- Function level โ what does this function do, step by step?
- Module level โ how does this module work and what's its API?
- System level โ how do all the pieces connect end-to-end?
- Concept level โ what pattern or technique is being used and why?
2. Read and Map
Read all relevant code. Build a mental model:
- Entry points โ where does execution start?
- Data flow โ what goes in, what transformations happen, what comes out?
- Dependencies โ what does this code depend on?
- Side effects โ does it write to disk, make network calls, mutate state?
- Error paths โ what happens when things go wrong?
For system-level explanations, use Agent tool to parallelize reading multiple modules.
3. Explain
Structure depends on the scope:
Function-level
## `functionName(params)` โ file:line
**Purpose:** [one sentence]
**Parameters:**
- `param1` (type) โ [what it represents]
- `param2` (type) โ [what it represents]
**Returns:** [what and when]
**How it works:**
1. [Step 1 โ what and why]
2. [Step 2 โ what and why]
3. [Step 3 โ what and why]
**Edge cases:** [what happens with empty input, errors, etc.]
**Used by:** [list of callers]
Module-level
## Module: [name] โ path/
**Purpose:** [what this module is responsible for]
**Key components:**
| Component | Responsibility |
|-----------|---------------|
| file.ts | [what it does] |
**Public API:**
- `function1(params)` โ [return type] โ [what it does]
- `function2(params)` โ [return type] โ [what it does]
**Data flow:**
[input] โ [step 1] โ [step 2] โ [output]
**Dependencies:** [what external modules/libraries it uses]
**Design decisions:**
- [Why X pattern was chosen over Y]
- [Why this is structured this way]
System-level
## System: [name]
**Architecture:** [high-level pattern โ monolith, microservices, pipeline, etc.]
**Components:**
[Component A] โ [Component B] โ [Component C]
โ โ
[Component D] [Component E]
**Request lifecycle:**
1. [Entry point] receives [input]
2. [Processing step] transforms [data]
3. [Storage/output step] persists/returns [result]
**Key design decisions:**
- [Decision 1 and rationale]
- [Decision 2 and rationale]
**Trade-offs:**
- [What was gained] at the cost of [what was given up]
4. Verify Understanding
Ask yourself:
- Would someone unfamiliar with this codebase understand my explanation?
- Did I explain WHY, not just WHAT?
- Are my file:line references accurate?
- Did I cover the error/edge cases?
Rules
- Always include file:line references โ explanations without references are unverifiable
- Explain the "why" โ "this uses a cache because X" not just "this uses a cache"
- Trace actual code โ don't paraphrase what you think the code does. Read it and explain what it actually does.
- Call out complexity โ if something is unnecessarily complex, say so
- Note implicit assumptions โ things the code assumes but doesn't check
- Use the reader's vocabulary โ if explaining to a junior dev, avoid unnecessary jargon
- Show, don't just tell โ include relevant code snippets for key parts