refactor-safely
Skill7 starsChanged 15 days agoMITView on GitHub
Use when a function or module has grown — long method, feature envy, god class, duplicated code — and must change shape without changing behavior.
19 other projects use a version of this.
Adopted by
Most recently taken up by
- rumotion/ai-agent-project-templatetheir own version, first seen Nov 1, 2026
- yaohuangguan/remote-arctheir own version, first seen Nov 1, 2026
- Remote-Arc/remote-arctheir own version, first seen Nov 1, 2026
- VelimirMueller/claude-skillsword for word, first seen Nov 1, 2026
- rpraharaj/ai-sdlctheir own version, first seen Nov 1, 2026
- yaohuangguan/agent-playbooktheir own version, first seen Nov 1, 2026
Used with
Projects with it also use audit-test-suite, change-data-safely and 10 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.
yaohuangguanSkillaudit-test-suite
Find where an existing test suite is weak and decide what to test next, ranked by risk. Use this when asked to add missing tests, find gaps, raise coverage, assess test quality or see which areas are thin, even if the request only mentions a coverage percentage.
Also in 3 projects that use this
yaohuangguanSkillchange-data-safely
Change a database schema or stored data without breaking running code or losing data. Use this for any migration, new or changed column, backfill, bulk update, delete, index, or change to a stored format, including in small projects. Data mistakes are often impossible to undo.
Also in 3 projects that use this
SauravSrivastavSkilldebug-failure
Diagnose a failing test, command, or runtime behavior using evidence and produce a minimal verified fix.
Also in 3 projects that use this
NVIDIASkilldebug-issue
Use when the user asks to debug, investigate, or fix a GitHub issue or supplies a repository bug report.
Also in 5 projects that use this
ficaviolaodorata520Skillsecurity-pass
Review an MCP server for common security gaps: LLM-facing surfaces as injection vector (tools, resources, prompts, descriptions), scope blast radius, destructive ops without consent, upstream auth shape, input sinks (URL / path / roots / shell / sampling / schema strictness / ReDoS), tenant isolation, leakage through errors and telemetry, unbounded resources, and HTTP-mode deployment surface. Use before a release, after a batch of handler changes, or when the user asks for a security review, audit, or hardening pass. Produces grouped findings and a numbered options list.
Also in 3 projects that use this
Codagent-AISkillimplement-change
Implements an approved change in one continuous session, with tiered test runs. Use when asked to implement a change from its approved definition, or to invoke codagent:implement-change.
Also in 5 projects that use this
- +6 more from yaohuangguan
Other versions19 projects use a version of this.
Word for word · 1
- VelimirMueller/claude-skills★ 7100% same
Edited · 0
None found.
Wrote their own version · 18
- tirth8205/code-review-graph★ 33ksame name
- techygarg/lattice★ 209same name
- Remote-Arc/remote-arc★ 5same name
- yaohuangguan/remote-arc★ 5same name
- Arasz/ai-badger★ 3same name
- hamakyo/okf-skills★ 2same name
- imMamdouhaboammar/get-things-done★ 2same name
- contextosai/skills★ 1same name
- exactbee/claude-code-workflow★ 1same name
- rpraharaj/ai-engineer★ 1same name
8 more not listed
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 repository156 other files it gives its agents.
- skills/swift/swiftui-design-principles/AGENTS.mdAGENTS.md
- skills/swift/ios-code-audit/CLAUDE.mdCLAUDE.md
- skills/swift/swift-focusengine-pro/llms.txtllms.txt
- build-llm-seamSkill
- build-mcp-serverSkill
- build-rag-pipelineSkill
- secure-llm-featuresSkill
- set-up-llm-evalsSkill
- build-nextjs-backendSkill
- build-supabase-edge-functionSkill
- configure-backend-testsSkill
- design-http-apiSkill
- harden-backendSkill
- scaffold-fastapi-serviceSkill
- scaffold-go-serviceSkill
- scaffold-hono-serviceSkill
- secure-supabase-rlsSkill
- set-up-backend-authSkill
- set-up-background-jobsSkill
- set-up-databaseSkill
- set-up-nextjs-supabase-authSkill
- set-up-observabilitySkill
- set-up-supabaseSkill
- build-cliSkill
- release-cliSkill
- set-up-dev-toolchainSkill
- audit-securitySkill
- audit-toolchainSkill
- extend-skillsetSkill
- promote-releaseSkill
- set-up-stack-profileSkill
- write-commit-messagesSkill
- write-pull-requestsSkill
- analyze-complexitySkill
- apply-algorithmsSkill
- apply-design-patternsSkill
- apply-design-principlesSkill
- apply-solidSkill
- choose-data-structureSkill
- debug-systematicallySkill
- enforce-dependency-ruleSkill
- slice-and-estimateSkill
- write-clean-testsSkill
- write-readable-codeSkill
- clean-frontend-scaffoldingSkill
- configure-accessibilitySkill
- configure-analyticsSkill
- configure-ciSkill
- configure-error-trackingSkill
- configure-lintingSkill
- configure-test-stackSkill
- configure-typescriptSkill
- create-moduleSkill
- optimize-performanceSkill
- scaffold-frontend-projectSkill
- set-up-authSkill
- set-up-design-systemSkill
- set-up-document-headSkill
- set-up-error-boundariesSkill
- set-up-feature-flagsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. 0 are common, 3 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 16 edited versions we read keep these.
3
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
- Distinctive: line 41
Prefer mechanical, reversible moves (extract, rename, inline, move) over clever rewrites.
- Distinctive: line 42
Leave the Boy-Scout rule as the default: make the touched code cleaner than you found it, but do not expand the blast radius to unrelated …
- Distinctive: line 52
No tests and no easy way to add one: make the smallest mechanical move and label it unverified.
“Common” is measured: kept by at least 6 in 10 of the 16 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 Safely
Changes the structure of code without changing its behaviour, one smell at a time, under a green test. The smell vocabulary and Boy-Scout rule are here; readability rules are in write-readable-code.
1. Audit (change nothing)
cat .claude/stack-profile.md 2>/dev/null | head -20
git status --short 2>/dev/null
ls tests 2>/dev/null || find . -name "*_test.*" -o -name "*.test.*" 2>/dev/null | headConfirm two preconditions before touching anything: the tree is clean (or changes are committed) and a test covers the code you will move. If neither holds, stop and say so — refactoring without a safety net is editing, not refactoring.
2. Name the smell
| Smell | Symptom | Refactor |
| Long method | a function that scrolls | Extract method, then extract until each does one thing |
| Feature envy | a method calls another object's data more than its own | Move the method to the object it envies |
| God class | one class with many reasons to change | Extract class by responsibility |
| Duplication | the same block in two places | Extract and link; one source of truth |
| Magic number | a bare literal in logic | Name the constant |
| Dead code | a path nothing reaches | Delete (git keeps it) |
| Data clump | the same 2–3 fields always passed together | Group into one value/struct |
| Switch over type | a conditional on a discriminator | Replace with a union + per-kind function |
3. Refactor in discipline
- One smell at a time, and run the tests after each move — never a batch that changes many things at once.
- Separate refactoring from behaviour change: refactor and feature land in different PRs.
- Prefer mechanical, reversible moves (extract, rename, inline, move) over clever rewrites.
- Leave the Boy-Scout rule as the default: make the touched code cleaner than you found it, but do not expand the blast radius to unrelated files.
Verify
The tests pass unchanged (you did not edit them except to add one), the public behaviour is identical, and the diff reads as moves and renames. State the smell found and the refactor applied in the note.
When to deviate
- No tests and no easy way to add one: make the smallest mechanical move and label it unverified.
- The smell is actually load-bearing performance: measure before changing (see engineering-principles.md — measure before optimizing).
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.

