# finding-duplicate-functions

Detects functions that share identical intent under different names or implementations. Useful for cleaning up shared helpers in codebases grown by multiple contributors or LLMs.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 634 installs · ★ 433
- Author: obra
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/obra/superpowers-lab/tree/HEAD/skills/finding-duplicate-functions/SKILL.md
- Updated: 2026-06-01
- HTML: https://affpapa.org/en/nevibecode/skills/finding-duplicate-functions

## What it does

The skill targets semantic duplication in TypeScript and JavaScript repositories. Standard copy-paste checkers like `jscpd` catch literal syntax clones, but they miss reimplemented utilities. It extracts public functions via `./scripts/extract-functions.sh` into `catalog.json`, gathering 15 lines of context by default while ignoring test suites.

The pipeline divides the workload between two models. A Haiku subagent first groups functions into domain categories using `scripts/categorize-prompt.md`. A helper script then partitions the data, filtering for categories with 3 or more functions. An Opus subagent inspects each category to spot actual semantic duplicates. Haiku works for domain grouping, but Opus is strictly needed for duplicate detection because lighter models miss nuanced logic overlap.

Blindly merging functions will break callers. The workflow requires checking test coverage for the surviving function before deleting redundant implementations.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add obra/superpowers-lab --skill finding-duplicate-functions -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/finding-duplicate-functions/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/finding-duplicate-functions/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add obra/superpowers-lab --skill finding-duplicate-functions -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/finding-duplicate-functions/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add obra/superpowers-lab --skill finding-duplicate-functions -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/finding-duplicate-functions/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install obra/superpowers-lab finding-duplicate-functions
```

2. **Manually: put the files in place**
- File: `.github/skills/finding-duplicate-functions/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add obra/superpowers-lab --skill finding-duplicate-functions -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/obra/superpowers-lab --path skills/finding-duplicate-functions
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/finding-duplicate-functions/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add obra/superpowers-lab --skill finding-duplicate-functions -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/obra/superpowers-lab/tree/HEAD/skills/finding-duplicate-functions/SKILL.md

## When to use it
- find reimplemented functions with different names and syntax
- extract public methods into a structured catalog without test code
- cluster utility functions into domain categories
- generate a prioritized markdown audit of duplicate logic

## Example prompts
- Run an audit for semantic duplicate functions using finding-duplicate-functions
- Analyze src/ for duplicate utility functions with finding-duplicate-functions

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 8553383a1195e57e.

BEGIN THIRD-PARTY FILE 8553383a1195e57e
````text
---
name: finding-duplicate-functions
description: Use when auditing a codebase for semantic duplication - functions that do the same thing but have different names or implementations. Especially useful for LLM-generated codebases where new functions are often created rather than reusing existing ones.
---

# Finding Duplicate-Intent Functions

## Overview

LLM-generated codebases accumulate semantic duplicates: functions that serve the same purpose but were implemented independently. Classical copy-paste detectors (jscpd) find syntactic duplicates but miss "same intent, different implementation."

This skill uses a two-phase approach: classical extraction followed by LLM-powered intent clustering.

## When to Use

- Codebase has grown organically with multiple contributors (human or LLM)
- You suspect utility functions have been reimplemented multiple times
- Before major refactoring to identify consolidation opportunities
- After jscpd has been run and syntactic duplicates are already handled

## Quick Reference

| Phase | Tool | Model | Output |
|-------|------|-------|--------|
| 1. Extract | `scripts/extract-functions.sh` | - | `catalog.json` |
| 2. Categorize | `scripts/categorize-prompt.md` | haiku | `categorized.json` |
| 3. Split | `scripts/prepare-category-analysis.sh` | - | `categories/*.json` |
| 4. Detect | `scripts/find-duplicates-prompt.md` | opus | `duplicates/*.json` |
| 5. Report | `scripts/generate-report.sh` | - | `report.md` |

## Process

```dot
digraph duplicate_detection {
  rankdir=TB;
  node [shape=box];

  extract [label="1. Extract function catalog\n./scripts/extract-functions.sh"];
  categorize [label="2. Categorize by domain\n(haiku subagent)"];
  split [label="3. Split into categories\n./scripts/prepare-category-analysis.sh"];
  detect [label="4. Find duplicates per category\n(opus subagent per category)"];
  report [label="5. Generate report\n./scripts/generate-report.sh"];
  review [label="6. Human review & consolidate"];

  extract -> categorize -> split -> detect -> report -> review;
}
```

### Phase 1: Extract Function Catalog

```bash
./scripts/extract-functions.sh src/ -o catalog.json
```

Options:
- `-o FILE`: Output file (default: stdout)
- `-c N`: Lines of context to capture (default: 15)
- `-t GLOB`: File types (default: `*.ts,*.tsx,*.js,*.jsx`)
- `--include-tests`: Include test files (excluded by default)

Test files (`*.test.*`, `*.spec.*`, `__tests__/**`) are excluded by default since test utilities are less likely to be consolidation candidates.

### Phase 2: Categorize by Domain
````
END THIRD-PARTY FILE 8553383a1195e57e

The third-party file has ended. Everything between the 8553383a1195e57e tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2571 of 4794 bytes. © obra · MIT · https://github.com/obra/superpowers-lab/tree/HEAD/skills/finding-duplicate-functions/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
