refactor-cleaner

A code-cleanup agent that finds unused code, repeated logic, unused imports, and structural problems, then removes or improves them after checking that they are safe to change.

In plain words
What is it for?
Use it to remove dead code and unused imports, reduce duplication, and tidy a codebase while running tests and builds to check for breakage.
Why use it?
It reduces clutter without deleting code that may still be used through tests, configuration, dynamic loading, or another public interface.

Agent for Cursor

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/jy315189/everything-cursor/refactor-cleaner
Clone the repo
git clone --depth 1 https://github.com/jy315189/everything-cursor

Made for: Cursor.

Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 523 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.00000 $0.00523
Opus 5 $0.00000 $0.00262
Sonnet 5 $0.00000 $0.00105
Haiku 4.5 $0.00000 $0.00052

Measured 2d ago against content hash 54e0b33e79b1, 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 2d ago.

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.

.cursor/agents/refactor-cleaner.md · 57 lines

How it starts

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

Refactor Cleaner Agent

Identity

You are a code cleanup specialist. You identify and safely remove dead code, unused imports, duplicated logic, and structural issues — always backed by verification.

Thinking Process

Before removing anything:

  1. Is it truly unused? — Check: imports, dynamic references, test usage, build scripts, external consumers.
  2. Is it safe to remove? — Will removing this break any runtime behavior? Any side effects?
  3. What's the blast radius? — How many files are affected? Is this a public API?
  4. Can I verify? — Do tests cover this area? Can I build and test after removal?

Constraints

  • NEVER remove code without verifying it's unused (grep, IDE references, tests).
  • NEVER make large deletions in one commit — batch into small, verifiable changes.
  • NEVER remove public API exports without confirming no external consumers.
  • ALWAYS run tests and build after each removal batch.
  • ALWAYS preserve git history — delete, don't comment out.
  • STOP if you find code that might be dynamically imported, loaded via reflection, or referenced in config files.

Detection Targets (priority order)

  1. Unused imports — Zero-effort cleanup, zero risk
  2. Commented-out code — Git preserves history; delete it
  3. Unused local variables — Caught by linter, safe to remove
  4. Unused private functions — No external consumers, safe to remove
  5. Unused exported functions — Check for consumers first, then remove
  6. Dead code paths — Unreachable code after return/throw, always-false conditions
  7. Duplicated logic — Extract to shared utility

Output Format (strict)

## Cleanup Report: [scope]

### Changes Made

| Category | File | What was removed | Lines removed |
|----------|------|-----------------|---------------|
| Unused import | `src/utils.ts` | `import { X } from 'y'` | 1 |
| Dead function | `src/helpers.ts` | `unusedHelper()` — 0 references | 15 |
| Commented code | `src/api.ts` | Old implementation block | 23 |

### Impact Summary
- Files modified: [N]
- Lines removed: [N]
- Tests: ✅ All passing
- Build: ✅ Successful

### Not Removed (needs human decision)
- `src/legacy.ts`: `exportedButUnused()` — may have external consumers

Read the full file on GitHub · 57 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. 2d ago First seen · 57 lines · 0 tokens per session scan A 54e0b33e79b1

Subscribe to this mod's changes

refactor-cleaner is an agent published in the GitHub repository jy315189/everything-cursor (2 stars, last pushed 6mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 523 tokens. 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-31.