refactor-cleaner

refactor-cleaner is an agent for Claude Code from zhukunpenglinyutong/ai-max. It costs 52 tokens per session (2,255 once invoked), scanned A, original, MIT.

A code-maintenance workflow that finds unused code, duplicate code, unused dependencies, and exports that are no longer needed, then removes them carefully.

In plain words
What is it for?
It is for cleaning JavaScript or TypeScript projects, checking unused files and packages, consolidating duplicate code, and recording removals in a deletion log.
Why use it?
It helps reduce clutter and maintenance work while checking that cleanup does not break features or shared interfaces.

Agent for Claude Code

Written for Claude Code: a Claude Code subagent (agents/*.md). Also seen: model in frontmatter.

Good fit It is for cleaning JavaScript or TypeScript projects, checking unused files and packages, consolidating duplicate code, and recording removals in a deletion log.

Compare 6 agents from other repositories ↓
Install with agentmods
npx agentmods add agents/zhukunpenglinyutong/ai-max/refactor-cleaner
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.

Clone the repo
git clone --depth 1 https://github.com/zhukunpenglinyutong/ai-max

Made for: Claude Code.

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/zhukunpenglinyutong/ai-max/refactor-cleaner/github.svg)](https://agentmods.dev/agents/zhukunpenglinyutong/ai-max/refactor-cleaner)
Your own site
<a href="https://agentmods.dev/agents/zhukunpenglinyutong/ai-max/refactor-cleaner"><img src="https://agentmods.dev/badge/agents/zhukunpenglinyutong/ai-max/refactor-cleaner/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for refactor-cleaner

Your own site · 80×15
<a href="https://agentmods.dev/agents/zhukunpenglinyutong/ai-max/refactor-cleaner"><img src="https://agentmods.dev/badge/agents/zhukunpenglinyutong/ai-max/refactor-cleaner.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 52 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,255 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.00052 $0.02255
Opus 5 $0.00026 $0.01128
Sonnet 5 $0.00010 $0.00451
Haiku 4.5 $0.00005 $0.00226

Measured 10d ago against content hash 2973ef69cebe, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-10, 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 10d 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 · 307 lines

How it starts

The opening of the file, as written. The whole thing — 307 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 - 检查未使用的 disable-directives 和变量

分析命令

# 运行 knip 检查未使用的导出/文件/依赖
npx knip

# 检查未使用的依赖
npx depcheck

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

# 检查未使用的 disable-directives
npx eslint . --report-unused-disable-directives

重构工作流

1. 分析阶段

a) 并行运行检测工具
b) 收集所有发现
c) 按风险级别分类:
   - 安全:未使用的导出、未使用的依赖
   - 谨慎:可能通过动态导入使用
   - 风险:公共 API、共享工具

2. 风险评估

对于每个要移除的项:
- 检查是否被导入(grep 搜索)
- 验证没有动态导入(grep 字符串模式)
- 检查是否是公共 API 的一部分
- 查看 git 历史了解上下文
- 测试对构建/测试的影响

3. 安全移除流程

a) 只从安全项开始
b) 每次移除一个类别:
   1. 未使用的 npm 依赖
   2. 未使用的内部导出
   3. 未使用的文件
   4. 重复代码
c) 每批后运行测试
d) 每批创建 git commit

4. 重复整合

a) 查找重复的组件/工具
b) 选择最佳实现:
   - 功能最完整
   - 测试最好
   - 最近使用
c) 更新所有导入使用选定版本
d) 删除重复
e) 验证测试仍然通过

删除日志格式

创建/更新 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

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

安全检查清单

移除任何内容之前:

  • 运行检测工具
  • Grep 所有引用
  • 检查动态导入
  • 查看 git 历史
  • 检查是否是公共 API 的一部分
  • 运行所有测试
  • 创建备份分支
  • 在 DELETION_LOG.md 中记录

每次移除后:

  • 构建成功
  • 测试通过
  • 无控制台错误
  • 提交更改
  • 更新 DELETION_LOG.md

要移除的常见模式

1. 未使用的导入

// ❌ 移除未使用的导入
import { useState, useEffect, useMemo } from 'react' // 只使用了 useState

// ✅ 只保留使用的
import { useState } from 'react'

Read the full file on GitHub · 307 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. 10d ago First seen · 307 lines · 52 tokens per session scan A 2973ef69cebe

Subscribe to this mod's changes

refactor-cleaner is an agent published in the GitHub repository zhukunpenglinyutong/ai-max (335 stars, last pushed 7mo ago), licensed MIT. It adds 52 tokens to every session and 2,255 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.