一键导入
explaining-code
Explains code with diagrams and analogies. Use when explaining how code works, teaching about a codebase, or when asked "how does this work?"
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Explains code with diagrams and analogies. Use when explaining how code works, teaching about a codebase, or when asked "how does this work?"
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | explaining-code |
| description | Explains code with diagrams and analogies. Use when explaining how code works, teaching about a codebase, or when asked "how does this work?" |
Explain code clearly using multiple techniques for different learning styles.
Before explaining, understand:
| If they ask... | Start with... |
|---|---|
| "How does X work?" | High-level flow, then details |
| "What does this code do?" | Purpose, then step-by-step |
| "Why is it written this way?" | Problem it solves, alternatives |
| "I'm confused about..." | Clarify specific concept |
Layer your explanation:
Different people learn differently:
Start wide, then zoom in:
System Level: "This app handles user authentication"
↓
Module Level: "This module manages sessions"
↓
Function Level: "This function validates tokens"
↓
Line Level: "This line checks expiration"
Connect to familiar concepts:
| Code Concept | Real-world Analogy |
|---|---|
| API | Restaurant menu + waiter |
| Cache | Sticky notes on your desk |
| Database | Filing cabinet |
| Queue | Line at a store |
| Stack | Stack of plates |
| Hash table | Library index cards |
| Middleware | Security checkpoint |
| Event loop | Receptionist handling calls |
| Promise | IOU note |
| Closure | Backpack carrying supplies |
Narrate the code as a story:
"When a user clicks login, our function wakes up.
First, it grabs the username and password from the form.
Then it sends them to the server and waits for a response.
If the server says 'OK', it saves the token and lets the user in.
If not, it shows an error message."
Use ASCII diagrams for structure and flow:
┌─────────┐ ┌─────────┐ ┌─────────┐
│ Browser │────▶│ API │────▶│ DB │
└─────────┘ └─────────┘ └─────────┘
│ │ │
│ 1. Request │ 2. Query │
│ │ │
│ 4. Response │ 3. Data │
│◀──────────────│◀──────────────│
Purpose: [What problem does it solve?]
Inputs: [What does it receive?]
Process: [What steps does it take?]
Output: [What does it return?]
Side effects: [What else does it change?]
Example:
function calculateDiscount(price, percentage) {
return price * (1 - percentage / 100);
}
Purpose: Calculate price after applying a percentage discount
Inputs:
- price: The original price (e.g., 100)
- percentage: The discount percentage (e.g., 20 for 20%)
Process:
1. Divide percentage by 100 to get decimal (20 → 0.20)
2. Subtract from 1 to get remaining fraction (1 - 0.20 = 0.80)
3. Multiply by price to get discounted price (100 × 0.80 = 80)
Output: The discounted price (80)
Side effects: None
Responsibility: [What is this class in charge of?]
Data it holds: [What state does it maintain?]
Actions it can: [What can you ask it to do?]
Collaborators: [What other classes does it work with?]
Purpose: [What business problem does this solve?]
Components: [What are the major parts?]
Data flow: [How does information move through?]
Entry points: [How do users/systems interact with it?]
// "Do this task, and when you're done, call me back"
fetchData(url, function(result) {
// This runs LATER, when data arrives
});
// Code here runs IMMEDIATELY, before data arrives
Analogy: Like ordering food and giving your number - you don't stand at the counter waiting.
// "I promise to give you a result eventually"
fetchData(url)
.then(result => { /* handle success */ })
.catch(error => { /* handle failure */ });
Analogy: Like a claim ticket at dry cleaning - you'll get your clothes, but not right now.
// "Tell me whenever something happens"
button.addEventListener('click', handleClick);
Analogy: Like subscribing to a newsletter - you get notified when new content arrives.
// "Check this before passing it on"
app.use(authMiddleware); // Runs first
app.use(loggingMiddleware); // Runs second
app.get('/api', handler); // Runs last
Analogy: Like airport security - multiple checkpoints before you board.
Complete the current milestone and prepare next work by following the canonical complete command doc.
Execute the current plan (from STATE.md -> PLAN.md) by following the canonical execute command doc. Make code changes + run necessary checks.
Initialize project with CLAUDE.md, STATE.md, and ROADMAP.md by following the canonical init command doc.
Create executable plan for the current phase (3-5 tasks). Reads the canonical plan command doc and produces/updates the current PLAN.md referenced from STATE.md. No implementation.
Review code changes and capture learnings for CLAUDE.md by following the canonical review command doc.
Check project progress and suggest the next action by following the canonical status command doc.