code-refactorer
Expert code refactoring that strictly preserves existing behavior.
Skill by mthalman
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/mthalman-code-refactorer
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: design
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/code-refactorer
What's inside
- Skill name
code-refactorer- Description
- Expert code refactoring that strictly preserves existing behavior. Use when asked to refactor code, improve code structure, reduce duplication, extract methods/classes/modules, simplify complex conditionals, improve naming, apply design patterns, reduce complexity, clean up code, make code more maintainable/readable/testable, decompose large functions/classes, or find cross-file patterns and commonalities to consolidate. Language-agnostic. Triggers on requests like "refactor this", "clean up this code", "this function is too long", "reduce duplication", "simplify this logic", "make this more maintainable", "make this more object-oriented", "apply design patterns", "find common patterns", or "what can be consolidated across files".
- License
- MIT
- Instructions
- 130 lines in SKILL.md · view on GitHub
Files (4)
- SKILL.md
- cross-file-discovery.md · references/
- refactoring-catalog.md · references/
- risk-gate.md · references/
SKILL.md (first lines)
# Code Refactorer Expert, behavior-preserving code refactoring across languages and paradigms. The default stance is restraint: refactor only when the structure is the real problem and the risk is understood. ## Core principles 1. **Preserve behavior exactly.** Change structure, not semantics. Document bugs you find; fix them only when explicitly asked. 2. **Assess before changing.** "Do not refactor" and "document instead" are valid expert outputs. 3. **Refactor incrementally.** Apply one named refactoring at a time, leaving the code working after each step. 4. **Verify with tests.** Run relevant tests before and after. If tests are absent, identify characterization tests before risky edits. 5. **Respect local style.** Match naming, formatting, idioms, and architecture. 6. **Minimize blast radius.** Prefer fewer files and lines. Avoid cascading renames or public API changes unless requested. 7. **Use proportionality.** Do not add heavyweight patterns to low-risk code or quick-fix refactors to high-risk code. ## Step 0: appropriateness gate Before editing, inspect code-observable signals: - **Caller count:** high caller count amplifies migration risk. - **Test coverage:** no tests plus many callers means strategy first. - **Age and stability:** old, stable code may encode hard-won constraints. - **Behavioral coupling:** ordered state changes, external calls, retry policy, logging checkpoints, or state machines often encode coordination. - **Performance sensitivity:** tight loops, benchmarks, SLA comments, allocation avoidance, or early exits need quantified risk. | Signal | Response | |---|---| | Behavioral coupling plus long stability | Do not refactor by default. Explain the structure instead. | | Many callers plus no tests | Strategy only: characterization tests, then phased migration. | | Performance-critical hot path | Quantify `per-call overhead × call volume` before recommending extraction. | | Recent code, few dependents, experimental branch | Lightweight naming, deduplication, or simplification only. | | Adequate tests, moderate callers, clear structural issues | Proceed with the standard workflow. | Always enumerate 3-4 candidate approaches, including **do nothing** and **document only**, with acceptance or rejection rationale. For the recommended approach, name branch points: "If X changes, switch to Y." If refactoring is mandatory despite risk, propose a conservative contingency such as a shadow implementation or gradual rollout. ## Step 1: adapt to risk - **High blast radius:** treat as migration. Add characterization tests, keep the public interface stable, extract internals, add a new interface, migrate callers one by one. - **Hot paths:** prefer zero-overhead improvements first. Do not extract helper calls inside tight loops without benchmarks. Preserve early exits unless data proves the cost is acceptable. - **Behavioral coupling:** investigate why order, timing, retry, and logging differ. Default to documentation or naming improvements that preserve control flow exactly. Open `references/refactoring-catalog.md` when you need the smell catalog, category guidance, OOP pattern guidance, language notes, or before/after examples for a candidate refactoring. Open `references/cross-file-discovery.md` when the request asks to find commonalities across files, consolidate patterns, create shared utilities/base classes, or reduce codebase-wide duplication. Open `references/risk-gate.md` when the gate involves old stable code, high caller count, low coverage, hot paths, behavioral coupling, or mandatory-risk contingencies. ## Standard workflow Use this only after the gate permits refactoring. 1. **Analyze:** read the target code and immediate dependencies. Identify smells, complexity hotspots, and test coverage. 2. **Diagnose:** categorize problems and prioritize by impact and risk. 3. **Plan:** propose a sequence of named refactorings. Check contraindications, alternatives rejected, trade-offs, and rollback points. 4. **Execute:** apply one refactoring at a time. After each step, confirm the code parses or compiles. 5. **Verify:** run tests after each logical group and compare before/after behavior. 6. **Summarize:** list each refactoring, what changed, why, validation run, and any behavior explicitly preserved. ## Compact decision tree - **Function too long:** extract cohesive clusters into intent-named methods. - **Duplicated code:** extract shared logic; for near-duplicates, parameterize the varying parts. Wait for a third short instance unless the duplication is already costly. - **Hard to understand:** rename, extract helpers, replace magic values, and simplify nesting with guard clauses. - **Class does too much:** split cohesive responsibilities and reconnect with composition. - **Cannot test:** break hidden dependencies with interfaces, dependency injection, or pure-function extraction. - **Complex conditionals:** use guard clauses and named predicates; use polymorphism only when branches repeat and there are enough variants. - **Cross-file consolidation:** run cross-file discovery before proposing a shared abstraction. - **More object-oriented / design patterns:** apply a pattern only when it solves a concrete structural problem and earns the indirection. - **General cleanup:** remove verified dead code, improve naming, extract long methods, reduce duplication, then simplify conditionals. ## Validation and rollback - Capture the baseline test/build command before editing when feasible. - Prefer the smallest validation that covers the changed behavior; escalate when public APIs, shared utilities, or many callers changed. - If validation fails, determine whether your refactor changed behavior. Revert or narrow the step before continuing. - Preserve public signatures for high-caller or low-test code. Add adapters or overloads instead of breaking callers. - Report missing tests as risk, not proof of correctness. ## Output contract
From mthalman/agents, MIT.
More from mthalman/agents
- 0.592score
dispatching-parallel-agents
mthalman
Use when facing 2+ substantial tasks that can run without shared state or sequential dependencies, or when a high-value uncertain task justifies an explicitly…
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
claude-extension-type-identifier
mthalman
Use when determining what type of Claude Code extension (command, skill, or agent) a prompt or description should be classified as.
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
logo-design
mthalman
Use when designing logos, creating brand marks, or helping with visual identity work - provides expert logo design process including discovery, strategic…
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
manual-worktree-session
mthalman
Create a Git worktree manually and attach an in-place Copilot child session when large repositories such as the dotnet VMR exceed native session/worktree…
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
azure-pipeline-monitor
mthalman
Monitor an Azure DevOps (ADO) pipeline run to completion — the whole run or a single stage/job — using a blocking poller that estimates expected duration from…
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
markdown-toolkit
mthalman
Use when generating or validating GitHub Flavored Markdown structure and mechanics, including headings, links, tables, lists, code fences, anchors, templates…
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
code-reviewer
mthalman
Review code changes for correctness, performance, safety, and quality when the user explicitly asks for a code review.
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
copilot-pr-review
mthalman
Full GitHub Copilot PR review feedback loop — add Copilot as reviewer, poll for review, respond to comments, resolve threads, re-request review, and repeat…
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
defend-the-diff
mthalman
Interrogate an existing code change through focused questions, evidence-backed answers, and independent judgment so the change is explainable, correct…
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
designing-ui-color
mthalman
Use when selecting colors for interfaces, evaluating color combinations, creating palettes, resolving stakeholder color conflicts, or when colors "feel wrong"…
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
designing-ui-typography
mthalman
Use when designing typography for web/app interfaces, selecting fonts, setting up type scales, addressing performance/accessibility concerns, or handling…
SkillAFreshness: A★ 1Claude Code +9 - 0.587score
blast-radius
mthalman
Analyze what a proposed or completed code change could break outside the visible diff, identify the small set of safety assumptions the change depends on, and…
SkillAFreshness: A★ 1Claude Code +9
Signals
- Stars
- 1
- Forks
- 0
- Open issues
- 26
- Last commit (this folder)
- Oct 6, 2026 (22 days ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/mthalman/agents
- Website
- mthalman.github.io/agents/
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from mthalman
- 0.592score
claude-extension-type-identifier
mthalman
Use when determining what type of Claude Code extension (command, skill, or agent) a prompt or description should be classified as.
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
code-reviewer
mthalman
Review code changes for correctness, performance, safety, and quality when the user explicitly asks for a code review.
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
manual-worktree-session
mthalman
Create a Git worktree manually and attach an in-place Copilot child session when large repositories such as the dotnet VMR exceed native session/worktree…
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
azure-pipeline-monitor
mthalman
Monitor an Azure DevOps (ADO) pipeline run to completion — the whole run or a single stage/job — using a blocking poller that estimates expected duration from…
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
logo-design
mthalman
Use when designing logos, creating brand marks, or helping with visual identity work - provides expert logo design process including discovery, strategic…
SkillAFreshness: A★ 1Claude Code +9 - 0.592score
copilot-pr-review
mthalman
Full GitHub Copilot PR review feedback loop — add Copilot as reviewer, poll for review, respond to comments, resolve threads, re-request review, and repeat…
SkillAFreshness: A★ 1Claude Code +9
Cite this page
code-refactorer skill. Agent Mart. https://agentmart.dev/skills/mthalman-code-refactorer (last updated 2026-10-24)