ToolMaster refactor
Refactor code for clarity, maintainability, and performance. Use when simplifying complex functions, extracting patterns, or reducing duplication.
install
source · Clone the upstream repo
git clone https://github.com/techieharry/ToolMaster
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/techieharry/ToolMaster "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/refactor" ~/.claude/skills/techieharry-toolmaster-refactor && rm -rf "$T"
manifest:
skills/refactor/SKILL.mdsource content
Refactor
When to refactor
- Function is over 50 lines
- Same pattern appears 3+ times
- You need a comment to explain what code does (the code should say it)
- Changing one thing requires changing many files
- Tests are hard to write for this code
Process
- Ensure tests exist — never refactor without a safety net
- Identify the smell — name what's wrong (duplication, coupling, complexity)
- Apply one transformation — extract function, rename, inline, split
- Run tests — verify nothing broke
- Repeat — one small change at a time, never big-bang refactor
Common refactors
- Extract function — pull a named chunk out of a long function
- Rename — make names match what code actually does
- Inline — remove unnecessary abstraction that adds indirection without value
- Split module — break a file doing 3 things into 3 files doing 1 thing each
- Replace conditional with polymorphism — when if/else chains map to types
Rules
- Refactor OR add features. Never both in the same commit.
- The behavior must not change. Refactoring is restructuring, not rewriting.
- If you're not sure the tests cover it, don't refactor it.
- Three similar lines is better than a premature abstraction.