safe-refactor
Skill60 starsChanged 10 months agoMITView on GitHub
When refactoring, rewriting, or migrating critical code paths, orchestrate a safe cycle: assess risks → implement → verify → document. Chains pre-mortem and prove-it with built-in implementation phase. Prevents "refactor broke production" disasters. Activates on "refactor", "rewrite", "migrate", or "clean up" for non-trivial code.
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
- suleymanbyzt/agent-helmtheir own version, first seen Aug 18, 2026
Used with
Projects with it also use caveman-explore, surgical-patch and 3 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
GoogleSkillcode-review
Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.
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
- 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
- suleymanbyzt/agent-helm★ 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 repository38 other files it gives its agents.
- agent-auditSkill
- battle-planSkill
- breadcrumbsSkill
- careful-deleteSkill
- debug-to-fixSkill
- dont-be-greedySkill
- dripSkill
- etaSkill
- fan-outSkill
- geordieSkill
- granola-syncSkill
- keep-it-simpleSkill
- learn-from-thisSkill
- loose-endsSkill
- map-reduceSkill
- obsidian-base-createSkill
- obsidian-canvas-createSkill
- obsidian-daily-driverSkill
- obsidian-note-createSkill
- obsidian-session-syncSkill
- obsidian-vault-initSkill
- obsidian-vault-searchSkill
- pair-modeSkill
- pipelineSkill
- pre-mortemSkill
- prove-itSkill
- retrospectiveSkill
- rubber-duckSkill
- sanity-checkSkill
- skill-creatorSkill
- skill-forgeSkill
- skill-gateSkill
- split-decisionSkill
- stay-in-laneSkill
- trace-itSkill
- you-sureSkill
- youtube-transcriptSkill
- zero-inSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. 0 are common, 14 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 10 edited versions we read keep these.
14
Distinctive
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
- could be automatic: a setting could enforce it
- Distinctive: line 74
GATE: Do not proceed if:
- Distinctive: line 79
If high risk: Consider breaking into smaller refactors.
- Distinctive: line 105
GATE: Do not proceed without:
- Distinctive: line 117
Don't mix refactoring with feature changes
- Distinctive: line 118
Don't fix bugs you discover (note them, fix separately)
- Distinctive: line 119
Don't "while I'm here" other improvements
- Distinctive: line 133
After each logical change
- Distinctive: line 135
If tests fail: revert and try smaller steps
- Distinctive: line 139
No fixing edge cases (that's a separate change)
- Distinctive: line 169
GATE: Do not merge until all checks pass.
- Distinctive: line 222
Commit all changes in one giant commit
- Distinctive: line 229
Ensure tests exist (write them if needed)
- Distinctive: line 232
Run tests after each logical change
- Distinctive: line 233
Verify behavior is preserved exactly
“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
<purpose>
An elixir for risky code changes. Refactors feel safe ("I'm just cleaning up")
but they're where bugs hide. This chains risk assessment → careful implementation
→ verification → documentation. The ceremony slows you down just enough to
catch problems before production does.
</purpose>Prerequisites
This elixir works best with these skills installed:
| Skill | Purpose | If Missing |
| pre-mortem | Risk assessment before starting | Falls back to built-in checklist |
| prove-it | Verification enforcement | Falls back to built-in verification |
| retrospective | Document learnings | Skipped (optional phase) |
When To Activate
<triggers>
- "Refactor this"
- "Clean up this code"
- "Rewrite this to be more..."
- "Migrate from X to Y"
- "Replace this implementation"
- Large-scale find-and-replace
- Changing shared utilities or core abstractions
- Touching code you didn't write
</triggers>Instructions
Phase 1: Assess Risk
<phase_risk> If pre-mortem skill installed: Invoke it now.
If not installed, evaluate:
## Refactor Risk Assessment
**What's changing:**
- [ ] Files affected: [list them]
- [ ] Functions/classes modified: [list them]
- [ ] Estimated lines changed: [number]
**Risk factors:**
- [ ] Touches shared/core code (used by multiple features)
- [ ] Affects data persistence (database, files, cache)
- [ ] Changes public API/interfaces
- [ ] Lacks test coverage
- [ ] Written by someone else / unfamiliar code
- [ ] Production-critical path
**Risk level:** [Low / Medium / High / Abort]GATE: Do not proceed if:
- Risk is "Abort"
- More than 3 risk factors checked AND no tests exist
- You can't list all affected files
If high risk: Consider breaking into smaller refactors. </phase_risk>
Phase 2: Prepare
<phase_prepare> Before touching code:
- Ensure tests exist (or write them first)
- [ ] Existing tests cover the behavior being preserved - [ ] If no tests: write characterization tests NOW - Create escape hatch
git stash # or commit current state git checkout -b refactor/[description] - Document current behavior
Before: [How it works now] After: [How it should work - must be identical externally]
GATE: Do not proceed without:
- Tests that verify current behavior
- Clean git state (can revert easily)
- Clear before/after behavior description </phase_prepare>
Phase 3: Implement
<phase_implement> Rules for safe refactoring:
- One thing at a time
- Don't mix refactoring with feature changes
- Don't fix bugs you discover (note them, fix separately)
- Don't "while I'm here" other improvements
- Small commits
# Good: multiple small commits git commit -m "Extract helper function" git commit -m "Rename variables for clarity" git commit -m "Move file to new location" # Bad: one giant commit git commit -m "Refactor everything" - Run tests frequently
- After each logical change
- Before each commit
- If tests fail: revert and try smaller steps
- Preserve behavior exactly
- No "improvements" to logic
- No fixing edge cases (that's a separate change)
- External behavior must be identical </phase_implement>
Phase 4: Verify
<phase_verify> If prove-it skill installed: Invoke it now.
If not installed:
## Refactor Verification
**Automated checks:**
- [ ] All existing tests pass
- [ ] No new linter errors
- [ ] Type checking passes (if applicable)
**Manual verification:**
- [ ] Tested the primary use case manually
- [ ] Checked one edge case
- [ ] Compared behavior before/after for critical paths
**Regression check:**
- [ ] git diff shows only intended changes
- [ ] No accidental behavior changes
- [ ] No debug code left inGATE: Do not merge until all checks pass.
If verification fails:
git revert HEAD # or reset to before refactor
# Start over with smaller scope</phase_verify>
Phase 5: Document (Optional)
<phase_document> If retrospective skill installed: Invoke for significant refactors.
For large refactors, capture:
- What was refactored and why
- Any tricky parts or gotchas discovered
- Patterns that emerged (potential future skills) </phase_document>
Output Format
## Safe Refactor: [Description]
### Risk Assessment
- Risk level: [Low/Medium/High]
- Files affected: [count]
- Risk factors: [list]
### Preparation
- [x] Tests verified/written
- [x] Branch created: refactor/[name]
- [x] Current behavior documented
### Implementation
- Commits: [count]
- Approach: [brief description]
### Verification
- [x] Tests pass
- [x] Manual verification complete
- [x] No regressions detected
### Learnings (if significant)
[What you'd do differently]NEVER
- Refactor and add features in the same change
- Skip the risk assessment ("it's just a small cleanup")
- Make large changes without test coverage
- Commit all changes in one giant commit
- "Fix" bugs discovered during refactoring (note them separately)
- Proceed when tests are failing
ALWAYS
- Assess risk before starting
- Ensure tests exist (write them if needed)
- Work on a branch with escape hatch ready
- Make small, incremental commits
- Run tests after each logical change
- Verify behavior is preserved exactly
Example
User: "Refactor the authentication module to use the new token format"
Phase 1 - Risk Assessment:
Refactor Risk Assessment:
- Files affected: auth.ts, token.ts, middleware.ts, 12 test files
- Risk factors: ✓ Core code, ✓ Production-critical, ✓ Written by someone else
- Risk level: High
Recommendation: Break into smaller refactors:
- First: Add new token format support alongside old
- Second: Migrate consumers one by one
- Third: Remove old format
Phase 2 - Prepare:
- Existing tests cover token generation and validation
- Created branch: refactor/token-format-v2
- Documented: Old format is JWT with RS256, new format adds
typheader
Phase 3 - Implement:
Making changes incrementally...
- Commit 1: "Add TokenV2 class with new format"
- Commit 2: "Add feature flag for token format"
- Commit 3: "Update token generation to use flag"
- Tests passing after each commit ✓
Phase 4 - Verify:
- All 47 auth tests pass
- Manual test: login flow works with both formats
- Manual test: token refresh works
- git diff shows only intended changes
Ready to merge.
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.

