Analyze codebases to identify reusable code patterns, duplications, and implementation patterns for future development. Use when refactoring code, identifying technical debt, finding opportunities for abstraction, or documenting common patterns in a directory or module. Outputs pattern catalogs, refactoring suggestions, and reusable template code.
76
71%
Does it follow best practices?
Impact
76%
1.40xAverage score across 3 eval scenarios
Passed
No known issues
Optimize this skill with Tessl
npx tessl skill review --optimize ./skills/code-pattern-extractor/SKILL.mdSystematically analyze code in directories or modules to identify recurring patterns, code duplication, and implementation patterns that can be abstracted into reusable components, utilities, or design patterns.
Identify the code to analyze:
Use Glob to find relevant files:
**/*.js, **/*.py, **/*.go, etc.Identify repeated code blocks that appear multiple times:
Look for:
Analysis criteria:
Find recurring implementation approaches:
Common patterns:
Example patterns to detect:
// Pattern: API call with error handling
async function fetchX() {
try {
const response = await fetch(url);
if (!response.ok) throw new Error();
return await response.json();
} catch (error) {
console.error(error);
return null;
}
}Group identified patterns by type and impact:
Categories:
Pattern types:
Document each identified pattern:
Pattern entry format:
## Pattern: [Descriptive Name]
**Type**: [Utility/API/UI/Business Logic]
**Frequency**: [Number of occurrences]
**Impact**: [High/Medium/Low]
**Description**: [What the pattern does]
**Current implementations**:
- `file1.js:45-60` - [Brief context]
- `file2.js:120-135` - [Brief context]
- `file3.js:89-104` - [Brief context]
**Common variations**:
- [Variation 1 description]
- [Variation 2 description]For each high-value pattern, provide refactoring recommendations:
Suggestion format:
### Refactoring: Extract [Pattern Name]
**Current state**: Pattern appears in [N] locations with [X]% code duplication
**Proposed solution**: Extract into [utility function/class/hook/module]
**Benefits**:
- Reduce code duplication by ~[N] lines
- Centralize logic for easier maintenance
- Improve testability
**Implementation approach**:
1. Create new file: `utils/[pattern-name].js`
2. Extract common logic with parameters for variations
3. Replace [N] occurrences with function calls
4. Add unit tests
**Estimated effort**: [Small/Medium/Large]Create reusable template implementations for high-value patterns:
Template format:
/**
* [Pattern description]
*
* @param {type} param1 - [Description]
* @param {type} param2 - [Description]
* @returns {type} [Description]
*/
function patternTemplate(param1, param2) {
// Extracted common logic
// Parameterized variations
// Return standardized result
}Include:
Organize findings into a comprehensive report:
# Code Pattern Analysis: [Directory/Module Name]
## Summary
- Files analyzed: [N]
- Patterns identified: [N]
- High-value patterns: [N]
- Estimated duplication: [N] lines
## Pattern Catalog
[List of all identified patterns with details]
## Refactoring Suggestions
[Prioritized list of refactoring opportunities]
## Template Code
[Reusable implementations for high-value patterns]
## Next Steps
[Recommended actions prioritized by impact]Code duplication detection:
Implementation pattern detection:
Abstraction opportunities:
0f00a4f
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.