Surgical Refactoring logo

Surgical Refactoring

Community
adamentwistle
surgical-refactoring

Refactor/rename/migration discipline — enumerate every call site before the first edit, separate mechanical from judgment edits, keep the build green, verify by absence and presence. Use when asked to rename, extract, move, split, inline, or deduplicate code; for signature/type reshapes; for codebase-wide pattern swaps (replace a helper, swap a library call); for any change touching 3+ call sites. Not for feature work or bug fixes that merely touch many files.

Overview

Publisheradamentwistle
Repositoryfable-skills
Skill namesurgical-refactoring
Stars
98
Forks
11
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by adamentwistle on GitHub. Read the source before you install it.

Installation

Install the Surgical Refactoring AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/adamentwistle/fable-skills/tree/main/surgical-refactoring
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/adamentwistle/fable-skills.git /tmp/fable-skills
mkdir -p .claude/skills
cp -r /tmp/fable-skills/surgical-refactoring .claude/skills/surgical-refactoring
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Surgical Refactoring in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Surgical Refactoring on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Surgical Refactoring is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Surgical Refactoring

Weak refactoring edits the hits the first grep happened to show, fixes a bug it noticed on the way, and calls it done when the build passes. Strong refactoring writes the full touch-point list before editing, changes behavior by exactly zero in the mechanical pass, and proves completion with a grep that returns nothing.

0. Baseline before the first edit

Run the project's gate suite (build/typecheck, lint, tests) once before touching anything and note what already fails. Without this you cannot tell a failure you caused from one you inherited.

1. Enumerate every touch point BEFORE the first edit

Grep for the symbol/pattern in every casing and form (fooBar, foo_bar, FooBar, foo-bar, string literals, dynamic/reflective access, re-exports, tests, docs, config). Record the exact command and the hit count. That list is the definition of done — not a green build, because dead branches, string-keyed lookups, and mock/stub twins compile fine while broken.

Sweeps people skip: test fixtures, mocks that mirror real implementations, serialized/persisted keys, API contract strings, comments/docs, CI and build config, anything reached by string dispatch.

2. Separate mechanical from judgment edits

(a) Mechanical: rename, move, signature reshuffle — zero behavior change. (b) Judgment: logic changes, improvements. Do them in separate passes, ideally separate commits, and run the gate suite between them: a green gate after the mechanical pass alone is the proof that pass was behavior-neutral. A diff mixing both is unreviewable, and behavior bugs hide inside "just a rename".

If asked only to refactor, behavior must be bit-identical. Bugs found mid-refactor are noted and reported, not fixed — fixing them silently changes behavior the user did not ask to change.

3. Sequence to keep the build green

Introduce the new shape first (new function/type alongside the old), migrate call sites in groups, delete the old shape last. When old and new cannot coexist, do the full sweep in one atomic pass. Never end a session with half the call sites migrated.

4. Verify by absence AND presence

  • Absence: rerun the step-1 grep → zero hits, or a one-line justification per remaining hit.
  • Presence: the full gate suite after the last edit.
  • Behavior: exercise the refactored path at runtime — a pure rename that passes tests can still break string-keyed dispatch or serialized data.

5. Scope is a contract

Improvements outside the requested scope go in the report as suggestions, not in the diff. The only exception is a change strictly required to complete the refactor (a caller that must adapt).

Stop and re-plan when

The sweep reveals far more sites than expected (5×), a public API or shared-interface boundary, or persisted-data implications (stored keys, wire formats, migrations). Surface it before continuing; it changes the cost and risk the user approved.

Report

Include: the grep command with before/after hit counts, justification for any remaining hit, gate results (baseline vs final), what you exercised at runtime, and the bugs and out-of-scope improvements you noticed but did not touch.

Frequently asked questions

What does the Surgical Refactoring AI skill do?

Refactor/rename/migration discipline — enumerate every call site before the first edit, separate mechanical from judgment edits, keep the build green, verify by absence and presence. Use when asked to rename, extract, move, split, inline, or deduplicate code; for signature/type reshapes; for codebase-wide pattern swaps (replace a helper, swap a library call); for any change touching 3+ call sites. Not for feature work or bug fixes that merely touch many files.

Why use Surgical Refactoring on TypingMind?

Because you install it once and use it with any model. Surgical Refactoring is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Surgical Refactoring in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/adamentwistle/fable-skills/tree/main/surgical-refactoring. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Surgical Refactoring?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Surgical Refactoring?

As many as you like. As long as a model supports skills, you can use Surgical Refactoring with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Surgical Refactoring AI skill free?

Yes. It is published on GitHub by adamentwistle under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇