refactor-code
Skill27 starsChanged 4 months agoMITView on GitHub
Use when changing Rails structure without changing behavior. Characterization tests must be green first. Trigger words: refactor, extract, restructure, split class.
9 other projects use a version of this.
Adopted by
Most recently taken up by
- BrOrlandi/my-claude-skillstheir own version, first seen Sep 22, 2026
- bsafronov/prosto-skillstheir own version, first seen Aug 31, 2026
- r2rka1/skillstheir own version, first seen Aug 18, 2026
- emaraschio/cursor-commandstheir own version, first seen Aug 7, 2026
- chrisetheridge/skillstheir own version, first seen May 11, 2026
- drafael/coding-harnesstheir own version, first seen Apr 28, 2026
Other versions9 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 9
- BrOrlandi/my-claude-skills★ 21same name
- zbruhnke/claude-code-starter★ 17same name
- emaraschio/cursor-commands★ 9same name
- chrisetheridge/skills★ 4same name
- adolfoaranaes12/BMAD-ENHANCED★ 2same name
- r2rka1/skills★ 2same name
- drafael/coding-harness★ 1same name
- bsafronov/prosto-skills★ 0same name
- gologo13/agent-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository32 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- apply-code-conventionsSkill
- apply-stack-conventionsSkill
- code-reviewSkill
- create-engine-installerSkill
- create-engineSkill
- document-engineSkill
- extract-engineSkill
- generate-api-collectionSkill
- implement-authorizationSkill
- implement-background-jobSkill
- implement-graphqlSkill
- implement-hotwireSkill
- load-contextSkill
- optimize-performanceSkill
- plan-testsSkill
- rails-featureSkill
- rails-maintenanceSkill
- rails-reviewSkill
- release-engineSkill
- review-architectureSkill
- review-engineSkill
- review-migrationSkill
- security-checkSkill
- seed-databaseSkill
- setup-environmentSkill
- test-engineSkill
- test-serviceSkill
- upgrade-engineSkill
- version-apiSkill
- write-testsSkill
The file
We split this skill into the rules it gives an agent
9 rules. 0 are common, 8 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 9 edited versions we read keep these.
8
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Use this skill when the task is to change structure without changing intended behavior.
- Distinctive: line 53
Write this before touching any production file: No refactoring step begins until this test exists and passes on the current (un-refactored) …
- Very specific: line 71
Run it: bundle exec rspec spec/requests/orders_spec.rb — it must pass on the current code.
- Distinctive: line 105
Run verification after every refactoring step:
- Distinctive: line 106
Run the full test suite.
- Distinctive: line 107
Read the output — check exit code, count failures.
- Distinctive: line 108
If tests fail: STOP, undo the step, investigate.
- Distinctive: line 109
If tests pass: proceed to next step.
- Distinctive: line 110
Only claim completion with evidence from the last test run — report the last line of output (e.g.
“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Refactor Code
Use this skill when the task is to change structure without changing intended behavior.
Core principle: Small, reversible steps over large rewrites. Separate design improvement from behavior change.
Quick Reference
| Step | Action | Verification |
| 1 | Define stable behavior | Written statement of what must not change |
| 2 | Add characterization tests | Tests pass on current code |
| 3 | Choose smallest safe slice | One boundary at a time |
| 4 | Rename, move, or extract | Tests still pass |
| 5 | Remove compatibility shims | Tests still pass, new path proven |
HARD-GATE
NO REFACTORING WITHOUT CHARACTERIZATION TESTS FIRST.
NEVER mix behavior changes with structural refactors in the same step —
if behavior changes are also needed, complete the structural refactor first,
then apply behavior changes in a separate step with its own test.
ONE boundary per refactoring step — never extract two abstractions in the same step.
If a public interface changes, document the compatibility shim and its removal condition.
NEVER fabricate test output — label only actual run output as Observed output.Core Process
1. Define stable behavior
Identify the exact inputs and outputs of the logic being refactored. Keep public interfaces stable until callers are migrated. Prefer adapters, facades, or wrappers for transitional states.
Include in your output:
- Stable behavior statement: an explicit statement of what must not change (inputs/outputs, public interfaces).
- Shim decision: name any transitional adapter/facade/wrapper and its removal condition, or state why none is needed.
2. Add characterization tests
Write this before touching any production file. No refactoring step begins until this test exists and passes on the current (un-refactored) code. If the characterization spec fails, do not continue — stop and fix the test or the behavior mismatch.
# spec/requests/orders_spec.rb (or service/model spec — mirror the file being refactored)
# frozen_string_literal: true
RSpec.describe "Orders#create current behavior", type: :request do
describe "POST /orders" do
let(:valid_params) { { order: { product_id: 1, quantity: 2 } } }
it "creates order and enqueues warehouse notification" do
expect { post orders_path, params: valid_params }
.to change(Order, :count).by(1)
expect(NotifyWarehouseJob).to have_been_enqueued
end
end
endRun it: bundle exec rspec spec/requests/orders_spec.rb — it must pass on the current code.
3. Choose the smallest safe slice
Good first moves include: renaming unclear methods, isolating duplicated logic behind a shared object, or wrapping external integrations before moving call sites. Add narrow seams before deleting old code paths. One boundary at a time — characterization tests first, verification after each step.
4. Execute extraction/refactor (One step at a time)
Extract, move, or rename logic. Stop and simplify if the refactor introduces more indirection than clarity.
Minimal Inline Example (Controller orchestration extraction)
Before:
def create
order = OrderCreator.new(params).call
NotifyWarehouseJob.perform_later(order.id)
redirect_to order_path(order)
endAfter:
def create
order = Orders::CreateOrder.call(params: params)
redirect_to order_path(order)
endExtended Resources (Progressive Disclosure)
Load these files only when their specific content is needed:
- assets/complete_example.md — A complete, step-by-step example of a high-scoring
answer.mdshowing plan, stable behavior, characterization tests, step-by-step verification runs, and final suite verification command outputs. - EXAMPLES.md — For more examples of extracting services and renaming in small batches.
5. Verification Protocol
Run verification after every refactoring step:
- Run the full test suite.
- Read the output — check exit code, count failures.
- If tests fail: STOP, undo the step, investigate.
- If tests pass: proceed to next step.
- Only claim completion with evidence from the last test run — report the last line of output (e.g. "5 examples, 0 failures").
Report test run output at EACH step — not only at the end. At least two separate Observed output entries at different sequence points are required.
Evidence labelling rules: Label actual run output as Observed output only. Never use labels such as "Expected output", "Required output", "Planned output", or "Must produce 0 failures" as substitutes for actual observed run output. If you have not run the tests, you have no observed output to report.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
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.

