dev_patterns
Analyze coding patterns in a file against similar code in the codebase. Compares import style, error handling, type coverage, test coverage, and file size.
Not for finding code (use dev_search) or tracing calls (use dev_refs).
Usage
dev_patterns(filePath, format?, limit?)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
filePath | string | required | File path to analyze (e.g., src/auth/middleware.ts) |
format | "compact" | "verbose" | "json" | "compact" | Output format |
limit | number | 10 | Maximum similar files to analyze |
What It Does
dev_patterns performs comprehensive file analysis in two steps:
- Finds similar files — Uses semantic search to find code with similar structure/purpose
- Analyzes patterns — Compares error handling, type coverage, imports, testing, and file size
Examples
Basic Inspection
“Use dev_patterns with filePath ‘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_patterns with filePath ‘packages/core/src/indexer/index.ts’, format ‘verbose’”
Returns detailed pattern distribution and statistics for each pattern category.
JSON Output (Token-Efficient)
“Use dev_patterns with filePath ‘src/auth/middleware.ts’, format ‘json’”
Returns structured JSON — compact and machine-parseable for agent workflows:
{
"fileSize": { "yourFile": 234, "average": 312, "deviation": "smaller" },
"importStyle": { "yourFile": "esm", "common": "esm", "percentage": 100 },
"errorHandling": { "yourFile": "throw", "common": "result", "percentage": 60 },
"typeAnnotations": { "yourFile": "full", "common": "full", "percentage": 80 },
"testing": { "yourFile": false, "percentage": 40 }
}Pattern Categories
| Pattern | What It Checks |
|---|---|
| Import Style | esm, cjs, mixed, or unknown |
| Error Handling | throw, result, error-return, or unknown |
| Type Coverage | full, partial, minimal, or none (TypeScript only) |
| Testing | Whether a co-located test file exists |
| File Size | Line count vs. similar files |
Workflow
Typical usage pattern:
- Search for concepts:
dev_search { query: "authentication middleware" } - Inspect what you found:
dev_patterns { filePath: "src/auth/middleware.ts" } - Analyze dependencies:
dev_refs { name: "authMiddleware" }
Performance
Pattern analysis reads from the Antfly index when available (~100ms). Falls back to ts-morph scanning when not (~1-3s).
Migration from dev_explore
If you previously used dev_explore:
dev_explore { action: "similar", query: "file.ts" }→dev_patterns { filePath: "file.ts" }dev_explore { action: "validate", query: "file.ts" }→dev_patterns { filePath: "file.ts" }(now does both!)dev_explore { action: "pattern" }→ Usedev_searchinsteaddev_explore { action: "relationships" }→ Usedev_refsinstead