refactor

Restructure working code by extracting, inlining, collapsing, or splitting, preserving public interfaces and tests.

Updated Apr 27, 2026
One-click install
npx skills add https://github.com/nokusukun/sublime --skill refactor-nokusukun
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/nokusukun/sublime/tree/main/refactor
Command: npx skills add https://github.com/nokusukun/sublime --skill refactor-nokusukun

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Restructure existing code for clarity — extract, inline, collapse, split — without changing behavior or names. Behavior preservation is the contract; the diff must shrink more than it grows. Use when a module has drifted into deep nesting, god components, copy-paste duplication, or layered indirection, and the shape is wrong but the logic is right.

Core Features & Use Cases

  • Preserve the public surface: exported signatures, parameter order, and interfaces remain unchanged.
  • One move per commit: perform a single structural change (e.g., extract function, inline variable, collapse conditional, split module).
  • Verify by tests: ensure tests pass and observable behavior remains identical after the refactor.
  • Use cases include tangled modules, nested conditionals, god components, and duplicated structure needing decomposition.

Quick Start

Apply a single targeted structural change to a working module to improve readability without changing external behavior.

Frequently Asked Questions about refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor code for readability without changing its behavior?

To refactor code without changing behavior, restructure the module using a single structural move per commit, such as extracting functions or collapsing conditionals, while preserving public interfaces and verifying tests pass.

When do I need to restructure a module to clarify its code structure?

You need to restructure code when a module drifts into deep nesting, conflated responsibilities, god components, or copy-paste duplication, and the shape is wrong but the underlying logic is correct.

What is the best way to untangle deeply nested handlers and duplicated logic?

The best way to untangle nested handlers and duplication is to apply targeted structural changes like splitting modules or extracting functions, keeping the diff small and ensuring observable behavior remains identical.

Does refactoring code preserve exported signatures and existing tests?

Yes, behavior-preserving refactoring strictly maintains the public surface, including exported signatures and parameter order, and relies on existing tests to verify that observable behavior remains unchanged.

Can I collapse conditionals and inline variables in a single large commit?

No, you should perform only one structural move per commit, like collapsing a conditional or inlining a variable, to keep diffs small and ensure the refactor maintains the behavior preservation contract.