From zenflow
Structured refactoring pipeline — analyze target code, propose changes with before/after examples, plan, execute with regression coverage. Use when improving existing code without changing behavior.
How this skill is triggered — by the user, by Claude, or both
Slash command
/zenflow:refactorThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Structured approach to improving existing code without changing behavior. Analyzes the target, proposes the refactor with concrete before/after examples, creates a plan with regression test coverage, then executes.
Structured approach to improving existing code without changing behavior. Analyzes the target, proposes the refactor with concrete before/after examples, creates a plan with regression test coverage, then executes.
Announce at start: "I'm using the zenflow:refactor skill to improve this code."
Refactoring MUST NOT change **external** behavior — observable outputs, public API contracts consumed by code outside this repository.Internal API changes are allowed if all callers are updated in the same scope. Examples:
If external consumers exist (npm package, REST API, CLI flags), signature changes are NOT a refactor — use zenflow:idea instead.
Determine what to refactor. The user may specify:
If vague ("refactor the auth module"), explore the code first:
For the identified target:
Present the refactor proposal to the user with:
Before/After examples — concrete code showing the transformation:
### Change 1: Extract shared validation logic
**Before** (duplicated in 3 files):
{code snippet from file A}
{code snippet from file B}
**After** (shared helper):
{proposed helper function}
{updated call site}
**Files affected:** fileA.ts, fileB.ts, fileC.ts, new: shared/validation.ts
Impact assessment:
Risk areas:
Ask: "Does this refactor plan look right? Any changes?"
Before making any changes:
This is non-negotiable. Refactoring without tests is just rearranging.
Two options based on scope:
Small refactor (1-3 files): Execute directly in this session.
Large refactor (4+ files): Invoke zenflow:plan to create a detailed plan, then zenflow:dispatch to execute.
After refactoring is complete:
When: Same logic in 2+ places, or a function does too many things. How: Pull the shared/excess logic into a named function. Update all call sites.
When: A function just wraps another call with no added value. How: Replace call sites with the direct call. Delete the wrapper.
When: Name doesn't match what the thing does. How: Rename with LSP (find all references), update tests, update docs.
When: A file has grown beyond one clear responsibility. How: Identify responsibility boundaries, create new files, move code, update imports.
When: Complex switch/if-else blocks that grow with each new case. How: Extract to discriminated union or strategy pattern.
When: Function has 3+ positional parameters (per project conventions). How: Replace with single options object, update all call sites.
Stop and reassess if:
Never:
npx claudepluginhub brewpirate/zen-flow --plugin zenflowRefactors code to improve structure, readability, and maintainability while preserving behavior. Guides test-driven cycle, checklists, and patterns like extract function.
Refactors code while preserving behavior: cleanup, modularize, deduplicate, rename, simplify structure in small reversible steps. Not for behavioral changes.
Safely refactors code with test coverage: writes tests first if absent, plans changes, applies small testable steps, verifies tests/lint/typecheck pass without behavior changes.