refactor

Restructures existing code to improve maintainability without changing external behavior.

Updated Aug 28, 2026
One-click install
npx skills add https://github.com/miyake-san/sogo-agent-platform --skill refactor-miyake-san
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/miyake-san/sogo-agent-platform/tree/main/skills/core/refactor
Command: npx skills add https://github.com/miyake-san/sogo-agent-platform --skill refactor-miyake-san

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Codebases accumulate technical debt: long functions, duplicated logic, magic numbers, and god classes that make features hard to add and bugs easy to introduce. This Skill provides a systematic, test-safe approach to cleaning up code incrementally without breaking existing behavior. ## Core Features & Use Cases - Code Smell Remediation: Identifies and fixes ten common smells including long methods, duplicated code, feature envy, primitive obsession, and nested conditionals, each with before/after examples. - Structural Refactoring Patterns: Covers extract method, strategy pattern, chain of responsibility, guard clauses, and introducing type safety with TypeScript-style domain types. - Safe Refactoring Process: Enforces a prepare-identify-refactor-verify workflow requiring tests, small commits, and behavior preservation at every step. - Use Case: A developer inherits a 200-line order processing function with nested conditionals and duplicated discount logic. Use this Skill to break it into focused functions, extract shared discount rates, and apply guard clauses while keeping all tests green. ## Quick Start Ask the agent to refactor a specific function or file to reduce duplication and improve readability without changing its behavior.

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I refactor a long function without breaking it?

Break the function into smaller focused methods using extract method refactoring, one step at a time. Ensure tests exist first, run them after each small change, and commit whenever tests pass so you can roll back safely.

How to remove duplicated code across multiple functions?

Extract the shared logic into a single reusable function or constant table, then have each original function call it. For example, replace repeated membership discount conditionals with one getMembershipDiscountRate lookup function.

When should I not refactor code?

Avoid refactoring stable code that will not change, critical production code lacking tests, or anything under a tight deadline. Add tests first before touching untested critical paths, and always have a clear purpose beyond cosmetic preference.

What is the difference between refactoring and rewriting code?

Refactoring preserves external behavior while improving internal structure through small verified steps. Rewriting replaces the implementation entirely, which carries higher risk; this Skill covers gradual improvement, not from-scratch rebuilds.

How do I replace nested conditionals with cleaner code?

Use guard clauses with early returns so each invalid condition exits immediately, leaving the happy path unindented. For complex validation, a chain of responsibility pattern or a Result type can compose individual validators.