safe-refactor
Skill1 starsChanged 3 months agoMITView on GitHub
Use when restructuring, cleaning up, or reorganizing existing code without changing its behavior. Enforces a test safety net before touching anything and proof that behavior was preserved.
10 other projects use a version of this.
Adopted by
Most recently taken up by
- Linchi1997yeh/craftsman-suitetheir own version, first seen Oct 5, 2026
- nomdedev/agent-manager-templatetheir own version, first seen Sep 30, 2026
- JPeetz/agent-skillstheir own version, first seen Sep 29, 2026
- YogirajA/Claude-Skillstheir own version, first seen Sep 17, 2026
- xingtu1996/xingtu-skillstheir own version, first seen Sep 7, 2026
- dennisrongo/claude-skillstheir own version, first seen Aug 16, 2026
Used with
Projects with it also use caveman-explore, surgical-patch and 2 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
JuliusBrusseeSkillcaveman-explore
Read-only repository explorer for cold-start orientation, broad cross-file localization, or when a direct search failed. Skip it when the exact file or symbol is already named. Returns path:line citations only; its reads stay out of main context.
Also in 3 projects that use this
JuliusBrusseeSkillsurgical-patch
Fix bugs and small behavior changes at the narrowest responsible layer. Use when regression proof, preserved surrounding behavior, and task-relevant tests matter.
Also in 3 projects that use this
MicrosoftSkillcaveman
Ultra-compressed response style that reduces output token count while preserving technical accuracy, with intensity levels and auto-clarity safety rules
Also in 3 projects that use this
- +1 more from JuliusBrussee
Other versions10 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 10
- JuliusBrussee/caveman★ 110ksame name
- ElliotJLT/Claude-Skill-Potions★ 60same name
- JPeetz/agent-skills★ 10same name
- yeaight7/agent-powerups★ 6same name
- adityaarakeri/senior-agent-skills★ 2same name
- Linchi1997yeh/craftsman-suite★ 2same name
- nomdedev/agent-manager-template★ 2same name
- dennisrongo/claude-skills★ 1same name
- YogirajA/Claude-Skills★ 1same name
- xingtu1996/xingtu-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 repository12 other files it gives its agents.
- AGENTS.mdAGENTS.md
- core/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- core/CLAUDE.mdCLAUDE.md
- bug-fixSkill
- code-reviewSkill
- dependency-upgradeSkill
- feature-developmentSkill
- integration-briefSkill
- performance-investigationSkill
- record-decisionSkill
- verify-workSkill
The file
We split this skill into the rules it gives an agent
7 rules. 0 are common, 5 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 10 edited versions we read keep these.
5
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Read the code, its callers, and its edge cases.
- Distinctive: line 26
No safety net, no refactor.
- Very specific: line 33
After every step: run the tests.
- Very specific: line 35
If you discover an actual bug mid-refactor, stop, report it, and handle it as a separate bug-fix task.
- Distinctive: line 49
Do not mix refactoring with feature work or bug fixes in one change.
- Distinctive: line 50
Do not delete "weird" code you don't understand — it is load-bearing until proven otherwise.
- Distinctive: line 52
Do not widen the scope mid-refactor.
“Common” is measured: kept by at least 6 in 10 of the 10 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
Safe Refactor
Goal: change the structure, prove the behavior did not change.
A refactor that changes behavior is not a refactor — it is an unreviewed functional change. Refactoring is at least L2: send the Plan message and wait for approval before starting.
Steps
- Understand the current behavior. Read the code, its callers, and its edge cases. List the invariants — the things that must still be true afterwards (outputs, side effects, error behavior, performance characteristics that matter).
- Build the safety net BEFORE changing code.
- Find the existing tests that cover this code. Run them; confirm green.
- Where behavior is untested, add characterization tests: tests that pin down what the code does today — including odd behavior. You are documenting reality, not fixing it.
- No safety net, no refactor.
- Plan small steps. Break the refactor into steps that each keep the tests green. Prefer many small mechanical moves over one big rewrite.
- Refactor.
After every step: run the tests. If a test goes red, the last step broke
behavior — fix the step, do not "adjust" the test.
If you discover an actual bug mid-refactor, stop, report it, and handle
it as a separate
bug-fixtask. Do not silently fix it inside the refactor. - Verify preservation.
Full test suite green. Diff reviewed: only structural changes, no logic
drift, no accidental behavior change. Run the
verify-workskill. - Record.
Journal entry:
docs/agent-journal/YYYY-MM-DD-refactor-<slug>.md(format: Why / Safety net / Steps taken / Proof behavior preserved).
Do not
- Do not mix refactoring with feature work or bug fixes in one change.
- Do not delete "weird" code you don't understand — it is load-bearing until proven otherwise. Investigate first.
- Do not widen the scope mid-refactor. New scope = new proposal.
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.

