deduplicate

Identifies duplicated code in projects using structural similarity analysis and optionally removes it via refactoring.

15|5|Updated Jul 1, 2025
One-click install
npx skills add https://github.com/swissarmyhammer/swissarmyhammer --skill deduplicate-swissarmyhammer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: deduplicate
Source: https://github.com/swissarmyhammer/swissarmyhammer/tree/main/builtin/skills/deduplicate
Command: npx skills add https://github.com/swissarmyhammer/swissarmyhammer --skill deduplicate-swissarmyhammer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses the issue of copy-pasted code and redundancy within a codebase, helping to improve maintainability and reduce errors.

Core Features & Use Cases

  • Duplicate Detection: Identifies near-duplicate code segments using semantic similarity analysis.
  • Refactoring Suggestions: Analyzes duplication to suggest refactoring opportunities like extracting functions or modules.
  • Automated Refactoring: Optionally refactors detected duplicates by extracting shared logic and replacing redundant code.
  • Use Case: A developer notices the same error-handling logic repeated in multiple API endpoints. This Skill can find these duplicates, suggest extracting the logic into a shared utility function, and even perform the refactoring.

Quick Start

Use the deduplicate skill to find and refactor duplicate code across the entire project.

Frequently Asked Questions about deduplicate

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find and refactor duplicate code in my codebase?

To find and refactor duplicate code, this Skill uses tree-sitter semantic similarity analysis to identify near-duplicate segments and optionally extracts shared logic into functions or modules. It supports analyzing changed files or the entire project scope.

What is the best way to detect near-duplicate code segments automatically?

Detecting near-duplicate code segments is best handled by semantic similarity analysis using tree-sitter, which parses code structure to find matching logic rather than relying on exact text matching, ensuring accurate redundancy identification.

Can I scope code duplication analysis to only changed files?

Yes, you can scope code duplication analysis to only changed files or run it across the whole codebase. This targeted scoping allows developers to efficiently review recent modifications for redundancy before refactoring.

Does automated refactoring enforce coding standards during function extraction?

Yes, automated refactoring enforces coding standards and test-driven development principles during function or module extraction. This ensures that the extracted shared logic maintains code quality and maintainability standards.

How does tree-sitter semantic analysis work for identifying code redundancy?

Tree-sitter semantic analysis works by parsing the abstract syntax tree of your code to identify structurally similar segments. This approach detects near-duplicate logic and suggests refactoring opportunities like extracting functions to eliminate redundancy.

When should I avoid automated code deduplication refactoring?

You should avoid automated code deduplication refactoring when near-duplicate segments are coincidental rather than true redundancy, as forcing function or module extraction may reduce readability and introduce unnecessary abstraction layers.