refactor
Has your agent restructure and simplify existing code. It's useful when you need to modernize or improve code organization.
What it does
This tool helps organize and improve your code. It understands what you want to change, analyzes how the code is connected, and plans changes safely to avoid errors.
When to use it
- ✓When you want to simplify a complex piece of code.
- ✓When you need to extract a part of the code into a new module.
- ✓When you want to modernize or restructure an old project.
Example of what to ask your AI
“Refactor the login function to use the new authentication pattern.”
Want more? Open the sections below.
How to use
The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.
Skill link
Ready-to-paste message
How it works
The AI first understands your request and analyzes all your code to see how parts relate. Then, it creates a detailed plan and makes changes step-by-step, checking that everything still works.
Installation
Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.
In the terminal (Claude Code, Codex, Cursor), in your project folder:
npx skills add code-yeongyu/oh-my-openagent --skill refactorOr download just the file:
curl -L https://raw.githubusercontent.com/code-yeongyu/oh-my-openagent/dev/packages/shared-skills/skills/refactor/SKILL.md -o SKILL.mdTechnical content (original SKILL.md)
Original text by the author, straight from GitHub.
export const REFACTOR_TEMPLATE = `# Intelligent Refactor Command
Usage
``` /refactor <refactoring-target> [--scope=<file|module|project>] [--strategy=<safe|aggressive>]
Arguments: refactoring-target: What to refactor. Can be: - File path: src/auth/handler.ts - Symbol name: "AuthService class" - Pattern: "all functions using deprecated API" - Description: "extract validation logic into separate module"
Options: --scope: Refactoring scope (default: module) - file: Single file only - module: Module/directory scope - project: Entire codebase
--strategy: Risk tolerance (default: safe) - safe: Conservative, maximum test coverage required - aggressive: Allow broader changes with adequate coverage ```
What This Command Does
Performs intelligent, deterministic refactoring with full codebase awareness. Unlike blind search-and-replace, this command:
- Understands your intent - Analyzes what you actually want to achieve
- Maps the codebase - Builds a definitive codemap before touching anything
- Assesses risk - Evaluates test coverage and determines verification strategy
- Plans meticulously - Creates a detailed plan with Plan agent
- Executes precisely - Step-by-step refactoring with LSP and AST-grep
- Verifies constantly - Runs tests after each change to ensure zero regression
PHASE 0: INTENT GATE (MANDATORY FIRST STEP)
BEFORE ANY ACTION, classify and validate the request.
Step 0.1: Parse Request Type
| Signal | Classification | Action |
|---|---|---|
| Specific file/symbol | Explicit | Proceed to codebase analysis |
| "Refactor X to Y" | Clear transformation | Proceed to codebase analysis |
| "Improve", "Clean up" | Open-ended | MUST ask: "What specific improvement?" |
| Ambiguous scope | Uncertain | MUST ask: "Which modules/files?" |
| Missing context | Incomplete | MUST ask: "What's the desired outcome?" |
Step 0.2: Validate Understanding
Before proceeding, confirm:
- Target is clearly identified
- Desired outcome is understood
- Scope is defined (file/module/project)
- Success criteria can be articulated
If ANY of above is unclear, ASK CLARIFYING QUESTION:
``` I want to make sure I understand the refactoring goal correctly.
What I understood: [interpretation] What I'm unsure about: [specific ambiguity]
Options I see:
- [Option A] - [implications]
- [Option B] - [implications]
My recommendation: [suggestion with reasoning]
Should I proceed with [recommendation], or would you prefer differently? ```
Step 0.3: Create Initial Todos
IMMEDIATELY after understanding the request, create todos:
``` TodoWrite([ {"id": "phase-1", "content": "PHASE 1: Codebase Analysis - launch parallel explore agents", "status": "pending", "priority": "high"}, {"id": "phase-2", "content": "PHASE 2: Build Codemap - map dependencies and impact zones", "status": "pending", "priority": "high"}, {"id": "phase-3", "content": "PHASE 3: Test Assessment - analyze test coverage and verification strategy", "status": "pending", "priority": "high"}, {"id": "phase-4", "content": "PHASE 4: Plan Generation - invoke Plan agent for detailed refactoring plan", "status": "pending", "priority": "high"}, {"id": "phase-5", "content": "PHASE 5: Execute Refactoring - step-by-step with continuous verification", "status": "pending", "priority": "high"}, {"id": "phase-6", "content": "PHASE 6: Final Verification - full test suite and regression check", "status": "pending", "priority": "high"} ]) ```
PHASE 1: CODEBASE ANALYSIS (PARALLEL EXPLORATION)
Mark phase-1 as in_progress.
1.1: Launch Parallel Explore Agents (BACKGROUND)
Fire ALL of these simultaneously using `call_omo_agent`:
``` // Agent 1: Find the refactoring target call_omo_agent( subagent_type="explore", run_in_background=true, prompt="Find all occurrences and definitions of [TARGET]. Report: file paths, line numbers, usage patterns." )
// Agent 2: Find related code call_omo_agent( subagent_type="explore", run_in_background=true, prompt="Find all code that imports, uses, or depends on [TARGET]. Report: dependency chains, import graphs." )
// Agent 3: Find similar patterns call_omo_agent( subagent_type="explore", run_in_background=true, prompt="Find similar code patterns to [TARGET] in the codebase.
…
FAQ
What does 'refactor' mean?
Refactoring is reorganizing existing code without changing what it does, just to make it cleaner, more efficient, or easier to understand.
How does the AI ensure it doesn't break anything?
It analyzes existing test coverage and runs tests after each small change to ensure nothing is broken (regression).
Can I ask to refactor a whole file or just a part?
Yes, you can specify if the refactoring should be in a single file, a module (directory), or the entire project.
Details
Original description by the author
Guides a refactor, cleanup, or restructure with the right decomposition. Use when the user asks to refactor, simplify, extract, or modernize code.
Popularity
- GitHub stars
- 70k
- Ranking position
- #1742
- License
- NOASSERTION
- Updated
- 10/16/2026
Comments
- …
More skills from this repository
comment-checker
Helps your agent understand and respond to feedback from automatic comment checkers. It's useful when the agent needs to process information from tools that automatically review code or content.
code-yeongyu/oh-my-openagent
lcx-contribute-bug-fix
Helps your agent contribute bug fixes for LazyCodex-related projects. It creates issues or pull requests to ensure code quality.
code-yeongyu/oh-my-openagent
lcx-doctor
Lets your agent check the health of LazyCodex and Codex CLI installations. It's useful when the system behaves oddly after updates or changes.
code-yeongyu/oh-my-openagent
lcx-report-bug
Helps your agent report bugs in detail for LazyCodex projects. It creates issues with useful information for developers to fix the problem.
code-yeongyu/oh-my-openagent
Similar skills
benchmark-optimization-loop
Has your agent improve something's speed in a measured way. It tests multiple versions and chooses the fastest one that still works correctly.
affaan-m/ECC
change-impact
Helps your agent analyze the impact of code changes before making them. It compares the planned vs. actual results afterward, covering paths, data, tests, and documentation. Useful for risky or system-wide changes.
affaan-m/ECC
click-path-audit
Lets your agent trace all user buttons and interactions to find bugs. It finds issues where functions seem to work alone but fail together. Useful when bugs persist even after debugging.
affaan-m/ECC