/github-cleanup-duplicates
Clean up duplicate GitHub issues for a Feature. Finds issues with duplicate titles and closes all except the first created issue.
> /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.mddescription: 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
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
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.
Repo: anton-abyzov/specweave
Other commands on specweave.
- /abandon
Abandon an incomplete increment (requirements changed, obsolete)
Open command - /ado-cleanup-duplicates
Clean up duplicate Azure DevOps work items for a Feature. Finds work items with duplicate titles and closes all except the first created item.
Open command - /ado-clone
Clone Azure DevOps repositories to local workspace. Use after init if cloning was skipped, or to add repos later.
Open command - /ado-close
Close Azure DevOps work item when increment complete
Open command - /ado-create
Create Azure DevOps work item from SpecWeave increment
Open command - /ado-import-areas
Import Azure DevOps area paths from a project and map them to SpecWeave projects. Creates 2-level directory structure with area path-based organization.
Open command

