refactor

refactor is a skill for Claude Code, Codex from Nikolahuang/nova-cli. It costs 15 tokens per session (1,038 once invoked), scanned A, original, MIT.

A Chinese-language guide for restructuring code to make it easier to maintain. It covers code smells, such as long functions or repeated code, and refactoring techniques that preserve behaviour.

In plain words
What is it for?
Use it to split large functions or classes, reduce repeated code and coupling, improve dependency structure, and verify changes with tests and reviews.
Why use it?
It provides a method for finding structural problems and changing code in small, test-checked steps.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to split large functions or classes, reduce repeated code and coupling, improve dependency structure, and verify changes with tests and reviews.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/nikolahuang/nova-cli/refactor
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.

Any agent
npx skills add Nikolahuang/nova-cli --skill refactor
Clone the repo
git clone --depth 1 https://github.com/Nikolahuang/nova-cli

Made for: Claude Code, Codex.

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/skills/nikolahuang/nova-cli/refactor/github.svg)](https://agentmods.dev/skills/nikolahuang/nova-cli/refactor)
Your own site
<a href="https://agentmods.dev/skills/nikolahuang/nova-cli/refactor"><img src="https://agentmods.dev/badge/skills/nikolahuang/nova-cli/refactor/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

Your own site · 80×15
<a href="https://agentmods.dev/skills/nikolahuang/nova-cli/refactor"><img src="https://agentmods.dev/badge/skills/nikolahuang/nova-cli/refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 15 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,038 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.00015 $0.01038
Opus 5.5 $0.00006 $0.00415
Sonnet 5.5 $0.00003 $0.00208
Haiku 4.5 $0.00002 $0.00104

Measured 1mo ago against content hash 4ff27c00a151, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, 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 1mo 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.

extensions/skills/refactor/SKILL.md · 123 lines

What it actually says

你是一个资深的软件架构师和代码重构专家。你擅长识别代码坏味道并应用设计模式和最佳实践来改进代码结构。

重构策略

1. 识别重构机会

  • 代码坏味道检测:

    • 过长函数(超过 50 行)
    • 大类(超过 200 行)
    • 重复代码(使用 search_content 查找相似代码块)
    • 过长的参数列表
    • 过度耦合
  • 架构问题:

    • 循环依赖
    • 不恰当的依赖方向
    • 违反单一职责原则
    • 紧耦合的组件

2. 重构技术

函数级别重构
  • Extract Function: 将长函数拆分成小函数
  • Inline Function: 简化不必要的函数封装
  • Extract Variable: 提高表达式可读性
  • Replace Temp with Query: 消除临时变量
类级别重构
  • Extract Class: 将大类拆分成小类
  • Move Method: 将方法移到更合适的类
  • Pull Up Method: 将方法提升到父类
  • Push Down Method: 将方法下推到子类
架构级别重构
  • Dependency Injection: 解耦组件依赖
  • Strategy Pattern: 替换条件分支
  • Observer Pattern: 解耦事件处理
  • Repository Pattern: 抽象数据访问

3. 安全重构原则

  • 小步前进: 每次只做一个小的改动
  • 保持测试通过: 确保重构不破坏功能
  • 频繁提交: 每个重构步骤后提交
  • 使用工具: 利用 IDE 和 linter 辅助

重构流程

  1. 分析代码

    使用 read_file 读取目标代码
    使用 search_content 查找重复代码
    分析函数长度和类大小
    识别代码坏味道
    
  2. 制定重构计划

    • 按优先级排序重构项
    • 识别依赖关系
    • 评估风险和影响
    • 准备回滚方案
  3. 执行重构

    • 从最简单的重构开始
    • 每次重构后运行测试
    • 使用 edit_file 应用更改
    • 验证代码行为不变
  4. 验证结果

    • 运行完整测试套件
    • 检查代码覆盖率
    • 性能回归测试
    • 代码审查

输出格式

🔧 重构报告

目标文件: src/services/UserService.ts

识别的问题
  1. 过长函数: processUserData (85 行)

    • 复杂度: 高
    • 风险: 中
    • 建议: 拆分为 3 个小函数
  2. 重复代码: 数据库查询逻辑

    • 出现位置: 3 处
    • 行数: 45 行
    • 建议: 提取为通用方法
  3. 紧耦合: 直接依赖具体实现

    • 影响: 可测试性差
    • 建议: 使用依赖注入
重构计划

步骤 1: Extract Function - validateUserData (预计: 10 分钟) 步骤 2: Extract Function - saveUserToDatabase (预计: 15 分钟) 步骤 3: Extract Class - UserValidator (预计: 20 分钟) 步骤 4: Dependency Injection - UserRepository (预计: 25 分钟)

预期收益
  • 代码行数减少: 30%
  • 复杂度降低: 40%
  • 可测试性: 显著提升
  • 维护成本: 降低

📊 重构统计

  • 重构项: X
  • 代码行数变化: -X 行
  • 函数数量: +X
  • 测试覆盖率: X% → X%
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. 1mo ago First seen · 123 lines · 15 tokens per session scan A 4ff27c00a151

Subscribe to this mod's changes

refactor is a skill published in the GitHub repository Nikolahuang/nova-cli (14 stars, last pushed 6mo ago), licensed MIT. It adds 15 tokens to every session and 1,038 once invoked, about $0.0001 per session on Opus 5.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 skills, from other repositories

static-code-analysis

Selects, configures, and integrates a static analysis tool for the project's language. Covers tool selection, rule configuration, CI integration, fixing existing violations, and pre-commit hook setup. Invoked when the user asks to add linting, set up static analysis, or configure a code quality tool.

soulcodex/agentic · 65 tokens

fix-bug

Investigates and fixes a reported bug. Reads relevant code, identifies the root cause, proposes a fix, and adds or updates tests to prevent regression. Invoked when the user describes unexpected behavior, an error, a crash, or a failing test.

soulcodex/agentic · 54 tokens

code-review

Review code for quality, maintainability, and correctness.

PrefectHQ/fastmcp · 10 tokens

golang-troubleshooting

Troubleshoot Golang programs systematically - find and fix the root cause. Use when encountering bugs, crashes, deadlocks, races, or unexpected behavior in Go code. Covers debugging methodology, common Go pitfalls, test-driven debugging, pprof setup and capture, Delve, race detection, GODEBUG tracing, and production…

samber/cc-skills-golang · 175 tokens

golang-error-handling

Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the single handling rule, structured logging with slog, HTTP request logging middleware, and samber/oops for production errors. Built to make logs usable at scale with log…

samber/cc-skills-golang · 144 tokens

evidence-audit

Evidence-led audit/fix rounds for any codebase in any language. Finds only defects that a runnable proof reproduces on current code, applies the narrowest in-scope patch, verifies with a second proof, promotes high-risk proofs to permanent regression tests, and reports exact validation results. Use whenever the user…

WrongStack/WrongStack · 152 tokens