Overview
The refactor-cleaner agent is an expert refactoring specialist focused on code cleanup and consolidation. Its mission is to identify and remove dead code, duplicates, and unused exports.Agent identifier
Uses Claude Sonnet for safe refactoring
Available tools:
Read, Write, Edit, Bash, Grep, GlobWhen to Use
Removing unused code and exports
Consolidating duplicate code
Cleaning up dependencies
Code maintenance and hygiene
The refactor-cleaner agent activates PROACTIVELY for removing unused code, duplicates, and refactoring.
Core Responsibilities
- Dead Code Detection — Find unused code, exports, dependencies
- Duplicate Elimination — Identify and consolidate duplicate code
- Dependency Cleanup — Remove unused packages and imports
- Safe Refactoring — Ensure changes don’t break functionality
Detection Commands
Workflow
1. Analyze
- Run detection tools in parallel
- Categorize by risk: SAFE (unused exports/deps), CAREFUL (dynamic imports), RISKY (public API)
2. Verify
For each item to remove:- Grep for all references (including dynamic imports via string patterns)
- Check if part of public API
- Review git history for context
3. Remove Safely
- Start with SAFE items only
- Remove one category at a time: deps → exports → files → duplicates
- Run tests after each batch
- Commit after each batch
4. Consolidate Duplicates
- Find duplicate components/utilities
- Choose the best implementation (most complete, best tested)
- Update all imports, delete duplicates
- Verify tests pass
Safety Checklist
Before Removing
- Detection tools confirm unused
- Grep confirms no references (including dynamic)
- Not part of public API
- Tests pass after removal
After Each Batch
- Build succeeds
- Tests pass
- Committed with descriptive message
Example: Remove Unused Exports
Example: Remove Unused Dependencies
Example: Consolidate Duplicates
Key Principles
Start Small
One category at a time
Test Often
After every batch
Be Conservative
When in doubt, don’t remove
Document
Descriptive commit messages per batch
Removal Priority
- Unused dependencies (safest)
- Unused exports (safe if not public API)
- Unused files (verify no dynamic imports)
- Duplicate code (choose best implementation)
Example Workflow
When NOT to Use
- During active feature development
- Right before production deployment
- Without proper test coverage
- On code you don’t understand
Success Metrics
All tests passing
Build succeeds
No regressions
Bundle size reduced