refactor
БесплатноБез исполняемых скриптовНе проверенRefactor code at method, file, or project scope. Assesses first and stops when the code is already clean, routes architecture problems elsewhere, and gates…
от svyatov★ 42 звезды на GitHubОб этом скилле
Refactor
Improve code structure without changing behavior. Works at three scopes: project, file, or method. Starts by assessing whether refactoring is even warranted: if the code is already clean, say so and stop.
Refactoring vs architecture: this skill handles code-level improvements: complexity, duplication, naming, dead code, method extraction. If the assessment shows that the real problem is module boundaries, coupling between packages, or shallow modules that need deepening, say so. That is an architecture problem this skill won't fix: tell the user to run /improve-architecture in Claude linked installs or Cursor, /supermatt:improve-architecture from the Claude plugin, $improve-architecture in Codex, or /skill:improve-architecture in OMP.
Philosophy
These principles calibrate what "good enough" means and guide every step below:
- Measure the end state, not the effort. Writing 50 lines that delete 200 is a win.
- Simple over easy. Simple means one concept, not intertwined. Easy means familiar. Choose simple.
- Separate, don't combine. Good design is taking things apart: removing dependencies, not adding abstractions.
- Data over abstractions. 100 functions on one data structure beat 10 functions on 10 custom types.
- Less total code. If "better organized" means more lines, it's more entropy, not less.
- When in doubt, leave it alone. The default verdict is Clean. Don't invent work.
Read a reference only when the assessment actually turns on it:
SIMPLICITY-VS-EASY.md: when the choice is between a familiar approach and a simpler oneDATA-OVER-ABSTRACTIONS.md: when custom types could be plain data structuresDESIGN-IS-TAKING-APART.md: when a coupled system needs decomposingEXPENSIVE-TO-ADD-LATER.md: when deciding whether something missing is worth adding now
Step 1: Determine scope
Infer from the user's request:
| Trigger | Scope |
|---|---|
| "refactor this method/function" or a specific symbol name | method |
| "refactor this file" or a file path | file |
| "refactor this project/codebase" or no specific target | project |
"The changes on this branch since <ref>" is file scope over each file in git diff --name-only <ref>...HEAD, judged on the changed code. If the scope is still ambiguous, ask the user, with the three scopes as the options.
Step 2: Assess whether refactoring is warranted
This step is mandatory. Read the target code and evaluate it against the criteria below. The default verdict is Clean: only escalate when there's clear evidence.
Method scope
- Cognitive complexity: nesting depth >3, boolean expressions with >2 operators, or branch count that makes the flow hard to follow. Investigate, but a long method that reads linearly is not automatically a smell.
- Length: functions over ~50 lines warrant a look, but length alone isn't a verdict. A 70-line function with clear flow is better than 5 tiny functions that scatter the logic.
- Parameter count: >4 parameters on a public API boundary suggests grouping. Internal helpers can have more.
- Single responsibility: does it do one thing?
- Naming clarity: do names describe intent or mechanics?
File scope
All method-level checks, plus:
- Dead code (unused functions, imports, variables)
- Duplicated logic across functions in the same file
- God class or kitchen-sink module: too many unrelated responsibilities
- Cohesion: do all parts belong together?
Project scope
All file-level checks, plus:
- Circular dependencies between modules
- Duplicated logic across files/modules
- Overly deep module nesting or excessive file count for what the code does
- Total codebase size: could fewer files/functions achieve the same result?
A whole codebase always offers more findings than are worth acting on. Read HOTSPOTS.md and rank by change frequency crossed with complexity before listing anything. It decides what to look at first, not what is wrong.
Read the ranked candidates through subagents, one per area, each returning findings rather than file contents. A project-scope assessment reads far more code than it reports on, and most of it comes back Clean. Step 4 reads what it actually edits. A project under about 1,000 source lines is the exception: read it directly, a few files per call, so each output stays under the 30,000-character limit that moves a result to a file.
Planned and settled work
Before you list any finding, read each issue the target's commits reference, with its comments, through the Read an issue operation in docs/agents/issue-tracker.md. Drop a finding that a comment already settled, such as a user's answer to the same question during implement, and name that comment in the verdict.
A finding that removes an indirection (a function where a value would do, a parameter, a hook, a seam) can take out what the next planned change needs. Before you list one, also read the open children of tho
Установить refactor в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл refactor?
Refactor code at method, file, or project scope. Assesses first and stops when the code is already clean, routes architecture problems elsewhere, and gates edits on test coverage. Language-agnostic.
Как установить скилл refactor?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл refactor запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic