Command Palette

Search for a command to run...

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

refactoring

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

WHEN you need a plan to refactor, restructure, or clean up working code and the test result is known, either green or a recorded failing set; NOT for new…

mintuzот mintuz★ 38 звёзд на GitHub

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

Refactoring

Refactoring is the third step of TDD: after GREEN, assess whether refactoring adds value. A refactor improves the structure of working code; it never changes observable behaviour.

When to Refactor

  • Assess after every GREEN: once per behaviour, not once after a batch
  • Refactor only if it improves the code; if the code is already clean, move on
  • Establish a reversible baseline with a known test result before refactoring (principle-capture-the-baseline)
  • Pin the behaviour the refactor must preserve with a passing test first
  • Refactor only code that green tests already cover; characterize anything else first or leave it alone, however trivial it looks
  • Refactor in small reversible steps; never refactor code you cannot restore
  • Keep external APIs unchanged and keep every test result unchanged

Reversible Baseline

A baseline is a state you can return to, so a broken slice costs one restore instead of a debugging session. A commit is one way to record it, not a requirement; refactoring uncommitted code is safe when the baseline is recorded another way.

Stay inside the user's authorised boundary:

  • Commit the baseline only when the user asked for a baseline commit and the owned changes are the only changes present. A separate commit also keeps git history readable.
  • Inside a TDD cycle where the user allows commits and the owned changes are the only changes present, commit the green code as the baseline; that permission is the explicit request this skill requires.
  • A request for one commit is a request for the refactor commit. Add no extra checkpoint commit for it.
  • Otherwise, record enough to restore the owned paths: their current content or diff, or a clean-tree restore point that already holds that content. Also record the test commands you ran and their results. A list of path names alone restores nothing. Preserve unrelated worktree changes (principle-preserve-unrelated-work).
  • Do not commit, stage, stash, or reset without an explicit request (principle-update-the-base-deliberately).
  • If the suite is not fully green, record the exact set of failing tests in the baseline; that set must be unchanged after the refactor. Restore green first when you can, as a separate change, never inside the refactor.

Workflow:

  1. GREEN: The suite passes, or the failing set is known and reproducible
  2. BASELINE: Save the authorised reversible state and that test result
  3. CHARACTERIZE: Pin any unpinned behaviour the refactor must preserve
  4. REFACTOR: Apply one structural slice
  5. VERIFY: Run the named characterization and focused behaviour tests, then the relevant regression suite; on failure, restore only that slice (principle-sequence-verifiable-units). When the slice moves or renames files, also check each tool the project uses that finds code by path, for example workspace globs, tsconfig paths, test and lint globs, build contexts and route discovery. A stale path in these tools is part of the move: update it in the same slice. Confirm that the same tests, lint inputs and build inputs are still found: a glob that stops matching drops them, and the suite stays green.
  6. COMMIT: Save the refactor separately when requested

Characterization Tests

A green suite proves only the behaviours it asserts, not that code is safe to move. Characterize before you move code, and only what matters:

  1. Trace the call path the change touches. List what each caller can observe across the boundary you are about to move.
  2. Keep the entries a caller relies on or the task states as required. Discard incidental details no caller can observe; pinning those freezes an implementation instead of a contract (principle-test-behavior-not-implementation). Common entries that do cross the boundary: public signatures, error type, error object identity, ordering, cleanup timing, retry count and delay, and fan-out to multiple waiters.
  3. For each kept entry no test asserts, write a test asserting the current observable behaviour: run the code and record the output it actually produces today. Never change production code to satisfy that first expectation.
  4. Run those tests against the unchanged implementation. They must pass before you move any code.

A failing characterization test means you do not yet understand the current behaviour: stop and investigate before refactoring.

Characterization tests are not speculative work; they record existing behaviour callers already depend on.

When a required behaviour cannot be characterized, stop before the refactor and report which behaviour you could not pin. Leave uncharacterized code alone, whether or not it looks trivial.

Priority Classification

Priority Action Examples
Critical Fix now Mutations, knowledge duplication, >3 levels nesting
High This session Magic numbers, unclear names, >30 line functions
Полный SKILL.md на GitHub

Установить refactoring в Claude Code и Claude Desktop

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

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

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

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

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

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

FAQ

Что делает скилл refactoring?

WHEN you need a plan to refactor, restructure, or clean up working code and the test result is known, either green or a recorded failing set; NOT for new feature delivery or any behavior change; reversible-baseline safety with prioritized improvements.

Как установить скилл refactoring?

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

Скилл refactoring запускает скрипты?

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

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

Сравнить refactoring с