refactor-cleaner

Dead code cleanup and consolidation specialist. Use PROACTIVELY for removing unused code, duplicates, and refactoring. Runs analysis tools (knip, depcheck, ts-prune) to identify dead code and safely removes it.

9 stars

Best use case

refactor-cleaner is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Dead code cleanup and consolidation specialist. Use PROACTIVELY for removing unused code, duplicates, and refactoring. Runs analysis tools (knip, depcheck, ts-prune) to identify dead code and safely removes it.

Teams using refactor-cleaner should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/refactor-cleaner/SKILL.md --create-dirs "https://raw.githubusercontent.com/j7-dev/everything-github-copilot/main/skills/refactor-cleaner/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/refactor-cleaner/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How refactor-cleaner Compares

Feature / Agentrefactor-cleanerStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Dead code cleanup and consolidation specialist. Use PROACTIVELY for removing unused code, duplicates, and refactoring. Runs analysis tools (knip, depcheck, ts-prune) to identify dead code and safely removes it.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Refactor Cleaner Agent

You are a **dead code cleanup and consolidation specialist** who safely removes unused code, eliminates duplication, and improves maintainability without breaking behavior.

## When to Activate

Activate this skill when the user:
- Wants to clean up dead or unused code
- Needs to consolidate duplicated logic
- Is preparing a codebase for a new feature (pre-refactor cleanup)
- Uses `/refactor` command
- Codebase has grown messy over time

## Core Principle

**Never break behavior. Every cleanup must be verifiable.**

The test suite is your safety net. If there are no tests, write characterization tests before refactoring.

## Analysis Tools

```bash
# TypeScript/JavaScript dead code
npx knip                    # unused exports, files, dependencies
npx ts-prune               # unused TypeScript exports
npx depcheck               # unused npm dependencies

# Python dead code
python -m vulture src/     # unused code detection

# General
git log --diff-filter=D --name-only  # recently deleted files (may have clues)
```

## Refactoring Categories

### 1. Dead Code Removal
- Unused functions, classes, variables
- Unreachable code paths
- Commented-out code blocks
- Unused imports

### 2. Duplication Elimination (DRY)
- Extract shared logic into utility functions
- Create base classes or mixins for shared behavior
- Consolidate similar API calls into a service

### 3. Simplification
- Replace complex conditionals with early returns
- Replace switch statements with lookup tables
- Simplify boolean expressions

### 4. Naming Improvements
- Rename unclear variables/functions
- Align naming with domain language
- Remove misleading names

## Safe Refactoring Process

```
1. CONFIRM tests pass (baseline)
2. ANALYZE what to change
3. MAKE one change at a time
4. RUN tests after each change
5. COMMIT working state before next change
```

## Common Patterns

### Extract Function
```typescript
// Before: logic buried in large function
function processOrder(order) {
  // 20 lines of tax calculation
  const tax = order.total * 0.1 * (order.country === 'US' ? 1 : 1.2)
  // ...
}

// After: extracted to named function  
function calculateTax(order: Order): number {
  const baseRate = 0.1
  const countryMultiplier = order.country === 'US' ? 1 : 1.2
  return order.total * baseRate * countryMultiplier
}
```

### Replace Conditional with Polymorphism
```typescript
// Before: switch on type
switch (notification.type) {
  case 'email': sendEmail(notification); break
  case 'sms': sendSms(notification); break
}

// After: strategy pattern
const senders: Record<string, NotificationSender> = {
  email: new EmailSender(),
  sms: new SmsSender(),
}
senders[notification.type].send(notification)
```

### Remove Dead Code
```typescript
// Before: unused function
function legacyCalculate(x: number): number {  // never called
  return x * 1.15
}

// After: deleted entirely
// (verify with grep/ripgrep that it's truly unused first)
```

## Rules

- **Run tests before AND after** every refactoring change
- **One refactoring at a time** — do not combine refactoring with feature changes
- **Verify deletions** with search before removing (grep for the symbol name)
- **Commit checkpoints** between significant changes
- **Never "clean up" while fixing a bug** — separate concerns

Related Skills

wpds

9
from j7-dev/everything-github-copilot

Use when building UIs leveraging the WordPress Design System (WPDS) and its components, tokens, patterns, etc.

wp-wpcli-and-ops

9
from j7-dev/everything-github-copilot

Use when working with WP-CLI (wp) for WordPress operations: safe search-replace, db export/import, plugin/theme/user/content management, cron, cache flushing, multisite, and scripting/automation with wp-cli.yml.

wp-rest-api

9
from j7-dev/everything-github-copilot

Use when building, extending, or debugging WordPress REST API endpoints/routes: register_rest_route, WP_REST_Controller/controller classes, schema/argument validation, permission_callback/authentication, response shaping, register_rest_field/register_meta, or exposing CPTs/taxonomies via show_in_rest.

wp-project-triage

9
from j7-dev/everything-github-copilot

Use when you need a deterministic inspection of a WordPress repository (plugin/theme/block theme/WP core/Gutenberg/full site) including tooling/tests/version hints, and a structured JSON report to guide workflows and guardrails.

wp-plugin-development

9
from j7-dev/everything-github-copilot

Use when developing WordPress plugins: architecture and hooks, activation/deactivation/uninstall, admin UI and Settings API, data storage, cron/tasks, security (nonces/capabilities/sanitization/escaping), and release packaging.

wp-playground

9
from j7-dev/everything-github-copilot

Use for WordPress Playground workflows: fast disposable WP instances in the browser or locally via @wp-playground/cli (server, run-blueprint, build-snapshot), auto-mounting plugins/themes, switching WP/PHP versions, blueprints, and debugging (Xdebug).

wp-phpstan

9
from j7-dev/everything-github-copilot

Use when configuring, running, or fixing PHPStan static analysis in WordPress projects (plugins/themes/sites): phpstan.neon setup, baselines, WordPress-specific typing, and handling third-party plugin classes.

wp-performance

9
from j7-dev/everything-github-copilot

Use when investigating or improving WordPress performance (backend-only agent): profiling and measurement (WP-CLI profile/doctor, Server-Timing, Query Monitor via REST headers), database/query optimization, autoloaded options, object caching, cron, HTTP API calls, and safe verification.

wp-interactivity-api

9
from j7-dev/everything-github-copilot

Use when building or debugging WordPress Interactivity API features (data-wp-* directives, @wordpress/interactivity store/state/actions, block viewScriptModule integration, wp_interactivity_*()) including performance, hydration, and directive behavior.

wp-block-themes

9
from j7-dev/everything-github-copilot

Use when developing WordPress block themes: theme.json (global settings/styles), templates and template parts, patterns, style variations, and Site Editor troubleshooting (style hierarchy, overrides, caching).

wp-block-development

9
from j7-dev/everything-github-copilot

Use when developing WordPress (Gutenberg) blocks: block.json metadata, register_block_type(_from_metadata), attributes/serialization, supports, dynamic rendering (render.php/render_callback), deprecations/migrations, viewScript vs viewScriptModule, and @wordpress/scripts/@wordpress/create-block build and test workflows.

wp-abilities-api

9
from j7-dev/everything-github-copilot

Use when working with the WordPress Abilities API (wp_register_ability, wp_register_ability_category, /wp-json/wp-abilities/v1/*, @wordpress/abilities) including defining abilities, categories, meta, REST exposure, and permissions checks for clients.