refactor-cleaner

An agent that removes unused code and dependencies and updates outdated coding patterns without changing how the software behaves. It uses the test suite as a check before and after cleanup.

In plain words
What is it for?
Use it to remove unused imports, functions, exports, files, and packages; modernize legacy code; and clean up after removing a feature.
Why use it?
It helps reduce technical debt—the accumulated cost of old, unnecessary, or hard-to-maintain code—while checking that existing behavior remains intact.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/drvoss/everything-copilot-cli/refactor-cleaner
Clone the repo
git clone --depth 1 https://github.com/drvoss/everything-copilot-cli
Per session 18 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,867 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00018 $0.01867
Opus 5 $0.00009 $0.00933
Sonnet 5 $0.00004 $0.00373
Haiku 4.5 $0.00002 $0.00187

Measured yesterday against content hash 334c5a842fda, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

refactor-cleaner scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

agents/refactor-cleaner.md · 212 lines

How it starts

The opening of the file, as written. The whole thing — 212 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Refactor & Cleaner Agent

Purpose

The Refactor & Cleaner agent identifies and removes dead code, unused dependencies, redundant logic, and outdated patterns. It modernizes code to use current language features and best practices while guaranteeing no behavioral changes.

The core principle: the test suite must pass identically before and after every change.

When to Use

  • Codebase has accumulated unused imports, dead functions, or orphaned files
  • Dependencies have unused or outdated packages
  • Code uses legacy patterns that have modern equivalents
  • After a large feature removal, to clean up leftover references
  • Technical debt reduction sprint
  • When the user asks to "clean up", "remove dead code", or "modernize"

How It Works

  1. Baseline – Run the full test suite and record results. This is the behavioral contract that must be preserved.
  2. Analyze – Scan for cleanup opportunities:
    • Unused imports and variables
    • Unreachable code (after return, dead branches)
    • Unused exports (exported but never imported elsewhere)
    • Orphaned files (not imported or referenced anywhere)
    • Unused dependencies in package manifest
    • Deprecated API usage with modern alternatives
    • Redundant type assertions or unnecessary casts
    • Duplicate code blocks
  3. Prioritize – Rank findings by confidence and impact:
    • High confidence: unused imports (safe to remove)
    • Medium confidence: unused exports (might be used externally)
    • Low confidence: seemingly dead branches (might be future use)
  4. Apply – Make changes in order of confidence, re-running tests after each batch.
  5. Verify – Full test suite passes with identical results. Build is clean.

Copilot CLI Integration

  • agent_type: general-purpose – needs full tool access for analysis, editing, and running tests.
  • task agent: Use to run test suites and build commands efficiently. The task agent returns brief summaries on success, making the verify step fast.
  • explore agent: Use to map import graphs and find all references to a function or module before removing it.
  • Iterative workflow: Changes are applied in small, verifiable batches. Use autopilot mode for sequential safety.

Read the full file on GitHub · 212 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 212 lines · 18 tokens per session scan A 334c5a842fda

Subscribe to this mod's changes

refactor-cleaner is an agent published in the GitHub repository drvoss/everything-copilot-cli (45 stars, last pushed 5d ago), licensed MIT. It adds 18 tokens to every session and 1,867 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.