-
Notifications
You must be signed in to change notification settings - Fork 59
Explain Tool
geoffrey fernald edited this page Jan 28, 2026
·
1 revision
Get comprehensive explanations of code in context of your codebase. Combines pattern analysis, call graph, security implications, and dependencies into a coherent narrative.
When you need to understand unfamiliar code, drift_explain provides a complete picture:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CODE EXPLANATION β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Target: src/auth/middleware.ts β
β β
β π SUMMARY β
β Authentication middleware that validates JWT tokens and β
β attaches user context to requests. Used by 23 routes. β
β β
β π― PURPOSE β
β - Validates incoming JWT tokens β
β - Extracts user ID and roles from token β
β - Attaches user object to request context β
β - Blocks unauthorized requests β
β β
β π PATTERNS USED β
β - Auth Middleware Pattern (92% confidence) β
β - Error Handling Pattern (88% confidence) β
β - Logging Pattern (85% confidence) β
β β
β π DEPENDENCIES β
β - Calls: tokenService.verify(), userService.findById() β
β - Called by: 23 route handlers β
β - Entry points: All /api/* routes β
β β
β β οΈ SECURITY β
β - Accesses: users.password_hash (read) β
β - Accesses: sessions.token (read/write) β
β - Risk: HIGH (authentication boundary) β
β β
β π§ͺ TESTING β
β - Covered by: auth.test.ts (12 tests) β
β - Coverage: 94% β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
drift_explain({
target: "src/auth/middleware.ts", // File, function, or symbol
depth: "comprehensive", // summary | detailed | comprehensive
focus: "security" // Optional: security | performance | architecture | testing
})Depth Options:
| Depth | Description | Token Cost |
|---|---|---|
summary |
Quick overview, key points | ~500 |
detailed |
Patterns, dependencies, basic analysis | ~1500 |
comprehensive |
Full analysis including security, testing | ~3000 |
Focus Options:
| Focus | Emphasizes |
|---|---|
security |
Data access, sensitive paths, vulnerabilities |
performance |
Caching, N+1 queries, optimization opportunities |
architecture |
Patterns, coupling, module boundaries |
testing |
Coverage, test quality, gaps |
Response:
{
"summary": "**middleware.ts** is a critical-importance data layer file. Data access layer for users, sessions (read). 2 data access point(s). β οΈ Deviates from 0 pattern(s). π 1 security concern(s).",
"data": {
"target": "src/auth/middleware.ts",
"depth": "comprehensive",
"focus": "security",
"explanation": {
"summary": "**middleware.ts** is a critical-importance data layer file...",
"purpose": "Data access layer for users, sessions (read)",
"context": {
"module": "auth",
"role": "data layer",
"importance": "critical"
},
"patterns": [
{
"name": "Auth Middleware Pattern",
"category": "auth",
"compliance": "follows",
"note": "Consistent with 23 implementations"
},
{
"name": "Error Handling Pattern",
"category": "errors",
"compliance": "follows",
"note": "Consistent with 45 implementations"
}
],
"dependencies": {
"imports": [],
"usedBy": ["getUsers", "createOrder", "updateProfile"],
"calls": [],
"dataAccess": [
{ "table": "users", "operation": "read", "fields": ["id", "email", "password_hash"] },
{ "table": "sessions", "operation": "read", "fields": ["token", "expires_at"] }
]
},
"security": {
"sensitiveData": ["password_hash", "token"],
"accessLevel": "public",
"concerns": ["Raw SQL at line 23"],
"reachableSensitiveFields": ["users.password_hash", "sessions.token"]
},
"semantics": {
"functions": 0,
"asyncFunctions": 0,
"exportedFunctions": 0,
"dataAccessPoints": 2,
"frameworks": ["Prisma"]
},
"insights": [
"Accesses 2 data point(s) across 2 table(s)",
"Participates in 2 pattern(s)",
"β οΈ 1 security concern(s)",
"π Can reach 2 sensitive field(s)"
],
"nextSteps": [
"Run drift_suggest_changes with issue=\"security\"",
"Use drift_reachability to trace sensitive data",
"Review raw SQL queries for injection vulnerabilities"
]
}
},
"hints": {
"nextActions": [
"Run drift_suggest_changes with issue=\"security\"",
"Use drift_reachability to trace sensitive data",
"Review raw SQL queries for injection vulnerabilities"
],
"relatedTools": ["drift_impact_analysis", "drift_reachability", "drift_code_examples"]
}
}While there's no direct CLI command, you can get explanations via:
# Get file patterns and context
drift files src/auth/middleware.ts --verbose
# Get call graph information
drift callgraph function requireAuth
# Get security information
drift boundaries file src/auth/middleware.ts// Understand the main entry point
drift_explain({
target: "src/index.ts",
depth: "comprehensive"
})// Understand what you're about to change
drift_explain({
target: "src/services/payment.ts",
depth: "detailed",
focus: "security"
})// Understand PR changes in context
drift_explain({
target: "src/new-feature/handler.ts",
depth: "detailed",
focus: "architecture"
})// Deep dive into security-critical code
drift_explain({
target: "src/auth/",
depth: "comprehensive",
focus: "security"
})drift_explain({ target: "src/auth/middleware.ts", depth: "summary" }){
"summary": "**middleware.ts** is a critical-importance data layer file. Data access layer for users, sessions (read).",
"data": {
"target": "src/auth/middleware.ts",
"depth": "summary",
"explanation": {
"summary": "...",
"purpose": "Data access layer for users, sessions (read)",
"context": { "module": "auth", "role": "data layer", "importance": "critical" },
"patterns": [],
"dependencies": { "imports": [], "usedBy": [], "calls": [], "dataAccess": [] },
"insights": ["Accesses 2 data point(s) across 2 table(s)"],
"nextSteps": ["Use drift_code_examples to see similar implementations"]
}
}
}drift_explain({ target: "src/auth/middleware.ts", depth: "detailed" })Adds: patterns, dependencies, data access details, basic security info
drift_explain({ target: "src/auth/middleware.ts", depth: "comprehensive" })Adds: full security analysis with reachable sensitive fields, semantic analysis, detailed insights
// First understand the code
const explanation = await drift_explain({
target: "src/auth/middleware.ts",
depth: "detailed"
});
// Then check impact of changes
const impact = await drift_impact_analysis({
target: "src/auth/middleware.ts"
});// Understand existing code
const explanation = await drift_explain({
target: "src/services/user.ts"
});
// Find similar code to use as reference
const similar = await drift_similar({
intent: "service",
description: explanation.data.explanation.purpose
});// Quick understanding first
const summary = await drift_explain({
target: "src/complex/module.ts",
depth: "summary"
});
// Go deeper if needed
if (needsMoreDetail) {
const detailed = await drift_explain({
target: "src/complex/module.ts",
depth: "comprehensive"
});
}// Security review
drift_explain({ target: "src/auth/", focus: "security" })
// Performance optimization
drift_explain({ target: "src/api/", focus: "performance" })Always understand code before changing it:
// 1. Explain
const explanation = await drift_explain({ target: file });
// 2. Check impact
const impact = await drift_impact_analysis({ target: file });
// 3. Make changes with full context- Impact Analysis β Understand blast radius
- Security Analysis β Deep security review
- Call Graph Analysis β Dependency mapping
- Cortex V2 Overview
- Memory Setup Wizard
- Memory CLI
- Universal Memory Types
- Learning System
- Token Efficiency
- Causal Graphs
- Code Generation
- Predictive Retrieval
- Architecture
- Call Graph Analysis
- Impact Analysis
- Security Analysis
- Data Boundaries
- Test Topology
- Coupling Analysis
- Error Handling Analysis
- Wrappers Detection
- Environment Variables
- Constants Analysis
- Styling DNA
- Constraints
- Contracts
- Decision Mining
- Speculative Execution
- Watch Mode
- Trends Analysis
- Projects Management
- Package Context
- Monorepo Support
- Reports & Export
- Dashboard
- 10 Languages
- 21 Frameworks
- 16 ORMs
- 400+ Detectors
- 50+ MCP Tools
- 60+ CLI Commands
- 23 Memory Types