Skip to Content

dev_inspect

Inspect a file for pattern analysis. Finds similar code and compares patterns like error handling, type coverage, imports, and testing.

Usage

dev_inspect(query, format?, limit?, threshold?)

Parameters

ParameterTypeDefaultDescription
querystringrequiredFile path to inspect
format"compact" | "verbose""compact"Output format
limitnumber10Maximum similar files to analyze
thresholdnumber0.7Similarity threshold (0-1)

What It Does

dev_inspect performs comprehensive file analysis in two steps:

  1. Finds similar files - Uses semantic search to find code with similar structure/purpose
  2. Analyzes patterns - Compares error handling, type coverage, imports, testing, and file size

This helps you understand how your file compares to similar code in the repository.

Examples

Basic Inspection

ā€œUse dev_inspect with query ā€˜src/auth/middleware.tsā€˜ā€œ

## File Inspection: src/auth/middleware.ts ### Similar Files (5 analyzed) 1. `src/auth/session.ts` (78%) 2. `src/middleware/logger.ts` (72%) 3. `src/api/auth-handler.ts` (68%) ### Pattern Analysis **Import Style:** Your file uses `esm`, matching 100% of similar files. **Error Handling:** Your file uses `throw`, but 60% of similar files use `result`. **Type Coverage:** Your file has `full` type coverage, matching 80% of similar files. **Testing:** No test file found. 40% of similar files have tests. **Size:** 234 lines (smaller than average of 312 lines)

Verbose Output

ā€œUse dev_inspect with query ā€˜packages/core/src/indexer/index.ts’, format ā€˜verboseā€™ā€

Returns detailed pattern distribution and statistics for each pattern category.

High Similarity Only

ā€œUse dev_inspect with query ā€˜src/utils/date.ts’, threshold 0.9ā€

Only analyzes very similar files (90%+ match).

Pattern Categories

dev_inspect analyzes 5 key patterns:

PatternWhat It Checks
Import Styleesm, cjs, mixed, or unknown
Error Handlingthrow, result, callback, or unknown
Type Coveragefull, partial, or none (TypeScript only)
TestingWhether a co-located test file exists
File SizeLine count vs. similar files

Output Formats

Compact (Default)

Shows pattern summary with actionable insights:

**Error Handling:** Your file uses `throw`, but 60% of similar files use `result`.

Highlights differences from similar files to guide improvements.

Verbose

Shows full pattern distribution:

#### Error Handling - **Your File:** `throw` - **Common Style:** `result` (60% of similar files) - **Distribution:** - result: 3 files (60%) - throw: 2 files (40%)

Use Cases

Use CaseDescription
Code ReviewCheck if your code follows project patterns
RefactoringUnderstand pattern usage before making changes
ConsistencyEnsure new code matches similar implementations
LearningSee how patterns are used across the codebase

Workflow

Typical usage pattern:

  1. Search for concepts: dev_search { query: "authentication middleware" }
  2. Inspect what you found: dev_inspect { query: "src/auth/middleware.ts" }
  3. Analyze dependencies: dev_refs { name: "authMiddleware" }

Tips

Always provide a file path. Unlike dev_search, dev_inspect requires a specific file to analyze.

Extension filtering. Only compares files with the same extension (e.g., .ts with .ts).

Use after search. dev_inspect is most valuable after finding relevant files with dev_search.

Pattern-driven insights. Focus on patterns where your file differs from similar code.

Performance

dev_inspect is optimized for speed:

  • Batch scanning (5-10x faster than individual scans)
  • Semantic similarity matching (not just path-based)
  • Extension-based filtering for relevant comparisons

Typical analysis time: 500-1000ms for 5 similar files.

Migration from dev_explore

If you previously used dev_explore:

  • dev_explore { action: "similar", query: "file.ts" } → dev_inspect { query: "file.ts" }
  • dev_explore { action: "validate", query: "file.ts" } → dev_inspect { query: "file.ts" } (now does both!)
  • dev_explore { action: "pattern" } → Use dev_search instead
  • dev_explore { action: "relationships" } → Use dev_refs instead

Key change: dev_inspect no longer requires an action parameter. It automatically finds similar files AND performs pattern analysis in one call.

Last updated on