Get a comprehensive explanation of complex code, files, or architectural concepts.
$ARGUMENTS
--depth <shallow|normal|deep>: Level of detail--focus <arch|flow|deps|api>: Specific focus areaIdentify Target
Analyze Code
Generate Explanation
# If file path
cat <file>
# If function name, search for it
grep -rn "function <name>\|def <name>\|class <name>" .
# If directory
ls -la <dir>
tree <dir> -L 2
For the target, collect:
For Functions:
For Classes:
For Files/Modules:
For Directories:
# Explanation: <target>
## Overview
<1-2 sentence summary of what this does and why>
## Architecture
<ASCII diagram if helpful>
┌─────────────┐ ┌─────────────┐ │ Input │───▶│ Processor │ └─────────────┘ └──────┬──────┘
│
▼
┌─────────────┐
│ Output │
└─────────────┘
## How It Works
### Step 1: <phase name>
<explanation>
### Step 2: <phase name>
<explanation>
## Key Concepts
### <Concept 1>
<explanation>
### <Concept 2>
<explanation>
## Dependencies
- `<dep1>` - <purpose>
- `<dep2>` - <purpose>
## Usage Examples
```<language>
// Example usage
<file1> -
<file2> -
# Explain a file
/explain src/auth/oauth.ts
# Explain a function
/explain validateToken
# Explain a class
/explain UserService
# Explain a directory
/explain src/services/
# Explain with deep detail
/explain src/core/engine.ts --depth deep
# Focus on data flow
/explain src/api/routes.ts --focus flow
# Architecture overview
/explain src/services/ --focus arch
| Level | Output |
|---|---|
shallow |
Quick overview, main purpose, key exports |
normal |
Full explanation with examples (default) |
deep |
Exhaustive breakdown, edge cases, internals |
| Focus | Explains |
|---|---|
arch |
Architecture, structure, patterns |
flow |
Data flow, control flow, sequence |
deps |
Dependencies, imports, integrations |
api |
Public API, inputs, outputs, contracts |
For complex systems, include ASCII diagrams:
User Service Database
│ │ │
│──request───▶│ │
│ │───query─────▶│
│ │◀──result─────│
│◀─response───│ │
[Input] → [Validate] → [Transform] → [Store] → [Output]
│
└──[Error]──▶ [Log]
┌────────────────────────────────────┐
│ Application │
├──────────┬──────────┬─────────────┤
│ Routes │ Services │ Models │
├──────────┴──────────┴─────────────┤
│ Database │
└────────────────────────────────────┘
| Flag | Effect |
|---|---|
--depth <level> |
Set detail level (shallow/normal/deep) |
--focus <area> |
Focus on specific aspect |
--no-examples |
Skip usage examples |
--no-diagrams |
Skip ASCII diagrams |
--json |
Output as structured JSON |
Works well with:
/review - Review after understanding/test - Generate tests for explained code/checkpoint - Save progress after learning--depth deep for unfamiliar codebases