Refactor Clean logo

Refactor Clean

Community
julianromli
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.

Overview

Publisherjulianromli
Repositoryai-skills
Skill namerefactor-clean
Stars
189
Forks
28
Bundled files
1
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by julianromli on GitHub. Read the source before you install it.

Installation

Install the Refactor Clean AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/julianromli/ai-skills.git /tmp/ai-skills
mkdir -p .claude/skills
cp -r /tmp/ai-skills/skills/refactor-clean .claude/skills/refactor-clean
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Refactor Clean in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Refactor Clean on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Refactor Clean is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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:

text
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.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Refactor Clean AI 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.

Why use Refactor Clean on TypingMind?

Because you install it once and use it with any model. Refactor Clean is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Refactor Clean in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/julianromli/ai-skills/tree/main/skills/refactor-clean. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Refactor Clean?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Refactor Clean?

As many as you like. As long as a model supports skills, you can use Refactor Clean with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Refactor Clean AI skill free?

It is published on GitHub by julianromli. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇