OmniscioSkills examplesRefactor
A Claude Code refactor skill you can copy
One complete SKILL.md for changing code without changing what it does. What a skill is and how the folder mechanism works is the skills guide; this page is the file, its fields, and the failure people hit with a skill that edits files.
Checked against Anthropic's documentation on November 25, 2026. By the Omniscio team. Updated .
When this skill fires
It does not fire on its own. disable-model-invocation: true stops Claude loading it by itself, because a refactor rewrites files and you want that to start when you say so.
- Directly with
/refactor src/billing.ts,/refactor the date helpers, or/refactoralone to be asked what to change. - Not automatically. "Clean this function up" will not load it. Remove
disable-model-invocationif you want that, but read the section on the common failure first, because that is where a refactor that runs itself goes wrong.
The whole skill, ready to copy
Save this as SKILL.md inside a folder named refactor. The frontmatter has to be the file's first line.
---
name: refactor
description: Refactors the code you name without changing its behaviour, in small steps, running the tests after each step. Use when the user asks to refactor, clean up, simplify, extract a function, rename something, or remove duplication.
argument-hint: [file-or-symbol]
disable-model-invocation: true
allowed-tools: Read Grep Glob Edit Bash(git diff *) Bash(git status *)
---
Refactor $ARGUMENTS. If the arguments are empty, ask which file or symbol before changing a line.
## Baseline first
Run `git status`. If the tree holds changes that are not part of this refactor, say so, because each step is undone by hand and unrelated work makes that messy.
Then run the tests that cover the code before you touch it, and report the result. If they already fail, stop here and say which ones: a refactor on top of a red suite cannot tell you what it broke.
## The rules
- Behaviour must not change. No bug fixes, no new features, no renamed public API, unless the user asked for one in this message.
- One mechanical step at a time — a rename, an extract, an inline — never two in one pass. Grep for the symbol before you rename it, and list the call sites you found. Run the covering tests after every step, not once at the end.
- If a step turns the suite red, revert that step and say what it broke. Do not press on and fix it later.
- Keep the diff readable. If one step touches more than one concern, split it.
- Match the style of the file you are changing, not the style you prefer.
## Finish
Run the whole suite for the package you touched, then report: what changed, the tests you ran and their result, and anything you deliberately left alone.The $ARGUMENTS placeholder is replaced by whatever you typed after the command, so /refactor src/billing.ts reaches Claude as "Refactor src/billing.ts."
The body is about twenty lines, far inside Anthropic's guidance to keep a SKILL.md under 500 lines. That matters because a loaded skill's content stays in the conversation and costs tokens on every turn that keeps it.
What each part does
Every field is optional, and only description is recommended. Field names are matched exactly, hyphens included: an unrecognised one is ignored without an error, so a typo does nothing and says nothing.
| Field | What it does here |
|---|---|
name: refactor | The name you type and its entry in the / menu; without this field the folder name is used instead |
description | What the skill does and when to use it, in the words a person would use: refactor, clean up, simplify, extract, rename. With model invocation off these words label the menu entry rather than matching requests, because Claude never sees the description |
argument-hint: [file-or-symbol] | The autocomplete hint for the one thing the skill needs, so an empty run is rare |
disable-model-invocation: true | Keeps the skill manual. Anthropic's guidance is to set it for workflows with a side effect or a timing you control, and a refactor is a batch of file edits |
allowed-tools: Read Grep Glob Edit Bash(git diff *) Bash(git status *) | Pre-approves reading, searching, editing and a review of the diff for the turn the skill runs. The grant clears on your next message, and it does not take any other tool away |
- "Run the tests after every step" is worded as standing guidance rather than as a single action, and the section on the common failure is where that wording earns its keep.
- The grant stops short of the test runner. Reading, searching, editing and the diff are pre-approved; running the tests and undoing a step are not, so under the default permission settings Claude asks before it does either. Add your own test command to
allowed-toolsif you would rather not be asked. - "Behaviour must not change" is what separates a refactor from a rewrite. Without it, an unnoticed bug fix lands inside a change whose whole claim is that nothing changed.
- "Revert that step" beats "fix it later": a step you cannot undo is a step you cannot trust.
- "Match the style of the file" stops the skill from reformatting a file the diff was meant to leave alone.
Where to put it: personal or project
| Choose | Path | Who gets it |
|---|---|---|
| Personal | ~/.claude/skills/refactor/SKILL.md | You, in every project on this machine, but not Cowork or cloud sessions |
| Project | .claude/skills/refactor/SKILL.md | Everyone in this repository once it is committed |
If both exist, personal wins over project, so a home-folder copy replaces the repository's without warning. A team that has agreed on its own refactor rules should ship only the project copy.
Claude Code watches both directories and picks up an added or edited skill within the session; /reload-skills loads one that does not appear.
How to confirm it loads
- Find the command. Type
/and look forrefactor, or open/skills. - Run it on something small. Pick one function with tests and run
/refactorwith its file. The first thing it should say is the baseline test result, before it edits anything. - Check that it reports the tests after each step. If you get one big edit and one test run at the end, the wording has been ignored; the tests should appear once per step.
- Check the diff before you accept it. A refactor whose diff touches formatting outside the function is not the refactor you asked for.
/doctor estimates the skill listing's context cost, and /skill-doctor reports what each skill costs and how often it is used.
The common failure
The failure this skill is built around is subtler than an error: Claude follows it in the first response and then drifts. A skill's content is added to the conversation once and never re-read, so an instruction phrased as a single action is the wrong shape for a rule that has to hold for the whole task, and the later steps run without tests.
- If the tests stop being run, the guidance reads as one-time. Word it as a rule for the whole task, as this file does: "run the covering tests after every step", not "run the tests".
- If it wanders, put the most important instruction near the top: after a long conversation is compacted, Claude Code can keep only the beginning of an invoked skill.
- If a rule must hold every time, a skill is the wrong place. Anthropic's answer is a hook in a settings file, which runs on its event whether or not Claude is following the skill.
- If it edits without being asked, the frontmatter lost
disable-model-invocation: true. Removing that line is the usual way a deliberate refactor turns into something that starts on its own.
Where this fits
Pair it with the review checklist skill when the refactor is done, and with the commit message writer for the commit itself. A refactor that changes a public interface is not a refactor, and belongs in its own change.
What a skill is, every load location and the full frontmatter reference is the Claude Code skills guide. The rest of the library, including the review and commit skills this one pairs with, is at the skills examples hub.
Where these answers come from
- Extend Claude with skills, read November 25, 2026: the folder and file, the frontmatter fields used here, invocation control,
allowed-tools, the content lifecycle, where skills load and live change detection. - Claude stops following a skill: why one-time wording is dropped, and when the right fix is a hook instead.
- The changelog: release 2.1.332, dated November 25, 2026, the newest listed on the day this page was checked.
Common questions
Why is it manual-only?
Because it edits files. Anthropic recommends disable-model-invocation: true for workflows with a side effect or a timing you want to control, and "Claude decided to restructure a module because I asked an unrelated question" is the failure that rule prevents.
What if the tests are already failing?
The file tells it to stop and name them. That is deliberate: with a red suite you cannot tell a regression you caused from one that was already there, and the refactor becomes a debugging session in disguise.
Will it fix the bugs it finds along the way?
Not unless you ask for one in the same message, and then it is no longer a refactor. Note the bug, finish the refactor, and fix the bug as its own change with the debugging skill.
Can it rename something used across the repository?
Yes, if you name it. The grep finds the call sites, the build and the type checker find the ones the grep missed, and the suite tells you the behaviour survived the rename.