mcpField
R
refactor-cleaner

refactor-cleaner

github.com/carvalabDevelopment45 installs
Repository

About refactor-cleaner

refactor-cleaner is a development skill for finding and removing dead code, duplicates, and unused exports. It is intended for developers cleaning codebases, with risk-based review, reference checks, testing, and deletion documentation.

Key features

  1. 01Select detection tools by language
  2. 02Classify cleanup items by risk
  3. 03Check references and dynamic imports
  4. 04Remove in batches and run tests
  5. 05Record deletions and their impact

Use cases

  1. 01Remove unused dependencies and exports
  2. 02Find unreachable code and unused files
  3. 03Assess dynamic-reference risks before removal
  4. 04Document refactoring and verify builds

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/carvalab/k-skills --skill refactor-cleaner

After installing, type/refactor-cleanerin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
deletion-log.md
detection-tools.md
patterns.md
pr-template.md
safety-checklist.md

Details

From the project README

Refactor & Dead Code Cleaner

Identify and remove dead code, duplicates, and unused exports to keep the codebase lean and maintainable. Safety-first approach with comprehensive documentation.

Related Skills:

  • kavak-documentation - Query for Kavak-specific patterns that might look like dead code but are used dynamically
  • Use kavak-platform/platform_docs_search MCP tool to verify before removing Kavak SDK/platform code

Quick Start

Detect project type and run appropriate analysis:

Node/TypeScript:

npx knip                    # unused exports/files/deps
npx depcheck                # unused dependencies
npx ts-prune                # unused exports

Go:

go mod tidy                 # remove unused deps
deadcode ./...              # find unreachable code (golang.org/x/tools)
staticcheck ./...           # includes unused code detection

Python:

vulture .                   # find dead code
pip-autoremove              # unused dependencies

Java:

./mvnw dependency:analyze   # unused dependencies
# Use IDE or SpotBugs for dead code detection

Workflow

1. Analysis Phase

Run detection tools and categorize findings:

Risk LevelExamplesAction
SAFEUnused exports, unused depsRemove after grep verify
CAREFULDynamic imports possibleManual review required
RISKYPublic API, shared utilsDo not remove
2. Risk Assessment

For each item to remove:

  • Grep for all references (including string patterns)
  • Check for dynamic imports
  • Verify not part of public API
  • Review git history for context
3. Safe Removal Process
a) Start with SAFE items only
b) Remove one category at a time (this order matters — each step
   may reveal more dead code in the next category):
   1. Unused npm/go dependencies (safest, no code changes)
   2. Unused internal exports (removing these may make files unused)
   3. Unused files (now visible after export cleanup)
   4. Duplicate code (consolidate remaining logic)
c) Run tests after each batch
d) Commit each batch separately
4. Document Deletions

Update docs/DELETION_LOG.md after each session:

## [YYYY-MM-DD] Refactor Session

### Removed
- package-name - Reason
- src/unused-file.ts - Replaced by X

### Impact
- Files: -15, Deps: -5, Lines: -2,300

Safety Rules

Before removing ANYTHING:

  • Run detection tools
  • Grep for all references
  • Check dynamic imports
  • Run all tests
  • Create backup branch

After each removal:

  • Build succeeds
  • Tests pass
  • Commit changes
  • Update DELETION_LOG.md

When NOT to Use

  • During active feature development
  • Right before production deployment
  • Without proper test coverage
  • On code you don't understand

Error Recovery

# Immediate rollback if something breaks
git revert HEAD

# Reinstall deps and verify (by language)
# Node: npm install && npm run build && npm test
# Go:   go mod download && go build ./... && go test ./...
# Python: pip install -r requirements.txt && pytest
# Java: ./mvnw clean install

Then investigate: Was it a dynamic import/reflection? Update "DO NOT REMOVE" list.

References

ReferencePurpose
references/detection-tools.mdTool commands and usage
references/safety-checklist.mdDetailed safety procedures
references/deletion-log.mdLog format and examples
references/patterns.mdCommon dead code patterns
references/pr-template.mdPR template for cleanup

Comments

Markdown supported