MCPInstall

refactor-clean

Safely identify and remove dead code with test verification at every step. Use when Codex needs to clean unused exports, files, dependencies, helpers, wrappers, re-exports, or duplicate code without risking regressions. Trigger for dead-code cleanup, unused dependency audits, stale utility removal, cleanup refactors, or requests to reduce code safely before or alongside maintenance work.

Installs
71
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/julianromli/ai-skills --skill refactor-clean
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads refactor-clean automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

Refactor Clean

Use a conservative cleanup loop. Prefer keeping uncertain code over deleting something with hidden runtime or external consumers.

Workflow

  1. Establish a baseline.
  2. Detect dead code with language-appropriate tools.
  3. Categorize findings into SAFE, CAUTION, or DANGER.
  4. Remove one SAFE item at a time.
  5. Re-run verification after every deletion.
  6. Investigate CAUTION items before touching them.
  7. Skip DANGER items unless the user explicitly wants deeper investigation.
  8. Consolidate obvious duplicates only after dead-code cleanup is stable.

Establish A Baseline

  • Run the smallest meaningful baseline first, then the broader project checks required by the repo.
  • Record whether the suite already fails before cleanup starts.
  • Do not treat newly discovered pre-existing failures as caused by the cleanup.
  • If the baseline is red in the target area, pause and tell the user before deleting code.

Detect Dead Code

Choose tools by ecosystem. Prefer the project's package manager and existing scripts where possible.

ToolWhat it findsCommand
knipUnused exports, files, dependenciesnpx knip
depcheckUnused npm dependenciesnpx depcheck
ts-pruneUnused TypeScript exportsnpx ts-prune
vultureUnused Python codevulture src/
deadcodeUnused Go codedeadcode ./...
cargo-udepsUnused Rust dependenciescargo +nightly udeps

If specialized tooling is unavailable, fall back to targeted search:

  • Find exported symbols and files.
  • Search for imports, requires, dynamic imports, route references, config references, and string-based lookups.
  • Treat "zero obvious references" as a lead, not proof.

Categorize Findings

Assign every finding to a safety tier before editing.

TierTypical examplesDefault action
SAFEUnused internal utilities, private helpers, unused tests/helpers, wrapper functions with no callersDelete with verification
CAUTIONComponents, hooks, API routes, middleware, server actions, jobs, CLI commandsInvestigate runtime and indirect usage first
DANGERConfig files, entry points, exported types, schema files, generated boundaries, public APIsSkip unless the user asks for deeper work

Escalate to a higher-risk tier when any of these are present:

  • Dynamic import paths
  • Reflection or registry lookups
  • String-based routing or command dispatch
  • Framework auto-discovery
  • Package public exports
  • External consumers or cross-repo usage

Safe Deletion Loop

For each SAFE item:

  1. Run the baseline verification.
  2. Delete exactly one item with a surgical edit.
  3. Re-run the relevant tests immediately.
  4. If tests fail, restore the deletion and skip the item.
  5. If tests pass, continue to the next item.

Keep deletions atomic. Do not batch multiple unrelated removals into a single verification cycle.

If a revert is needed:

  • Restore only the item under test.
  • Prefer non-destructive restore methods that do not disturb unrelated user changes.
  • Note the failure in the summary and move on.

Handle Caution Items

Before deleting a CAUTION item, explicitly check for:

  • import() or require() usage
  • String references in configs, routes, registries, feature flags, and tests
  • Re-exports from package or app entry points
  • External consumers if the module is part of a published or shared surface
  • Framework conventions that auto-load files by name or location

Delete a CAUTION item only when indirect usage has been ruled out and verification still passes.

Consolidate Duplicates

After dead-code removals are green, look for low-risk consolidation:

  • Near-duplicate functions with the same behavior
  • Redundant type definitions
  • Pass-through wrappers that add no policy or ergonomics
  • Re-exports that add no discoverability or compatibility value

Keep this phase separate from dead-code deletion. If consolidation changes behavior, stop treating it as cleanup and call it out explicitly.

Reporting

End with a short cleanup report that includes:

  • Deleted functions, files, and dependencies
  • Skipped items and why
  • Approximate lines removed
  • Verification commands run
  • Final pass/fail state

Use this format when it helps:

Dead Code Cleanup
----------------------------
Deleted:   12 unused functions
           3 unused files
           5 unused dependencies
Skipped:   2 items (verification failed)
Saved:     ~450 lines removed
----------------------------
All tests passing

Rules

  • Never delete code before running a baseline verification step.
  • Remove one item at a time.
  • Skip uncertain findings instead of guessing.
  • Do not mix broad refactors into the deletion loop.
  • Preserve unrelated user changes while restoring failed deletions.
  • Be explicit about residual risk when CAUTION or DANGER items remain.

FAQ

What does the refactor-clean skill do?

Safely identify and remove dead code with test verification at every step. Use when Codex needs to clean unused exports, files, dependencies, helpers, wrappers, re-exports, or duplicate code without risking regressions. Trigger for dead-code cleanup, unused dependency audits, stale utility removal, cleanup refactors, or requests to reduce code safely before or alongside maintenance work.

How do I install refactor-clean?

Run npx skills add https://github.com/julianromli/ai-skills --skill refactor-clean in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/refactor-clean/ (personal) or .claude/skills/refactor-clean/ (project).

Which AI agents can use refactor-clean?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is refactor-clean safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains refactor-clean?

It is published by julianromli in julianromli/ai-skills. It has 71 recorded installs.

More from julianromli/ai-skills

View all →

clone-website

julianromli/ai-skills

Reverse-engineer and clone one or more websites in one shot — extracts assets, CSS, and content section-by-section and proactively dispatches parallel builder agents in worktrees as it goes. Use this whenever the user wants to clone, replicate, rebuild, reverse-engineer, or copy any website. Also triggers on phrases like "make a copy of this site", "rebuild this page", "pixel-perfect clone". Provide one or more target URLs as arguments.

Marketing & SEO2.1K installs

frontend-ui-animator

julianromli/ai-skills

Open the skill to read its SKILL.md instructions.

Frontend & Design342 installs

make-interfaces-feel-better

julianromli/ai-skills

Open the skill to read its SKILL.md instructions.

184 installs

frontend-design

julianromli/ai-skills

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML/CSS layouts, or when styling/beautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.

Frontend & Design177 installs

browser

julianromli/ai-skills

Minimal Chrome DevTools Protocol tools for browser automation and scraping. Use when you need to start Chrome, navigate pages, execute JavaScript, take screenshots, or interactively pick DOM elements.

ui-ux-pro-max

julianromli/ai-skills

UI/UX design intelligence for web and mobile. Includes 50+ styles, 161 color palettes, 57 font pairings, 161 product types, 99 UX guidelines, and 25 chart types across 10 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind, shadcn/ui, and HTML/CSS). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, and check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, and mobile app. Elements: button, modal, navbar, sidebar, card, table, form, and chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, and flat design. Topics: color systems, accessibility, animation, layout, typography, font pairing, spacing, interaction states, shadow, and gradient. Integrations: shadcn/ui MCP for component search and examples.

Frontend & Design121 installs

Popular code quality & workflow skills

View category →

grill-me

mattpocock/skills

A relentless interview to sharpen a plan or design.

Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.

handoff

mattpocock/skills

Compact the current conversation into a handoff document for another agent to pick up.

domain-modeling

mattpocock/skills

Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.

codebase-design

mattpocock/skills

Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.

diagnosing-bugs

mattpocock/skills

Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.