skills/explain/SKILL.md
Deep explanation of complex code, files, or concepts. Dispatches skill-preloaded agents, uses structural search, generates mermaid diagrams. Triggers on: explain, deep dive, how does X work, architecture, data flow.
npx skillsauth add 0xDarkMatter/claude-mods explainInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Get a comprehensive explanation of code, files, directories, or architectural concepts. Automatically dispatches a general-purpose agent preloaded with the most relevant -ops skill 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 Explainer (general-purpose + skill preload)
| +- .ts/.tsx -> general-purpose, preload typescript-ops or react-ops
| +- .py -> general-purpose, preload python-* skill by topic
| +- .vue -> general-purpose, preload vue-ops
| +- .sql/migrations -> general-purpose, preload postgres-ops
| +- agents/skills/commands -> general-purpose, preload claude-code-ops
| +- Default -> general-purpose
| +- All explainers preload: debug-ops (systematic analysis)
|
+-> 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
# 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:
Dispatch is skills-first: the generic general-purpose subagent preloads the relevant -ops skill based on file extension and content:
| Pattern | Dispatch | Preload | Condition |
|---------|----------|---------|-----------|
| .ts | general-purpose | skills/typescript-ops/SKILL.md | No JSX/React imports |
| .tsx | general-purpose | skills/react-ops/SKILL.md | JSX present |
| .js, .jsx | general-purpose | skills/javascript-ops/SKILL.md | - |
| .py | general-purpose | relevant skills/python-*/SKILL.md by topic | - |
| .vue | general-purpose | skills/vue-ops/SKILL.md | - |
| .sql, migrations/* | general-purpose | skills/postgres-ops/SKILL.md | - |
| agents/*.md, skills/*, commands/* | general-purpose | skills/claude-code-ops/SKILL.md | Claude extensions |
| *.test.*, *.spec.* | general-purpose | (framework skill by file type) | - |
| Other | general-purpose | - | Fallback |
Invoke via Task tool:
Task tool with subagent_type: "general-purpose" (preload claude-code-ops for Claude extensions)
model: "sonnet"
Prompt includes:
- Skill preloading (domain knowledge):
"First, read these files for analysis context:
- Read: skills/debug-ops/SKILL.md
- Read: [Preload column for the matched pattern]"
- File content
- Related files found
- Project conventions
- Requested depth and focus
The dispatched 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 codebases-ops skills provide framework-specific insightstools
yt-dlp operations - the media ACQUISITION layer that feeds ffmpeg-ops: format selection (-S sort vs -f filters) that avoids post-download transcodes, --download-sections clip-at-download, audio-only extraction for STT pipelines (-x --audio-format opus), playlists + --download-archive incremental channel syncs, cookies/auth (--cookies-from-browser), rate limiting and politeness, SponsorBlock mark/remove, output templates (-o), subtitle download (--write-subs/--write-auto-subs), remux-vs-recode doctrine, and failure triage (403s, throttling, geo blocks, the nsig-extraction class that means yt-dlp is outdated). Triggers on: yt-dlp, ytdlp, youtube-dl, download video, download youtube, download from youtube, download playlist, download channel, archive channel, channel sync, rip audio, youtube to mp3, youtube to mp4, save video, grab video, video downloader, download subtitles, download transcript, clip from youtube, download section, sponsorblock, cookies-from-browser, download-archive, nsig, requested format is not available, sign in to confirm, download livestream, record stream, live-from-start, premiere, impersonate.
tools
Comprehensive ffmpeg/ffprobe operations - probe-first media processing: transcode and compress (H.264/H.265/AV1/Opus), frame-accurate cut/trim/concat, EDL-driven editing, color grading and .cube LUTs, audio loudnorm and mixing, STT/Whisper audio prep, subtitles, GIF and thumbnails, HLS packaging, hardware encoding (NVENC/QSV/AMF/VideoToolbox), restoration, scene and silence detection, VMAF quality gates, screen capture, yt-dlp interop. Triggers on: ffmpeg, ffprobe, transcode, convert video, compress video, encode video, extract audio, trim video, cut video, concat videos, video to gif, thumbnail, contact sheet, burn subtitles, watermark, resize video, crop video, change fps, slow motion, timelapse, loudnorm, normalize audio, audio for whisper, transcription prep, scene detection, silence detection, remove silence, color grade, LUT, tonemap HDR, vmaf, nvenc, hardware encode, hls, remux, faststart, deinterlace, stabilize video, denoise video, screen record, EDL, keyframes.
development
Payload CMS 3 (Next.js-native) architecture - collections, globals, fields, access control, hooks, Local API, storage adapters, and database (Postgres/MongoDB/SQLite). Use for: payload, payloadcms, payload cms, payload 3, collection config, access control, payload hooks, local api, payload fields, multi-tenant payload, payload nextjs, payload s3, payload r2, payloadcms architecture, headless cms typescript.
testing
Cypress end-to-end and component testing operations - selector/retry-ability strategy, cy.intercept network stubbing, cy.session auth, component vs e2e, flake diagnosis, CI, Test Replay. Use for: cypress, e2e test, component test, cy.get, cy.intercept, cy.session, data-cy, data-test, retry-ability, flake, flaky test, cypress.config, cy.mount, Test Replay, custom commands, fixtures.