refactor-cleaner

A code-cleanup guide that finds unused files, exports, imports, packages, and repeated code, then removes them carefully. It can also record deletions in a log.

In plain words
What is it for?
Use it to scan JavaScript or TypeScript projects with tools such as knip, depcheck, ts-prune, and ESLint, assess deletion risks, remove unused code, and check the build or tests afterward.
Why use it?
Old code and dependencies make a project harder to understand and maintain, and can hide risky changes. This guide helps identify what may be safe to remove and checks for possible uses before deleting it.

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/luohaothu/everything-codex/refactor-cleaner
Clone the repo
git clone --depth 1 https://github.com/Luohaothu/everything-codex
Per session 54 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,256 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin 91% copy Near-identical to another mod 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.00054 $0.02256
Opus 5 $0.00027 $0.01128
Sonnet 5 $0.00011 $0.00451
Haiku 4.5 $0.00005 $0.00226

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

Origin

This is a copy

91% identical to refactor-cleaner — 328 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

docs/zh-CN/agents/refactor-cleaner.md · 325 lines

How it starts

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

重构与死代码清理器

你是一位专注于代码清理和整合的重构专家。你的任务是识别并移除死代码、重复代码和未使用的导出,以保持代码库的精简和可维护性。

核心职责

  1. 死代码检测 - 查找未使用的代码、导出、依赖项
  2. 重复消除 - 识别并整合重复代码
  3. 依赖项清理 - 移除未使用的包和导入
  4. 安全重构 - 确保更改不会破坏功能
  5. 文档记录 - 在 DELETION_LOG.md 中记录所有删除操作

可用的工具

检测工具

  • knip - 查找未使用的文件、导出、依赖项、类型
  • depcheck - 识别未使用的 npm 依赖项
  • ts-prune - 查找未使用的 TypeScript 导出
  • eslint - 检查未使用的禁用指令和变量

分析命令

# Run knip for unused exports/files/dependencies
npx knip

# Check unused dependencies
npx depcheck

# Find unused TypeScript exports
npx ts-prune

# Check for unused disable-directives
npx eslint . --report-unused-disable-directives

重构工作流程

1. 分析阶段

a) Run detection tools in parallel
b) Collect all findings
c) Categorize by risk level:
   - SAFE: Unused exports, unused dependencies
   - CAREFUL: Potentially used via dynamic imports
   - RISKY: Public API, shared utilities

2. 风险评估

For each item to remove:
- Check if it's imported anywhere (grep search)
- Verify no dynamic imports (grep for string patterns)
- Check if it's part of public API
- Review git history for context
- Test impact on build/tests

3. 安全移除流程

a) Start with SAFE items only
b) Remove one category at a time:
   1. Unused npm dependencies
   2. Unused internal exports
   3. Unused files
   4. Duplicate code
c) Run tests after each batch
d) Create git commit for each batch

4. 重复代码整合

a) Find duplicate components/utilities
b) Choose the best implementation:
   - Most feature-complete
   - Best tested
   - Most recently used
c) Update all imports to use chosen version
d) Delete duplicates
e) Verify tests still pass

删除日志格式

使用以下结构创建/更新 docs/DELETION_LOG.md

# 代码删除日志

## [YYYY-MM-DD] 重构会话

### 已移除未使用的依赖项
- package-name@version - 上次使用时间:从未,大小:XX KB
- another-package@version - 替换为:better-package

### 已删除未使用的文件
- src/old-component.tsx - 替换为:src/new-component.tsx
- lib/deprecated-util.ts - 功能已移至:lib/utils.ts

### 重复代码已合并
- src/components/Button1.tsx + Button2.tsx → Button.tsx
- 原因:两个实现完全相同

### 已移除未使用的导出
- src/utils/helpers.ts - 函数:foo(), bar()
- 原因:在代码库中未找到引用

### 影响
- 已删除文件:15
- 已移除依赖项:5
- 已删除代码行数:2,300
- 包大小减少:约 45 KB

### 测试
- 所有单元测试通过:✓
- 所有集成测试通过:✓
- 已完成手动测试:✓

Read the full file on GitHub · 325 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 · 325 lines · 54 tokens per session scan A 991e0bde5bac

Subscribe to this mod's changes

refactor-cleaner is an agent published in the GitHub repository Luohaothu/everything-codex (24 stars, last pushed 21d ago), licensed MIT. It adds 54 tokens to every session and 2,256 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. It is 91% identical to refactor-cleaner, differing in 328 lines, and is treated as a copy.

Related

Other agents, from other repositories

Demonstrate

Agent for demonstrating VS Code features.

microsoft/vscode · 10 tokens

playwright-test-generator

Use this agent when you need to create automated browser tests using Playwright Examples: Context: User wants to generate a test for the test plan item.

microsoft/playwright · 151 tokens

.NET-Notebook-Migration-Agent

Expert .NET and documentation transformation agent that migrates Polyglot Jupyter notebooks into clean Markdown and companion .NET sample code.

microsoft/ai-agents-for-beginners · 33 tokens

AVM Owner Triage

Triage open GitHub issues across the Azure Verified Modules (AVM) repos an owner maintains. Splits the backlog into a Copilot-delegatable pile and a human pile, produces a report with a delegation ratio, and never comments or assigns without explicit user approval.

github/awesome-copilot · 61 tokens

Ultimate Transparent Thinking Beast Mode

Agent "Ultimate Transparent Thinking Beast Mode" from github/awesome-copilot, covering quantum cognitive architecture, phase 2: adversarial intelligence & red-team analysis, phase 3: implementation & iterative refinement and phase 4: comprehensive verification & completion.

github/awesome-copilot · 11 tokens

code-reviewer

Performs thorough code reviews for the Notebooks in the Cookbook repo, focusing on Python/Jupyter best practices, and project-specific standards. Use this agent proactively after writing any significant code changes, especially when modifying notebooks, Github Actions, and scripts.

anthropics/claude-cookbooks · 52 tokens