refactoring-pass
Skill4 starsChanged 8 months agoUnlicenseView on GitHub
Changing existing code structure without intending to change observable behavior. Based on Refactoring (Martin Fowler). Covers: behavior-preserving transformations, code smell detection, named refactoring moves (extract, inline, move, rename, decompose), preparatory and follow-up refactoring around feature work, and stop conditions. Triggers on: "refactor", "restructure", "clean up", "extract", "inline", "rename", "move code", "reduce duplication", "simplify", "code smell", "behavior-preserving", or when reviewing code for structural improvement without changing observable behavior.
We split this skill into the rules it gives an agent
16 rules. About 0 are common, 16 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈16
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
If you are reading this, the user wants to improve code structure without changing what the code does.
- Distinctive: line 21
Preserve observable behavior: Every structural change must leave the code doing exactly what it did before — just better organized.
- Distinctive: line 39
Before refactoring, make sure you can detect regressions:
- Distinctive: line 40
Existing tests: Run them. They must pass before you start.
- Distinctive: line 41
No tests: Write characterization tests around the area you're changing.
- Distinctive: line 55
When a requested feature is awkward to make:
- Distinctive: line 62
After making a behavior change:
- Distinctive: line 63
Look for smells the change introduced or revealed.
- Distinctive: line 65
Don't expand beyond what the feature touched.
- Distinctive: line 69
Prefer the simplest named move that helps:
- Distinctive: line 86
Separate behavior changes from structural changes: Never mix a feature change with a refactoring in the same commit.
- Distinctive: line 88
Use abstraction only when current evidence justifies it: Remove pass-through layers, vague utilities, and just-in-case interfaces.
- Distinctive: line 91
Preserve public compatibility, or provide a transition path: When a move changes a public signature, class hierarchy, or serialized shape, …
- Distinctive: line 99
Third repetition: When the same edit appears for a third time, remove duplication through clearer ownership instead of copying again.
- Distinctive: line 100
Mixed responsibilities: When a function mixes phases, abstraction levels, or hidden side effects, split them before adding more logic.
- Distinctive: line 101
Shotgun surgery: When one change forces edits across many files, centralize the knowledge or introduce a clearer boundary.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Refactoring Pass
When This Skill Loads
If you are reading this, the user wants to improve code structure without changing what the code does. Refactoring is behavior-preserving design work in small steps. Do not turn cleanup into a rewrite, a hidden feature change, or speculative architecture.
Core Principle
Preserve observable behavior. Every structural change must leave the code doing exactly what it did before — just better organized.
The Refactoring Workflow
1. Identify the Friction
What makes the current code hard to change? Common smells:
- Duplication — same code in multiple places
- Long functions — too much in one method
- Long parameter lists — too many arguments
- Divergent change — one class changes for many reasons
- Shotgun surgery — one change requires edits across many files
- Feature envy — a method uses another class's data more than its own
- Primitive obsession — primitives where value objects would carry meaning
- Repeated conditionals — same switch/if-else chain in multiple places
- Middle man — a class that only delegates to another
- Speculative generality — abstractions with one caller
2. Establish a Safety Net
Before refactoring, make sure you can detect regressions:
- Existing tests: Run them. They must pass before you start.
- No tests: Write characterization tests around the area you're changing. Capture current behavior, even if it's ugly.
- Unclear behavior: Characterize first. Don't refactor code you don't understand.
- Never delete a failing test to complete a refactoring. A failing test is a signal, not an obstacle.
3. Refactor in Small Steps
Each step should be:
- Reversible — you can undo it if something breaks
- Buildable — the code compiles/passes after each step
- Testable — you can run tests after each step
- Reviewable — the diff is small enough to reason about
Commit after each step that passes tests.
4. Preparatory Refactoring (Before a Feature)
When a requested feature is awkward to make:
- Identify the structural friction that blocks the change.
- Reshape that local structure first — just enough to make the feature simple.
- Make the behavior change.
- Clean up debt introduced by the change.
5. Follow-up Refactoring (After a Feature)
After making a behavior change:
- Look for smells the change introduced or revealed.
- Clean them up while the context is fresh.
- Don't expand beyond what the feature touched.
Named Moves
Prefer the simplest named move that helps:
| Move | When |
| Rename | Name is misleading, vague, or mechanism-focused. Rename before deeper work when bad names block understanding. |
| Extract method | A chunk of code has a distinct purpose. Extract it, name the purpose. |
| Extract class | A class has two independent responsibilities. Split them. |
| Inline | A method's body is as clear as its name. Inline it. |
| Move method/field | Behavior lives in the wrong class. Move it where the data is. |
| Introduce parameter object | A group of parameters always travels together. Bundle them. |
| Encapsulate collection | Callers manipulate a collection directly. Expose intent-revealing methods instead. |
| Decompose conditional | A complex conditional or switch. Extract predicates, use guard clauses, or replace with polymorphism. |
| Replace conditional with polymorphism | Repeated type codes or switch statements that vary behavior. |
| Use guard clauses | Nested conditionals with early exits. Flatten with guard clauses at the top. |
Decision Rules
- Separate behavior changes from structural changes. Never mix a feature change with a refactoring in the same commit.
- Refactor the blocking smell, not every smell in sight. Focus on what makes the current task hard.
- Use abstraction only when current evidence justifies it. Remove pass-through layers, vague utilities, and just-in-case interfaces.
- Separate business policy from delivery mechanics — not just from UI, but from formatting, transport, persistence, I/O, and frameworks.
- Preserve error semantics unless intentionally changing behavior. Refactor error handling to reveal the main path.
- Preserve public compatibility, or provide a transition path. When a move changes a public signature, class hierarchy, or serialized shape, add the new form and migrate callers before removing the old one; check generated/reflected/serialized/plugin-facing usages before deleting anything "unused." See Technique Safety.
- Keep patches reviewable. Group related refactorings. Avoid giant patches that rename, move, redesign, and change logic together.
Trigger Rules
- Adding behavior: First ask what structural friction blocks the change. Refactor before the feature only when it makes the feature safer or simpler.
- Fixing a bug in unclear code: Characterize the current failure. Refactor only enough to make the fix visible before changing behavior.
- Weak tests: Make the smallest possible structural move. Improve testability before broader cleanup.
- Third repetition: When the same edit appears for a third time, remove duplication through clearer ownership instead of copying again.
- Mixed responsibilities: When a function mixes phases, abstraction levels, or hidden side effects, split them before adding more logic. Keep variable scope tight and each function at one consistent abstraction level.
- Shotgun surgery: When one change forces edits across many files, centralize the knowledge or introduce a clearer boundary.
- Repeated conditionals: Decompose intent first. Introduce polymorphism or strategy only when the variation is real.
- UI/domain mixing: Move rules toward domain objects. Keep presentation in adapters, and verify any required presentation synchronization.
- Rewrite temptation: Choose the next small behavior-preserving transformation that recovers control.
Stop Conditions
Stop refactoring when:
- The requested change is easy to make.
- The blocking smell is gone.
- Readability and local changeability are clearly better.
- The next cleanup would be speculative.
Do not turn cleanup into a rewrite, a hidden feature change, or speculative architecture.
Final Checklist
- Observable behavior preserved?
- Structural change, behavior change, and test updates separated?
- Safety net in place (tests pass before and after)? Any verification gap — behavior not protected by tests during the pass — recorded?
- At least one real source of friction removed?
- Names, responsibilities, control flow, data ownership, interfaces clearer?
- Patch still reviewable and runnable?
- Cleanup stopped before speculative abstraction or rewrite pressure?
Reference
| File | Use When |
| Code Smells | Identifying which smell to refactor and which move to apply — the six smell families, the full catalog, the smell→treatment priority map, and when not to treat a smell |
| Refactoring Moves | Step-by-step instructions for specific refactoring techniques |
| Technique Safety | Pre-flight checklists for executing a move safely (extraction, inlining, moving, encapsulation, conditionals, data, generalization) and the public-compatibility rule |
| Preparatory Refactoring | Reshaping structure before adding a feature |
In this repository73 other files it gives its agents.
- agent/AGENTS.mdAGENTS.md
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- git-guardrails-claude-codeSkill
- setup-project-skillsSkill
- skill-creatorSkill
- websearchSkill
- writing-great-skillsSkill
- codebase-designSkill
- construction-craftSkill
- critical-partnerSkill
- data-intensiveSkill
- diagnosing-bugsSkill
- django-disciplineSkill
- docker-disciplineSkill
- documentation-lifecycleSkill
- domain-driven-designSkill
- enterprise-patternsSkill
- git-disciplineSkill
- legacy-codeSkill
- production-readinessSkill
- resolving-merge-conflictsSkill
- tddSkill
- testing-workflowSkill
- ui-design-directionSkill
- webapp-testingSkill
- writing-for-agentsSkill
- django-allauthSkill
- djangoSkill
- dockerSkill
- drfSkill
- full-calendarSkill
- giteaSkill
- htmxSkill
- http-status-codesSkill
- hyperscriptSkill
- langchainSkill
- litestarSkill
- prestashopSkill
- prSkill
- pykeSkill
- python-asyncSkill
- tablerSkill
- cleanroom-rewriteSkill
- councilSkill
- court-jesterSkill
- domain-modelingSkill
- fix-prSkill
- grillingSkill
- grill-meSkill
- grill-with-docsSkill
- handoffSkill
- humanifySkill
- implementSkill
- implement-specSkill
- improve-codebase-architectureSkill
- ponytail-auditSkill
- ponytail-debtSkill
- prototypeSkill
- qaSkill
- The first 60 shown.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

