Provides a structured, safe process for refactoring and removing dead code while verifying results with tests.

Install

mkdir -p .claude/skills/refactoring-justinbornais && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/15379" && unzip -o skill.zip -d .claude/skills/refactoring-justinbornais && rm skill.zip

Installs to .claude/skills/refactoring-justinbornais

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

<!-- managed-by: copilot-agent-kit --> --- name: 'refactoring' description: 'Use when removing dead code, cleaning up unused imports/variables/functions, or performing incremental codebase cleanup' ---
201 chars · catalog description✓ has a “when” trigger
Intermediate

Key capabilities

  • Detect unused imports and variables
  • Classify code by removal safety risk
  • Remove unused private functions
  • Remove commented-out code
  • Run tests after each removal step
  • Generate a cleanup report

How it works

The skill identifies dead code, classifies it by removal risk, and then incrementally removes categories of unused code, running the test suite after each step to ensure no behavior changes.

Inputs & outputs

You give it
Codebase files, test suite
You get back
Cleaned codebase, passing tests, cleanup report

When to use refactoring

  • Clean up unused imports and variables
  • Remove dead or commented-out code
  • Refactor codebase to improve maintainability
  • Safely delete unused internal functions

About this skill

<!-- managed-by: copilot-agent-kit -->

name: 'refactoring' description: 'Use when removing dead code, cleaning up unused imports/variables/functions, or performing incremental codebase cleanup'

Refactoring

Dead code detection, safety classification, and incremental cleanup.

Overview

Refactoring focuses on removing dead code and cleaning up the codebase without changing behavior. Every removal must be verified by running the test suite. Work incrementally, removing one category at a time, and confirm tests pass after each step.

Safety Classification

Before removing anything, classify it by risk level.

Safe to Remove

These can be removed with confidence after verifying tests pass:

  • Unused imports -- modules or symbols imported but never referenced
  • Unused variables -- declared but never read
  • Unused private functions -- private/unexported functions with zero callers
  • Commented-out code -- dead code preserved in comments serves no purpose in version-controlled projects

Requires Verification

These may have consumers outside the current codebase. Verify before removing:

  • Unused exports -- may be consumed by other packages, scripts, or downstream projects
  • API endpoints -- may be called by external clients not visible in the codebase
  • Configuration options -- may be used in deployment environments not represented in code

Search for references across the entire project, check documentation, and consult the team before removing.

Never Remove Without Review

These have high blast radius. Removal requires explicit human approval:

  • Public APIs -- external consumers depend on stability
  • Database migrations -- removing migration files can corrupt schema history
  • Environment variables -- may be set in CI/CD, deployment configs, or secrets managers
  • Feature flags -- may control behavior in production; coordinate with product team

Detection Commands by Language

TypeScript / JavaScript

# Unused exports, files, dependencies, and types
npx knip

# Unused dependencies only
npx depcheck

# Unused imports and variables (via linter)
npx eslint --rule 'no-unused-vars: error' --rule 'no-unused-imports: error' src/

Go

# Unused code (functions, variables, types)
staticcheck -checks U1000 ./...

# Unused dependencies
go mod tidy -v

Python

# Unused imports (F401) and unused variables (F841)
ruff check --select F401,F841 .

# Alternative with flake8
flake8 --select F401,F841 .

Rust

# Dead code warnings
cargo clippy -- -W dead_code

# Unused dependencies
cargo +nightly udeps

Incremental Removal Order

Remove dead code in this order, running tests after each step:

  1. Unused imports -- lowest risk, highest noise reduction
  2. Unused variables -- eliminates compiler/linter warnings
  3. Unused private functions -- safe because they have no external callers
  4. Unused dependencies -- reduces install size and attack surface
  5. Commented-out code -- recoverable from version control history
Step 1: Remove unused imports     -> Run tests -> Pass? Continue
Step 2: Remove unused variables   -> Run tests -> Pass? Continue
Step 3: Remove private functions  -> Run tests -> Pass? Continue
Step 4: Remove unused deps        -> Run tests -> Pass? Continue
Step 5: Remove commented code     -> Run tests -> Pass? Continue

If tests fail at any step, revert the last removal and investigate before proceeding.

Process

  1. Scan -- Run detection tools for the project language
  2. Classify -- Sort findings into the three safety categories above
  3. Plan -- List removals in incremental order
  4. Remove -- Delete one category at a time
  5. Test -- Run the full test suite after each removal
  6. Report -- Generate a cleanup report summarizing the work

Cleanup Report Format

After completing the refactoring, produce a report:

# Cleanup Report

## Summary
- **Files modified**: <count>
- **Lines removed**: <count>
- **Tests passing**: Yes / No

## Removals

### Unused Imports
| File | Import Removed |
|------|---------------|
| src/utils/helpers.ts | `import { unused } from 'lib'` |

### Unused Variables
| File | Variable |
|------|----------|
| src/service.ts | `const staleData` |

### Unused Private Functions
| File | Function |
|------|----------|
| src/calc.ts | `_legacyCompute()` |

### Unused Dependencies
| Package | Type |
|---------|------|
| left-pad | production |
| old-tool | dev |

### Commented-Out Code
| File | Lines | Description |
|------|-------|-------------|
| src/api.ts | 45-62 | Old endpoint handler |

## Verification
- [ ] All tests pass
- [ ] Linter reports no new warnings
- [ ] Build succeeds
- [ ] No regressions in functionality

Rules

  • Never skip tests -- run the full suite after every removal
  • One category at a time -- do not batch different types of removals
  • Revert on failure -- if tests break, undo the last change before investigating
  • Do not refactor logic -- this skill is for removal only; behavior changes belong in a separate task
  • Preserve public contracts -- do not remove or rename anything in the public API without approval

When not to use it

  • When refactoring logic or changing behavior
  • When removing public APIs without explicit approval
  • When modifying database migrations or environment variables

Limitations

  • Never skip tests
  • One category at a time
  • Do not refactor logic

How it compares

This skill provides a structured, test-verified, and incremental approach to dead code removal and codebase cleanup, ensuring stability and preventing regressions, unlike ad-hoc manual deletions.

Compared to similar skills

refactoring side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
refactoring (this skill)05moReviewIntermediate
effective-go3239moNo flagsBeginner
solid-principles579moNo flagsIntermediate
typescript-review392moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

effective-go

openshift

Apply Go best practices, idioms, and conventions from golang.org/doc/effective_go. Use when writing, reviewing, or refactoring Go code to ensure idiomatic, clean, and efficient implementations.

323536

solid-principles

SmidigStorm

Enforce SOLID principles (Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion) in object-oriented design. Use when writing or reviewing classes and modules.

57236

typescript-review

metabase

Review TypeScript and JavaScript code changes for compliance with Metabase coding standards, style violations, and code quality issues. Use when reviewing pull requests or diffs containing TypeScript/JavaScript code.

39178

ast-grep

ast-grep

Guide for writing ast-grep rules to perform structural code search and analysis. Use when users need to search codebases using Abstract Syntax Tree (AST) patterns, find specific code structures, or perform complex code queries that go beyond simple text search. This skill should be used when users ask to search for code patterns, find specific language constructs, or locate code with particular structural characteristics.

17135

serena

massgen

This skill provides symbol-level code understanding and navigation using Language Server Protocol (LSP). Enables IDE-like capabilities for finding symbols, tracking references, and making precise code edits at the symbol level.

1597

typescript

lobehub

TypeScript code style and optimization guidelines. Use when writing TypeScript code (.ts, .tsx, .mts files), reviewing code quality, or implementing type-safe patterns. Triggers on TypeScript development, type safety questions, or code style discussions.

2877

Search skills

Search the agent skills registry