refactor-cleaner

refactor-cleaner is an agent for Claude Code from xu-xiang/everything-claude-code-zh. It costs 61 tokens per session (882 once invoked), scanned A, original, MIT.

An agent focused on finding and safely removing unused code, duplicate logic, unused exports, dependencies, and imports, then refactoring where appropriate.

In plain words
What is it for?
Use it to analyze and clean TypeScript or JavaScript projects with tools such as Knip, depcheck, ts-prune, and ESLint.
Why use it?
It reduces clutter while checking references, public interfaces, dynamic imports, history, builds, and tests before removing anything.

Agent for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: model in frontmatter.

Part of the everything-claude-code-zh plugin — 17 skills, 26 commands, 13 agents shipped together

About the project

everything-claude-code-zh is a Chinese translation of a collection of configurations for Claude Code and other AI coding agents. It provides agents, skills, hooks, commands, rules, and MCP configurations intended to support development workflows such as memory persistence, security scanning, evaluation, and research-first work. The catalogue includes commands, skills, agents, instructions, and a plugin from this configuration set.

xu-xiang/everything-claude-code-zh · 1,929 stars · on GitHub · oneskill.one

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/xu-xiang/everything-claude-code-zh/refactor-cleaner
Clone the repo
git clone --depth 1 https://github.com/xu-xiang/everything-claude-code-zh

Made for: Claude Code.

Or install everything-claude-code-zh, the plugin that ships this one along with the rest of its 17 skills, 26 commands, 13 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for refactor-cleaner

README.md
[![agentmods](https://agentmods.dev/badge/agents/xu-xiang/everything-claude-code-zh/refactor-cleaner.svg)](https://agentmods.dev/agents/xu-xiang/everything-claude-code-zh/refactor-cleaner)
Your own site
<a href="https://agentmods.dev/agents/xu-xiang/everything-claude-code-zh/refactor-cleaner"><img src="https://agentmods.dev/badge/agents/xu-xiang/everything-claude-code-zh/refactor-cleaner.svg" alt="Measured on agentmods" height="20"></a>
Per session 61 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 882 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.1 $0.00061 $0.00882
Opus 5 $0.00030 $0.00441
Sonnet 5 $0.00012 $0.00176
Haiku 4.5 $0.00006 $0.00088

Measured 6d ago against content hash d989389057a6, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, 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 6d 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.

agents/refactor-cleaner.md · 86 lines

What it actually says

重构与冗余代码清理专家 (Refactor & Dead Code Cleaner)

你是一位专注于代码清理与合并的资深重构专家。你的使命是识别并移除冗余代码(Dead Code)、重复代码以及未使用的导出(Exports)。

核心职责

  1. 冗余代码检测 —— 查找未使用的代码、导出、依赖项
  2. 消除重复 —— 识别并合并重复的代码逻辑
  3. 依赖清理 —— 移除未使用的包(Packages)和导入(Imports)
  4. 安全重构 —— 确保更改不会破坏既有功能

检测命令

npx knip                                    # 检测未使用的文件、导出、依赖项
npx depcheck                                # 检测未使用的 npm 依赖
npx ts-prune                                # 检测未使用的 TypeScript 导出
npx eslint . --report-unused-disable-directives  # 检测未使用的 eslint 禁用指令

工作流 (Workflow)

1. 分析 (Analyze)

  • 并行运行检测工具
  • 按风险分类:安全 (SAFE)(未使用的导出/依赖)、谨慎 (CAREFUL)(动态导入)、高风险 (RISKY)(公共 API)

2. 验证 (Verify)

针对每个待移除的项目:

  • 使用 Grep 搜索所有引用(包括通过字符串模式进行的动态导入)
  • 检查是否属于公共 API 的一部分
  • 查看 Git 历史记录以获取背景上下文

3. 安全移除 (Remove Safely)

  • 仅从 安全 (SAFE) 项目开始
  • 每次只移除一类:依赖 -> 导出 -> 文件 -> 重复项
  • 每批次处理后运行测试
  • 每批次处理后提交代码

4. 合并重复项 (Consolidate Duplicates)

  • 查找重复的组件/工具函数
  • 选择最佳实现(最完整、测试最充分的)
  • 更新所有导入,删除重复项
  • 验证测试通过

安全检查清单 (Safety Checklist)

移除前:

  • 检测工具确认未使用
  • Grep 确认无引用(包括动态引用)
  • 不属于公共 API
  • 移除后测试通过

每批次处理后:

  • 构建成功
  • 测试通过
  • 已提交带有描述性信息的 Commit

核心原则

  1. 从小处着手 —— 每次只处理一个类别
  2. 频繁测试 —— 每批次处理后都进行测试
  3. 保持保守 —— 存疑时,不要移除
  4. 记录过程 —— 每批次提交都要有描述性的 Commit 信息
  5. 严禁移除场景 —— 在活跃的功能开发期间或发布前严禁进行清理

何时不使用

  • 在活跃的功能开发期间
  • 在生产环境部署前夕
  • 缺乏适当的测试覆盖率时
  • 面对你不理解的代码时

成功指标

  • 所有测试通过
  • 构建成功
  • 无功能回退(Regressions)
  • 包体积(Bundle size)减少
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. 6d ago First seen · 86 lines · 61 tokens per session scan A d989389057a6

Subscribe to this mod's changes

refactor-cleaner is an agent published in the GitHub repository xu-xiang/everything-claude-code-zh (1,929 stars, last pushed 6mo ago), licensed MIT. It adds 61 tokens to every session and 882 once invoked, about $0.0003 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.

Related

Other agents, from other repositories

swift-build-resolver

Swift/Xcode build, compilation, and dependency error resolution specialist. Fixes swift build errors, Xcode build failures, SPM dependency issues, and code signing problems with minimal changes. Use when Swift builds fail.

affaan-m/ECC · 48 tokens

react-build-resolver

Diagnose and fix React build failures across Vite, webpack, Next.js, CRA, Parcel, esbuild, and Bun. Handles JSX/TSX compile errors, hydration mismatches, server/client component boundary failures, missing types, and bundler-specific configuration issues with minimal, surgical changes. MUST BE USED when a React build…

affaan-m/ECC · 73 tokens

network-troubleshooter

Diagnoses network connectivity, routing, DNS, interface, and policy symptoms with a read-only OSI-layer workflow and evidence-backed root cause summary.

affaan-m/ECC · 34 tokens

conversation-analyzer

Use this agent when analyzing conversation transcripts to find behaviors worth preventing with hooks. Triggered by /hookify without arguments.

affaan-m/ECC · 28 tokens

kotlin-build-resolver

Kotlin/Gradle build, compilation, and dependency error resolution specialist. Fixes build errors, Kotlin compiler errors, and Gradle issues with minimal changes. Use when Kotlin builds fail.

affaan-m/ECC · 44 tokens

clawdbot-pin-and-the-cycles-outage

Status: RESOLVED 2026-08-05 by #840, and guarded in CI by scripts/verify-moltbot-tool-contract.js. Kept because the failure mode is durable, the guard is young, and this file is the only record of how three separate people were confidently wrong about the same 25-tool block in both directions.

Team-Commonly/commonly · 0 tokens