refactor

refactor is a command for Claude Code from sumulige/sumulige-claude. It costs 6 tokens per session (568 once invoked), scanned A, original, MIT.

A command for finding and safely cleaning up unused code, dependencies, duplicate code, and unnecessary configuration.

In plain words
What is it for?
Use `/refactor` to inspect cleanup opportunities, find dead code or unused dependencies, review duplicates, and optionally execute confirmed deletions.
Why use it?
It helps reduce clutter while highlighting changes that may be risky, such as removing code used through dynamic imports or public interfaces.

Command for Claude Code

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/sumulige/sumulige-claude/refactor
Clone the repo
git clone --depth 1 https://github.com/sumulige/sumulige-claude

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

README.md
[![agentmods](https://agentmods.dev/badge/commands/sumulige/sumulige-claude/refactor.svg)](https://agentmods.dev/commands/sumulige/sumulige-claude/refactor)
Your own site
<a href="https://agentmods.dev/commands/sumulige/sumulige-claude/refactor"><img src="https://agentmods.dev/badge/commands/sumulige/sumulige-claude/refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 6 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 568 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.00006 $0.00568
Opus 5 $0.00003 $0.00284
Sonnet 5 $0.00001 $0.00114
Haiku 4.5 $0.00001 $0.00057

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

Security

Grade A, and why

refactor 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 3d 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.

.claude/commands/refactor.md · 103 lines

What it actually says

/refactor

安全的代码重构和清理。

使用方式

/refactor              # 分析并建议清理(默认)
/refactor --dead       # 查找死代码
/refactor --deps       # 查找未使用依赖
/refactor --duplicate  # 查找重复代码
/refactor --execute    # 执行清理(需确认)

关联 Skill

此命令加载 quality-guard skill(清理模式)。


工作流程

Step 1: 运行分析工具

# 未使用的文件、导出、依赖
npx knip

# 未使用的 npm 依赖
npx depcheck

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

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

Step 2: 风险分类

风险 类型 处理
🟢 SAFE 未使用导出、测试文件 可直接删除
🟡 CAREFUL 动态导入可能使用 需验证
🔴 RISKY 公共 API、配置文件 谨慎处理

Step 3: 生成报告

# Refactor Report

## Dead Code
| File | Type | Risk | Reason |
|------|------|------|--------|

## Unused Dependencies
| Package | Size | Last Used |
|---------|------|-----------|

## Duplicate Code
| Location 1 | Location 2 | Lines |
|------------|------------|-------|

## Recommended Actions
1. [ ] Remove unused-package (SAFE)
2. [ ] Delete src/old.ts (SAFE)
3. [ ] Review src/utils.ts (CAREFUL)

## Impact
- Files to delete: X
- Dependencies to remove: Y
- Lines of code: -Z

Step 4: 执行清理(--execute)

⚠️ 执行前:
1. 创建备份分支
2. 确保测试通过
3. 逐个删除,每删一个运行测试
4. 记录到 DELETION_LOG.md

安全检查清单

删除前:

  • grep 所有引用
  • 检查动态导入
  • 查看 git 历史
  • 运行所有测试

删除后:

  • 构建成功
  • 测试通过
  • 提交变更
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. 3d ago First seen · 103 lines · 6 tokens per session scan A ce1aef1eaad4

Subscribe to this mod's changes

refactor is a command published in the GitHub repository sumulige/sumulige-claude (2 stars, last pushed 6mo ago), licensed MIT. It adds 6 tokens to every session and 568 once invoked, about $0.0000 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-31.