agentleFS
tarikhamiltontarikhamilton/claude-skills/skills/refactor-and-safety-pass/SKILL.md

refactor-and-safety-pass

Skill0 starsChanged 5 months agoMITView on GitHub

Refactoring safety guard. Use when the user asks to refactor, rename, extract, move, restructure, or reorganize code. Ensures all consumers are updated, no references are orphaned, and changes are verified.

The file

Show its rules and text

We split this skill into the rules it gives an agent

15 rules. About 0 are common, 14 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈14

    Distinctive · estimate

    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
  1. Distinctive:

    Before touching any code:

    line 12
  2. Very specific:

    Update barrel files (index.ts, index.js) when moving or renaming exports.

    line 22
  3. Distinctive:

    Keep git commits atomic: one logical change per commit.

    line 24
  4. Distinctive:

    If renaming: grep the entire project for string references — test IDs, route names, analytics events, config keys, comments.

    line 25
  5. Distinctive:

    Check dynamic references (string interpolation, object key access).

    line 31
  6. Distinctive:

    Update barrel files if the project uses them.

    line 36
  7. Distinctive:

    Update all import paths that reference the old location.

    line 39
  8. Distinctive:

    Check for relative path breakage in nearby files.

    line 41
  9. Distinctive:

    Delete the old file — do not leave a copy behind.

    line 42
  10. Distinctive:

    Update all call sites to match the new signature.

    line 45
  11. Distinctive:

    Update tests that call the function or component.

    line 47
  12. Distinctive:

    Verify the abstraction has a single usage (or very few) before inlining.

    line 50
  13. Distinctive:

    Remove the now-dead abstraction after inlining.

    line 51
  14. Distinctive:

    Remove its export from barrel files.

    line 52
  15. Distinctive:

    After completing the refactor:

    line 56

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Refactor & Safety Pass

You are performing a guarded refactoring operation. Follow every section in order — do not skip the pre-check or post-check.

Pre-Refactor Checklist

Before touching any code:

  1. Identify all consumers — grep for imports and usages of the target across the entire project.
  2. Check test coverage — find test files that cover the target (matching file names, import paths, or direct references).
  3. Note public API surface — list every exported type, function, component, or constant from the target.
  4. Assess blast radius — count how many files will change. If >20 files, warn the user and confirm before proceeding.

During Refactor — Safety Rules

  • Preserve all public exports, or update every consumer that depends on them.
  • Update barrel files (index.ts, index.js) when moving or renaming exports.
  • Maintain backward-compatible type signatures unless the user explicitly intends a breaking change.
  • Keep git commits atomic: one logical change per commit.
  • If renaming: grep the entire project for string references — test IDs, route names, analytics events, config keys, comments.

Refactor Patterns

Rename

  • Find-and-replace across the entire project, including strings, comments, and test IDs.
  • Check dynamic references (string interpolation, object key access).

Extract function / component

  • Move to the appropriate directory following existing project conventions.
  • Export from the new location, update the original to import from it.
  • Update barrel files if the project uses them.

Move file

  • Update all import paths that reference the old location.
  • Update barrel exports.
  • Check for relative path breakage in nearby files.
  • Delete the old file — do not leave a copy behind.

Change signature

  • Update all call sites to match the new signature.
  • Update type definitions.
  • Update tests that call the function or component.

Inline

  • Verify the abstraction has a single usage (or very few) before inlining.
  • Remove the now-dead abstraction after inlining.
  • Remove its export from barrel files.

Post-Refactor Verification

After completing the refactor:

  1. Grep for old name/path — should return zero hits. If any remain, update them.
  2. Check for orphaned files — if a new file was created, confirm the old file was deleted (unless intentionally keeping both).
  3. Check for dead exports — things still exported but no longer imported anywhere.
  4. Verify tests reference valid targets — test imports and assertions should point to the new name/path.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.