Refactor Extract Skill: Pull Out a Function Safely
Extract Function is the safest refactor there is — when you do it right. The wrong way silently changes behavior, breaks a test you forgot existed, or just renames a problem. This skill maps dependencies first, names the function before moving anything, and verifies tests still pass before declaring done.
An installable refactor-extract skill. Maps the block's read/write dependencies, names the new function so it actually says what it does, moves the code, and verifies tests still pass before declaring done.
What It Does
- Maps reads and writes — what's input, what's returned, what mutates outside scope
- Names earn their place — if you can't name it in 4 words, the block isn't ready
- Pure restructure — same calls, same order, same error handling, same behavior
- Verify or revert — existing tests must pass without modification
Install in 30 Seconds
Pick your tool above and download:
- Claude Code:
~/.claude/skills/refactor-extract/SKILL.md - OpenAI Codex CLI: append to
AGENTS.md - Cursor: append to
.cursorrules
Point at a function or range: "Extract validateAddress from src/checkout/submit.ts:80-120."
Why Naming Comes First
If you can't name the extracted function in 4 words, it's doing more than one thing — extracting it just renames the mess. The 4-word rule forces you to either find the real unit of work or restructure before extracting. This skill encodes that rule, which is what makes the refactor actually clean instead of just smaller.
Install once, ship refactors that simplify.