npx skills add https://github.com/0xdarkmatter/claude-mods --skill explain获取代码、文件、目录或架构概念的全面解释。自动路由到最相关的专家代理,并使用现代 CLI 工具进行分析。
$ARGUMENTS
<target> - 文件路径、函数名、类名、目录或概念--depth <shallow|normal|deep|trace> - 详细程度(默认:normal)--focus <arch|flow|deps|api|perf> - 特定的关注领域/explain <target> [--depth] [--focus]
|
+-> Step 1: Detect & Classify Target
| +- File exists? -> Read it
| +- Function/class? -> ast-grep to find definition
| +- Directory? -> tokei for overview
| +- Concept? -> rg search codebase
|
+-> Step 2: Gather Context (parallel)
| +- structural-search skill -> find usages
| +- code-stats skill -> assess scope
| +- Find related: tests, types, docs
| +- Load: AGENTS.md, CLAUDE.md conventions
|
+-> Step 3: Route to Expert Agent
| +- .ts/.tsx -> typescript-expert or react-expert
| +- .py -> python-expert
| +- .vue -> vue-expert
| +- .sql/migrations -> postgres-expert
| +- agents/skills/commands -> claude-architect
| +- Default -> general-purpose
|
+-> Step 4: Generate Explanation
| +- Structured markdown with sections
| +- Mermaid diagrams (flowchart/sequence/class)
| +- Related code paths as file:line refs
| +- Design decisions and rationale
|
+-> Step 5: Integrate
+- Offer to save to ARCHITECTURE.md (if significant)
+- Link to /save if working on related task
Get a comprehensive explanation of code, files, directories, or architectural concepts. Automatically routes to the most relevant expert agent and uses modern CLI tools for analysis.
$ARGUMENTS
<target> - File path, function name, class name, directory, or concept--depth <shallow|normal|deep|trace> - Level of detail (default: normal)--focus <arch|flow|deps|api|perf> - Specific focus area/explain <target> [--depth] [--focus]
|
+-> Step 1: Detect & Classify Target
| +- File exists? -> Read it
| +- Function/class? -> ast-grep to find definition
| +- Directory? -> tokei for overview
| +- Concept? -> rg search codebase
|
+-> Step 2: Gather Context (parallel)
| +- structural-search skill -> find usages
| +- code-stats skill -> assess scope
| +- Find related: tests, types, docs
| +- Load: AGENTS.md, CLAUDE.md conventions
|
+-> Step 3: Route to Expert Agent
| +- .ts/.tsx -> typescript-expert or react-expert
| +- .py -> python-expert
| +- .vue -> vue-expert
| +- .sql/migrations -> postgres-expert
| +- agents/skills/commands -> claude-architect
| +- Default -> general-purpose
|
+-> Step 4: Generate Explanation
| +- Structured markdown with sections
| +- Mermaid diagrams (flowchart/sequence/class)
| +- Related code paths as file:line refs
| +- Design decisions and rationale
|
+-> Step 5: Integrate
+- Offer to save to ARCHITECTURE.md (if significant)
+- Link to /save if working on related task
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# Check if target is a file
test -f "$TARGET" && echo "FILE" && exit
# Check if target is a directory
test -d "$TARGET" && echo "DIRECTORY" && exit
# Otherwise, search for it as a symbol
对于文件: 使用 bat(语法高亮)或 Read 工具直接读取。
对于目录: 使用 tokei 获取概览(如果可用):
command -v tokei >/dev/null 2>&1 && tokei "$TARGET" --compact || echo "tokei unavailable"
对于符号(函数/类): 使用 ast-grep 查找定义:
# 首先尝试 ast-grep(结构化搜索)
command -v ast-grep >/dev/null 2>&1 && ast-grep -p "function $TARGET" -p "class $TARGET" -p "def $TARGET"
# 回退到 ripgrep
rg "(?:function|class|def|const|let|var)\s+$TARGET" --type-add 'code:*.{ts,tsx,js,jsx,py,vue}' -t code
尽可能并行运行以下操作:
查找使用情况(structural-search 技能):
# 使用 ast-grep
ast-grep -p "$TARGET($_)" --json 2>/dev/null | head -20
# 回退方案
rg "$TARGET" --type-add 'code:*.{ts,tsx,js,jsx,py,vue}' -t code -l
查找相关文件:
# 测试文件
fd -e test.ts -e spec.ts -e test.py -e spec.py | xargs rg -l "$TARGET" 2>/dev/null
# 类型/接口文件
fd -e d.ts -e types.ts | xargs rg -l "$TARGET" 2>/dev/null
加载项目约定:
根据文件扩展名和内容确定最佳专家:
| 模式 | 主要代理 | 条件 |
|---|---|---|
.ts | typescript-expert | 没有 JSX/React 导入 |
.tsx | react-expert | 存在 JSX |
.js, .jsx | javascript-expert | - |
.py | python-expert | - |
.vue | vue-expert | - |
.sql, migrations/* | postgres-expert | - |
agents/*.md, skills/*, commands/* | claude-architect | Claude 扩展 |
*.test.*, *.spec.* | (框架专家) | 按文件类型路由 |
| 其他 | general-purpose | 回退 |
通过 Task 工具调用:
Task tool with subagent_type: "[detected]-expert"
Prompt includes:
- File content
- Related files found
- Project conventions
- Requested depth and focus
专家代理生成结构化的解释:
# Explanation: [target]
## Overview
[1-2 sentence summary of purpose and role in the system]
## Architecture
[Mermaid diagram - choose appropriate type]
### Flowchart (for control flow)
` ` `mermaid
flowchart TD
A[Input] --> B{Validate}
B -->|Valid| C[Process]
B -->|Invalid| D[Error]
C --> E[Output]
` ` `
### Sequence (for interactions)
` ` `mermaid
sequenceDiagram
participant Client
participant Server
participant Database
Client->>Server: Request
Server->>Database: Query
Database-->>Server: Result
Server-->>Client: Response
` ` `
### Class (for structures)
` ` `mermaid
classDiagram
class Component {
+props: Props
+state: State
+render(): JSX
}
` ` `
## How It Works
### Step 1: [Phase Name]
[Explanation with code references]
See: `src/module.ts:42`
### Step 2: [Phase Name]
[Explanation]
## Key Concepts
### [Concept 1]
[Explanation]
### [Concept 2]
[Explanation]
## Dependencies
| Import | Purpose |
|--------|---------|
| `package` | [why it's used] |
## Design Decisions
### Why [decision]?
[Rationale and tradeoffs considered]
## Related Code
| File | Relationship |
|------|--------------|
| `path/to/file.ts:123` | [how it relates] |
## See Also
- `/explain path/to/related` - [description]
- [External docs link] - [description]
| 模式 | 输出 |
|---|---|
--shallow | 概述段落、关键导出、无图表 |
--normal | 完整解释,包含 1 个图表、主要概念(默认) |
--deep | 详尽:所有内部细节、边界情况、历史记录、多个图表 |
--trace | 数据流在整个系统中的追踪、序列图 |
/explain src/auth/token.ts --shallow
输出:单个段落 + 导出列表。
/explain src/core/engine.ts --deep
输出:完整的内部细节、算法分析、性能说明、边界情况。
/explain handleLogin --trace
输出:追踪数据流从入口到数据库再到响应的过程。
| 模式 | 分析内容 |
|---|---|
--focus arch | 模块边界、层分离、依赖关系 |
--focus flow | 数据流、控制流、状态变化 |
--focus deps | 导入、外部依赖、集成 |
--focus api | 公共接口、输入/输出、契约 |
--focus perf | 复杂度、瓶颈、优化机会 |
命令使用现代 CLI 工具,并提供优雅的回退方案:
| 工具 | 用途 | 回退方案 |
|---|---|---|
tokei | 代码统计 | 跳过统计 |
ast-grep | 结构化搜索 | 使用模式的 rg |
bat | 语法高亮 | Read 工具 |
rg | 内容搜索 | Grep 工具 |
fd | 文件查找 | Glob 工具 |
检查可用性:
command -v tokei >/dev/null 2>&1 || echo "tokei not installed - skipping stats"
# 解释一个文件
/explain src/auth/oauth.ts
# 解释一个函数(自动查找)
/explain validateToken
# 解释一个目录
/explain src/services/
# 深度探索,聚焦架构
/explain src/core/engine.ts --deep --focus arch
# 追踪数据流
/explain handleUserLogin --trace
# 快速概览
/explain src/utils/helpers.ts --shallow
# 聚焦依赖关系
/explain package.json --focus deps
| 技能/命令 | 关系 |
|---|---|
/review | 理解后进行审查 |
/testgen | 为已解释的代码生成测试 |
/save | 如果正在处理相关任务,保存进度 |
在生成重要的解释后,可能会提供以下选项:
Would you like to save this explanation?
1. Append to ARCHITECTURE.md
2. Append to AGENTS.md (if conventions-related)
3. Don't save (output only)
这可以将有价值的架构知识保存在 git 跟踪的文档中。
/explain--deep每周安装次数
19
仓库
GitHub 星标数
8
首次出现
2026年1月25日
安全审计
安装于
opencode16
gemini-cli16
claude-code16
codex15
antigravity14
cursor14
# Check if target is a file
test -f "$TARGET" && echo "FILE" && exit
# Check if target is a directory
test -d "$TARGET" && echo "DIRECTORY" && exit
# Otherwise, search for it as a symbol
For files: Read directly with bat (syntax highlighted) or Read tool.
For directories: Get overview with tokei (if available):
command -v tokei >/dev/null 2>&1 && tokei "$TARGET" --compact || echo "tokei unavailable"
For symbols (function/class): Find definition with ast-grep:
# Try ast-grep first (structural)
command -v ast-grep >/dev/null 2>&1 && ast-grep -p "function $TARGET" -p "class $TARGET" -p "def $TARGET"
# Fallback to ripgrep
rg "(?:function|class|def|const|let|var)\s+$TARGET" --type-add 'code:*.{ts,tsx,js,jsx,py,vue}' -t code
Run these in parallel where possible:
Find usages (structural-search skill):
# With ast-grep
ast-grep -p "$TARGET($_)" --json 2>/dev/null | head -20
# Fallback
rg "$TARGET" --type-add 'code:*.{ts,tsx,js,jsx,py,vue}' -t code -l
Find related files:
# Tests
fd -e test.ts -e spec.ts -e test.py -e spec.py | xargs rg -l "$TARGET" 2>/dev/null
# Types/interfaces
fd -e d.ts -e types.ts | xargs rg -l "$TARGET" 2>/dev/null
Load project conventions:
Determine the best expert based on file extension and content:
| Pattern | Primary Agent | Condition |
|---|---|---|
.ts | typescript-expert | No JSX/React imports |
.tsx | react-expert | JSX present |
.js, .jsx | javascript-expert | - |
.py | python-expert | - |
.vue | vue-expert | - |
.sql, migrations/* | postgres-expert | - |
agents/*.md, skills/*, commands/* | claude-architect | Claude extensions |
*.test.*, *.spec.* | (framework expert) | Route by file type |
| Other | general-purpose | Fallback |
Invoke via Task tool:
Task tool with subagent_type: "[detected]-expert"
Prompt includes:
- File content
- Related files found
- Project conventions
- Requested depth and focus
The expert agent produces a structured explanation:
# Explanation: [target]
## Overview
[1-2 sentence summary of purpose and role in the system]
## Architecture
[Mermaid diagram - choose appropriate type]
### Flowchart (for control flow)
` ` `mermaid
flowchart TD
A[Input] --> B{Validate}
B -->|Valid| C[Process]
B -->|Invalid| D[Error]
C --> E[Output]
` ` `
### Sequence (for interactions)
` ` `mermaid
sequenceDiagram
participant Client
participant Server
participant Database
Client->>Server: Request
Server->>Database: Query
Database-->>Server: Result
Server-->>Client: Response
` ` `
### Class (for structures)
` ` `mermaid
classDiagram
class Component {
+props: Props
+state: State
+render(): JSX
}
` ` `
## How It Works
### Step 1: [Phase Name]
[Explanation with code references]
See: `src/module.ts:42`
### Step 2: [Phase Name]
[Explanation]
## Key Concepts
### [Concept 1]
[Explanation]
### [Concept 2]
[Explanation]
## Dependencies
| Import | Purpose |
|--------|---------|
| `package` | [why it's used] |
## Design Decisions
### Why [decision]?
[Rationale and tradeoffs considered]
## Related Code
| File | Relationship |
|------|--------------|
| `path/to/file.ts:123` | [how it relates] |
## See Also
- `/explain path/to/related` - [description]
- [External docs link] - [description]
| Mode | Output |
|---|---|
--shallow | Overview paragraph, key exports, no diagram |
--normal | Full explanation with 1 diagram, main concepts (default) |
--deep | Exhaustive: all internals, edge cases, history, multiple diagrams |
--trace | Data flow tracing through entire system, sequence diagrams |
/explain src/auth/token.ts --shallow
Output: Single paragraph + exports list.
/explain src/core/engine.ts --deep
Output: Full internals, algorithm analysis, performance notes, edge cases.
/explain handleLogin --trace
Output: Traces data flow from entry to database to response.
| Mode | What It Analyzes |
|---|---|
--focus arch | Module boundaries, layer separation, dependencies |
--focus flow | Data flow, control flow, state changes |
--focus deps | Imports, external dependencies, integrations |
--focus api | Public interface, inputs/outputs, contracts |
--focus perf | Complexity, bottlenecks, optimization opportunities |
Commands use modern CLI tools with graceful fallbacks:
| Tool | Purpose | Fallback |
|---|---|---|
tokei | Code statistics | Skip stats |
ast-grep | Structural search | rg with patterns |
bat | Syntax highlighting | Read tool |
rg | Content search | Grep tool |
fd | File finding | Glob tool |
Check availability:
command -v tokei >/dev/null 2>&1 || echo "tokei not installed - skipping stats"
# Explain a file
/explain src/auth/oauth.ts
# Explain a function (finds it automatically)
/explain validateToken
# Explain a directory
/explain src/services/
# Deep dive with architecture focus
/explain src/core/engine.ts --deep --focus arch
# Trace data flow
/explain handleUserLogin --trace
# Quick overview
/explain src/utils/helpers.ts --shallow
# Focus on dependencies
/explain package.json --focus deps
| Skill/Command | Relationship |
|---|---|
/review | Review after understanding |
/testgen | Generate tests for explained code |
/save | Save progress if working on related task |
After significant explanations, you may be offered:
Would you like to save this explanation?
1. Append to ARCHITECTURE.md
2. Append to AGENTS.md (if conventions-related)
3. Don't save (output only)
This keeps valuable architectural knowledge in git-tracked documentation.
/explain calls--deep for unfamiliar codebasesWeekly Installs
19
Repository
GitHub Stars
8
First Seen
Jan 25, 2026
Security Audits
Installed on
opencode16
gemini-cli16
claude-code16
codex15
antigravity14
cursor14
AI新闻播客制作技能:实时新闻转对话式播客脚本与音频生成
1,200 周安装