Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

code-refactor

БесплатноБез исполняемых скриптовНе проверен

Refactor, rewrite, port, migrate, or modernize existing source code - read this skill FIRST, before searching files or planning, even if the named files are…

linkxzhouот linkxzhou324 установки в других каталогах

Об этом скилле

Code Refactor · Rewrite · Port

Change the shape or the language of code while keeping what it does. The promise: every caller, test, and observable output behaves as before unless the user approved a difference. To keep it, pin behavior down before editing, move in green steps, and report evidence rather than confidence.

Local cleanup of one function or snippet belongs to simplify-code. If the request is that small, say so and hand it over.

Read first (hard rules)

Read this SKILL.md top to bottom before anything else, even when the workspace is empty or the files the user names are missing. A missing file is not a reason to skip the skill: pick the mode, say what is missing, and deliver what the mode allows (a plan, a contract, or a port of the code the user pasted).

  1. Stay in the workspace. Read and write only inside the given working directory. Never search the disk for other projects, and never read, reuse, or write sibling/parent project folders or earlier runs' outputs, even if they look like a head start.
  2. No installs. Do not brew install, apt, pip install toolchains, add rustup components, or download compilers/SDKs without the user's approval. If a toolchain is missing, write "Not run: unavailable ()", verify what you can with the tools present, and still deliver the code.
  3. Finish, don't hand off. Do not end with "state saved to RESUME.md" / "say the word and I'll continue" while work can still proceed. Stop early only for a Gate, a denial, or the budget below, and then deliver the full report for what exists.
  4. Plan-only means no files. If the user asks for a plan, review, or assessment, edit and create nothing; put the plan in the reply (write a file only if asked).
  5. Denied means stop. If a command or deletion is denied, do not get the same effect another way; list it in the report.

Budget (time and steps)

Runs are time-limited; a correct port with no report counts as a failure.

  • Smallest verifiable slice first: get the contract, one end-to-end path, and the given fixtures/compare script green before anything else.
  • Checkpoint: report before hardening. The moment the given fixtures/compare script first pass, write the Output-format report to PORTING.md (or the plan) with the current N/M result before running any generated/differential inputs. Every later milestone only updates it.
  • Stay in the input domain. Differential mismatches on inputs the fixtures and contract do not cover (wrong types such as bools or mixed int/float, huge magnitudes, float summation order, exotic Unicode) go under Follow-ups as "outside contract"; do not fix them unless the user asked for full-domain parity.
  • Cap exploration: at most one modest differential/fuzz run (hundreds to a few thousand inputs) and at most 3 fix-and-rerun rounds per mismatch class. Do not re-derive language runtime internals, hand-build Unicode tables, or chase cases outside the given fixtures and contract; list them under Follow-ups.
  • Milestones: (1) mode + contract, (2) baseline/fixtures captured, (3) first green slice, (4) full fixtures green + report written, (5) optional extra hardening. If you have used roughly two thirds of your steps or time, stop hardening and deliver the final report.

Pick the mode

Signal in the request Mode
Same language, structure is the problem (god module, tangled imports, wrong boundaries, widely used API needs a new shape) refactor: existing code survives and moves in mechanical steps
Same language, existing code not worth evolving (unreadable legacy, dead framework, "rewrite / from scratch") rewrite: the old implementation becomes the oracle
Target language differs port: numbers, strings, errors, ordering, and concurrency semantics shift, so prove parity

Rules of thumb:

  • Prefer refactor over rewrite whenever an incremental path exists, because rewrites discard encoded edge-case knowledge. Choose a rewrite only when the user asks for one or it is clearly cheaper, and say why.
  • Framework migrations (Express→Fastify, Vue→React, callbacks→async across a codebase) are rewrite when components are re-implemented, refactor when the change can be done as a mechanical, staged transformation.
  • Port + redesign ("port to Go and clean it up") is two projects: port first, then refactor as a separate later step.

State the chosen mode in one line before starting, with the reason.

Safety gates (all modes)

The workflows below enforce seven gates:

  1. contract first;
  2. a green safety net before edits (characterization tests where coverage is thin, references/safety-net.md);
  3. a plan with sign-off when the blast radius is large;
  4. structure and behavior never share a step (bugs go under "Found, not fixed");
  5. small, revertible green steps (revert and go smaller when red);
  6. the same proof re-run at the end (N inputs / M differences for rewrite/po
Полный SKILL.md на ClawHub

Установить code-refactor в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл code-refactor?

Refactor, rewrite, port, migrate, or modernize existing source code - read this skill FIRST, before searching files or planning, even if the named files are not in the workspace. Covers refactor (split a god module into a package, untangle circular imports, move modules, change a signature across callers, swap an internal API or library across a codebase step by step), rewrite (re-implement a component from scratch or on a new framework, e.g. JS to TS + NestJS), and port / translate code to another language (Python to Go or Rust, pyo3 extensions, TS to Go, Java to Kotlin, C to Rust behind an unchanged C header) with fixture parity. Triggers - refactor, restructure, split modules, rewrite, reimplement, port, convert to another language, migrate to a framework, modernize, 重构, 拆分模块, 重写, 代码迁移, 移植到 Rust, 把 Python 改成 Go. Not for tidying one function (simplify-code), type hints, bug fixes, features, perf, database/schema/cloud/infra migrations (e.g. Postgres RDS to Cloud SQL), dependency bumps, or prose translation.

Как установить скилл code-refactor?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл code-refactor запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить code-refactor с