Skip to content
Development
Command

/github-cleanup-duplicates

Clean up duplicate GitHub issues for a Feature. Finds issues with duplicate titles and closes all except the first created issue.

From plugin
specweave
15673 skills20 agents73 commands
Install
> /plugin marketplace add anton-abyzov/specweave
> /plugin install sw@specweave

How it fires

How this command gets triggered: by you, by Claude, or both.

  • Fires itselfClaude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/github-cleanup-duplicates

Context preview

What this command does when you run it.

Clean up duplicate GitHub issues for a Feature. Finds issues with duplicate titles and closes all except the first created issue.

Command definition

github-cleanup-duplicates.md
description: Clean up duplicate GitHub issues for a Feature. Finds issues with duplicate titles and closes all except the first created issue.
justification: |
  CRITICAL INCIDENT RESPONSE TOOL - DO NOT DELETE!

  Why This Command Exists:
  - Prevention systems (deduplication, GitHub self-healing) work for single-process execution
  - Multiple parallel Claude Code instances bypass all prevention (file-based cache, no distributed locking)
  - GitHub API race conditions: Time gap between "check exists" and "create issue" allows duplicates
  - Historical duplicates from pre-v0.14.1 users (before prevention was added)

  Evidence of Need:
  - 2025-11-13: 123 duplicate GitHub issues incident (cleaned to 29 unique)
  - Parallel execution creates race conditions that prevention CANNOT solve
  - Industry standard: Prevention + Detection + Cleanup (defense in depth)

  When to Delete:
  - ONLY if distributed locking implemented (Redis/file locks)
  - AND parallel execution tested (100+ concurrent syncs with zero duplicates)
  - AND zero duplicates for 6+ months in production
  - AND all users migrated to prevention-enabled versions

  See: .specweave/increments/0043-spec-md-desync-fix/reports/ULTRATHINK-CLEANUP-DUPLICATES-NECESSITY-2025-11-18.md

Clean Up Duplicate GitHub Issues

**CRITICAL**: This command detects and closes duplicate GitHub issues created by multiple syncs.

Usage

sw-github:cleanup-duplicates <epic-id> [--dry-run]

What It Does

**Duplicate Detection & Cleanup**:

1. **Find all issues** for the Epic (searches by Epic ID in title) 2. **Group by title** (detect duplicates) 3. **For each duplicate group**:

  • Keep the **FIRST created** issue (lowest number)
  • Close all **LATER** issues with comment: "Duplicate of #XXX"

4. **Update Epic README** with correct issue numbers

Examples

Dry Run (No Changes)

sw-github:cleanup-duplicates FS-031 --dry-run

**Output**:

๐Ÿ” Scanning for duplicates in Epic FS-031...
   Found 25 total issues
   Detected 10 duplicate groups:

   ๐Ÿ“‹ Group 1: "[FS-031] External Tool Status Synchronization"
      - #250 (KEEP) - Created 2025-11-10
      - #255 (CLOSE) - Created 2025-11-11 - DUPLICATE
      - #260 (CLOSE) - Created 2025-11-12 - DUPLICATE

   ๐Ÿ“‹ Group 2: "[FS-031] Multi-Project GitHub Sync"
      - #251 (KEEP) - Created 2025-11-10
      - #256 (CLOSE) - Created 2025-11-11 - DUPLICATE

   ...

โœ… Dry run complete!
   Total issues: 25
   Duplicate groups: 10
   Issues to close: 15

โš ๏ธ  This was a DRY RUN - no changes made.
   Run without --dry-run to actually close duplicates.

Actual Cleanup

sw-github:cleanup-duplicates FS-031

**Output**:

๐Ÿ” Scanning for duplicates in Epic FS-031...
   Found 25 total issues
   Detected 10 duplicate groups

โš ๏ธ  CONFIRM: Close 15 duplicate issues? [y/N]
> y

๐Ÿ—‘๏ธ  Closing duplicates...
   โœ… Closed #255 (duplicate of #250)
   โœ… Closed #256 (duplicate of #251)
   โœ… Closed #260 (duplicate of #250)
   ...

๐Ÿ“ Updating Epic README frontmatter...
   โœ… Updated frontmatter with correct issue numbers

โœ… Cleanup complete!
   Closed: 15 duplicates
   Kept: 10 original issues

Arguments

  • `<epic-id>` - Epic ID (e.g., `FS-031` or just `031`)
  • `--dry-run` - Preview changes without actually closing issues (optional)

Safety Features

โœ… **Confirmation prompt**: Asks before closing issues (unless --dry-run) โœ… **Dry run mode**: Preview changes safely โœ… **Keeps oldest issue**: Preserves the first created issue โœ… **Adds closure comment**: Links to the original issue โœ… **Updates metadata**: Fixes Epic README frontmatter

What Gets Closed

**Closed issues**:

  • โœ… Duplicate titles (second, third, etc. occurrences)
  • โœ… Closed with comment: "Duplicate of #XXX"
  • โœ… Original issue kept open (or maintains its status)

**Example comment on closed duplicate**:

Duplicate of #250

This issue was automatically closed by SpecWeave cleanup because it is a duplicate.

The original issue (#250) contains the same content and should be used for tracking instead.

๐Ÿค– Auto-closed by SpecWeave Duplicate Cleanup

Requirements

1. **GitHub CLI** (`gh`) installed and authenticated 2. **Write access** to repository (for closing issues) 3. **Epic folder exists** at `.specweave/docs/internal/specs/FS-XXX-name/`

When to Use

**Use this command when**:

  • โœ… You see multiple issues with the same title in GitHub
  • โœ… Epic sync ran multiple times and created duplicates
  • โœ… Epic README frontmatter got corrupted and reset
  • โœ… Post-sync validation warns about duplicates

**Example warning that triggers this**:

โš ๏ธ  WARNING: 10 duplicate(s) detected!
   Run cleanup command to resolve:
   sw-github:cleanup-duplicates FS-031

Troubleshooting

**"No duplicates found"**:

  • Good! Your Epic has no duplicate issues
  • Run epic sync is working correctly with duplicate detection

**"GitHub CLI not authenticated"**:

  • Run: `gh auth login`
  • Ensure you have write access to the repository

**"Could not find Epic folder"**:

  • Check Epic exists: `ls .specweave/docs/internal/specs/`
  • Verify Epic ID format: `FS-031-epic-name/`

**"Error closing issue"**:

  • Check GitHub CLI: `gh auth status`
  • Verify write permissions: `gh repo view`

Architecture

**Duplicate Detection Logic**: 1. Group issues by **exact title match** 2. Within each group, sort by **issue number** (ascending) 3. Keep **first issue** (lowest number = oldest) 4. Close **all others** as duplicates

**Why lowest number?**:

  • Lower issue numbers were created first
  • Preserves chronological order
  • Maintains links from old documentation

Related Commands

  • `sw-github:sync` - Sync Feature to GitHub (with duplicate detection)
  • `sw:validate` - Validate increment completeness
  • `gh issue list` - View all issues (GitHub CLI)

Implementation

**File**: `plugins/specweave-github/lib/duplicate-detector.ts`

**Class**: `DuplicateDetector`

**Algorithm** (3-phase protection): 1. **Detection**: Search GitH

Read more
Ships withspecweave

Spec-first AI development: describe a feature โ†’ AI creates spec + plan + tasks, builds autonomously, syncs to GitHub/JIRA. Domain-expert skills for PM, Architect, Frontend, QA learn your patterns permanently. Claude Code, Codex, Cursor, Copilot & more.

Get the whole plugin