refactor-code

Refactors existing code to remove duplication and complexity while preserving observable behavior.

1|Updated Jul 3, 2026
One-click install
npx skills add https://github.com/nejcm/agents --skill refactor-code-nejcm
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: refactor-code
Source: https://github.com/nejcm/agents/tree/main/skills/refactor-code
Command: npx skills add https://github.com/nejcm/agents --skill refactor-code-nejcm

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Cleaning up duplicated, deeply nested, or overly complex code is risky because even small edits can silently change behavior. This Skill enforces a disciplined, audit-first refactoring workflow that restructures code without altering its public API, outputs, error handling, or side effects. ## Core Features & Use Cases - Audit-before-edit workflow: Produces a structured refactoring audit with exact duplicate locations, risk analysis, and verification plans before any code is changed. - Behavior-preserving transformations: Consolidates duplicated logic, applies guard clauses, and extracts narrowly scoped helpers while preserving validation order, error paths, and async semantics. - Incremental verification: Runs the repository's existing tests, linters, and type checks after each change block and reports residual risk at handoff. - Use Case: You notice the same validation logic copied across three API handlers. The Skill audits all occurrences, confirms their contracts are identical, extracts a shared helper, and proves equivalence with the existing test suite. ## Quick Start Ask the assistant to refactor the duplicated logic in a specific file or module while keeping its behavior and public API unchanged.

Frequently Asked Questions about refactor-code

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

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

Start by auditing the target code to map its behavior contract, then run existing tests as a baseline before editing. Apply one cohesive change at a time, re-running focused tests after each block to catch regressions immediately.

How to remove duplicate code across multiple files safely?▼

First confirm the duplicates share the same inputs, invariants, error handling, and lifecycle, not just similar appearance. Then extract a narrowly scoped helper with a domain-meaningful name and verify equivalence with the repository's existing tests.

When should I use refactoring versus a code review?▼

Use refactoring when you want the code actually edited to remove duplication or complexity. Use a code review skill when you only want problems identified and reported without modifying any files.

What happens if there are no tests before refactoring?▼

The Skill runs the narrowest relevant existing checks first and records the results. If coverage is weak, it may add a focused characterization test, keep the refactor smaller, or stop and report the limitation rather than risk unverified changes.

Can refactoring change a public API or function signature?▼

No, this Skill preserves types, exports, schemas, and public names by default. An API change is only made when the request explicitly permits it.