refactor-clean

refactor-clean is a command for coding agents from xu-xiang/everything-claude-code-zh. It costs 16 tokens per session (708 once invoked), scanned A, original, MIT.

A command for finding unused code and combining duplicated code in a project. Dead code is code that is no longer used, while duplicated code repeats the same logic in multiple places.

In plain words
What is it for?
Use it to inspect unused exports, dependencies, imports, functions, files, CSS classes, and repeated patterns, then verify the result with builds, tests, linting, and smoke checks.
Why use it?
It helps reduce unnecessary code and repeated logic while checking that cleanup does not break the project.

Command

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

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

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-clean

README.md
[![agentmods](https://agentmods.dev/badge/commands/xu-xiang/everything-claude-code-zh/refactor-clean.svg)](https://agentmods.dev/commands/xu-xiang/everything-claude-code-zh/refactor-clean)
Your own site
<a href="https://agentmods.dev/commands/xu-xiang/everything-claude-code-zh/refactor-clean"><img src="https://agentmods.dev/badge/commands/xu-xiang/everything-claude-code-zh/refactor-clean.svg" alt="Measured on agentmods" height="20"></a>
Per session 16 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 708 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.00016 $0.00708
Opus 5 $0.00008 $0.00354
Sonnet 5 $0.00003 $0.00142
Haiku 4.5 $0.00002 $0.00071

Measured 5d ago against content hash 53a6a16dde2e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

refactor-clean 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 5d 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.

.opencode/commands/refactor-clean.md · 103 lines

What it actually says

重构清理 (Refactor Clean) 命令

分析并清理代码库:$ARGUMENTS

你的任务 (Your Task)

  1. 使用分析工具检测死代码 (Dead code)
  2. 识别重复项与合并机会
  3. 安全删除未使用的代码并记录文档
  4. 验证没有功能被破坏

检测阶段 (Detection Phase)

运行分析工具

# 查找未使用的导出 (exports)
npx knip

# 查找未使用的依赖项 (dependencies)
npx depcheck

# 查找未使用的 TypeScript 导出
npx ts-prune

手动检查

  • 未使用的函数(无调用方)
  • 未使用的变量
  • 未使用的导入 (imports)
  • 被注释掉的代码
  • 不可达代码 (Unreachable code)
  • 未使用的 CSS 类

删除阶段 (Removal Phase)

删除前准备

  1. 搜索用法 - 使用 grep、查找引用 (find references)
  2. 检查导出 - 可能被外部使用
  3. 验证测试 - 确保没有测试依赖它
  4. 记录删除 - git 提交信息 (commit message)

安全删除顺序

  1. 首先删除未使用的导入 (imports)
  2. 删除未使用的私有函数
  3. 删除未使用的导出函数
  4. 删除未使用的类型/接口 (types/interfaces)
  5. 删除未使用的文件

合并阶段 (Consolidation Phase)

识别重复项

  • 具有细微差异的相似函数
  • 复制粘贴的代码块
  • 重复的模式 (patterns)

合并策略

  1. 提取工具函数 (Utility function) - 针对重复逻辑
  2. 创建基类 (Base class) - 针对相似的类
  3. 使用高阶函数 (Higher-order functions) - 针对重复模式
  4. 创建共享常量 - 针对魔术值 (magic values)

验证 (Verification)

清理完成后:

  1. npm run build - 成功构建
  2. npm test - 所有测试通过
  3. npm run lint - 无新增 lint 错误
  4. 手动冒烟测试 (Smoke test) - 功能正常运行

报告格式 (Report Format)

死代码分析报告 (Dead Code Analysis)
==================

已删除:
- file.ts: functionName (未使用的导出)
- utils.ts: helperFunction (无调用方)

已合并:
- formatDate() 和 formatDateTime() → dateUtils.format()

剩余项(需手动审查):
- oldComponent.tsx: 可能未使用,需向团队确认

注意 (CAUTION):删除前务必验证。如有疑问,请询问或添加 // TODO: verify usage 注释。

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. 5d ago First seen · 103 lines · 16 tokens per session scan A 53a6a16dde2e

Subscribe to this mod's changes

refactor-clean is a command published in the GitHub repository xu-xiang/everything-claude-code-zh (1,929 stars, last pushed 6mo ago), licensed MIT. It adds 16 tokens to every session and 708 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.