refactorer

refactorer is an agent for coding agents from mehrad-dm/mastermind. It costs 86 tokens per session (875 once invoked), scanned A, original, MIT.

A code-refactoring agent that reorganizes working software while keeping its behavior unchanged. Refactoring means improving the internal design without changing what users see.

In plain words
What is it for?
Use it to split up complex code, improve data structures, separate dependencies, and apply named refactoring patterns while preserving behavior.
Why use it?
It reduces design and architecture problems in code that already works, such as tangled dependencies, oversized modules, and unclear data models.

Agent

Part of the mastermind plugin — 23 skills, 4 agents, 1 hook shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/mehrad-dm/mastermind/refactorer
Clone the repo
git clone --depth 1 https://github.com/mehrad-dm/mastermind

Or install mastermind, the plugin that ships this one along with the rest of its 23 skills, 4 agents, 1 hook.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for refactorer

README.md
[![agentmods](https://agentmods.dev/badge/agents/mehrad-dm/mastermind/refactorer.svg)](https://agentmods.dev/agents/mehrad-dm/mastermind/refactorer)
Your own site
<a href="https://agentmods.dev/agents/mehrad-dm/mastermind/refactorer"><img src="https://agentmods.dev/badge/agents/mehrad-dm/mastermind/refactorer.svg" alt="Measured on agentmods" height="20"></a>
Per session 86 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 875 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00086 $0.00875
Opus 5 $0.00043 $0.00438
Sonnet 5 $0.00017 $0.00175
Haiku 4.5 $0.00009 $0.00088

Measured 4d ago against content hash 59412a987537, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

refactorer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

agents/refactorer.md · 56 lines

How it starts

The opening of the file, as written. The whole thing — 56 lines — stays where its author put it; the contents beside it link to each section on GitHub.

You are the MasterMind refactorer. You improve the design of code that already works, without changing what it does. Fowler's discipline: "make the change easy, then make the easy change." This is not a bug hunt (that's code-reviewer) and not surface tidying (that's /simplify); it's structural redesign toward the standard in core/mindset.md and core/principles.md.

Load first

Read ~/.mastermind/engineering/core/principles.md, ~/.mastermind/engineering/core/mindset.md, and the active field's stack-defaults.md.

Reference catalog (field-agnostic)

You have no web tools: work from the vocabulary you already carry, not from a fetch. The canonical catalog is Fowler's refactorings + code smells + the GoF patterns: name the move you're making (extract function · inline · move method · replace conditional with polymorphism · introduce parameter object · replace temp with query) and the smell you're removing (long function · large class · feature envy · shotgun surgery · primitive obsession · data clump). Naming it keeps the change deliberate and reviewable. Use it as vocabulary, not a checklist: a pattern earns its place only if it makes the code simpler: otherwise you've added indirection and called it design.

In React/frontend, prefer composition-first idioms: composition over inheritance, children and slots over configuration flags, hooks for shared behavior, lifting state only as far as it must go. Inheritance-heavy GoF solutions are usually the wrong fit there. The active field's curriculum.md and lessons.md are readable locally and are the field-specific authority; prefer them over recall.

(Human reference, not fetchable from here: refactoring.guru for the catalog, patterns.dev for the frontend patterns.)

Non-negotiable: behavior is preserved

  • Safety net first. Confirm tests cover the target and pass. If a risky area is untested, say so and get a yes before writing characterization tests: a suite is the user's call, not yours (~/.mastermind/engineering/core/rigor.md). If they decline, restrict the refactor to what typecheck, lint and driving the flow can verify, or hand it back as Not done. No way to prove behavior is unchanged → build the proof first; an unverifiable refactor is a rewrite.
  • One at a time: structure or behavior. If you spot a bug mid-refactor, note it and leave it for its own change: a silent fix hides a behavior change inside a "refactor".

Read the full file on GitHub · 56 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 56 lines · 0 tokens per session scan A 59412a987537

Subscribe to this mod's changes

refactorer is an agent published in the GitHub repository mehrad-dm/mastermind (24 stars, last pushed 4d ago), licensed MIT. It adds 86 tokens to every session and 875 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other agents, from other repositories

code-reviewer

Reviews code for project guideline compliance, bugs, and quality issues. Use after writing code, before commits, or before PRs. Specify files to review or defaults to unstaged git changes. High-confidence issues only (80+) to minimize noise.

coleam00/Archon · 53 tokens

codebase-analyst

Use proactively to understand HOW code works. Analyzes implementation details, traces data flow, and documents technical workings with precise file:line references. The more specific your request, the better the analysis.

coleam00/Archon · 46 tokens

plan-creator

Use this agent to create comprehensive strategic plan documents combining business strategy and technical architecture. Specializes in context gathering, YAGNI enforcement, and producing actionable blueprints with visual communication.

e0ipso/strikethroo · 40 tokens

code-stealer-detector

Adversarial code-provenance auditor. Use when reviewing PRs, accepting AI-generated code, doing M&A due diligence, or before going open-source. Detects copy-pasted Stack Overflow snippets, copyleft contamination, leaked private code, and AI-generated code with unverified provenance.

sifxprime/kodelyth-ecc · 64 tokens

kodelyth-advisor

Master engineering advisor — Kodelyth. A decade-seasoned principal engineer who has architected systems at $300B-scale companies. Reads between the lines, feels what the user is struggling with, and gives precise, senior-grade direction instantly. No hand-holding, no noise — just the exact answer. Use when you need…

sifxprime/kodelyth-ecc · 83 tokens

incident-commander

Production incident response specialist — Kodelyth. A decade-seasoned SRE who has led incident response at $300B-scale companies. Runs the triage, containment, communication, and postmortem for active production incidents. Stays calm when everything is on fire. Knows exactly what to do, in what order, and who to tell.…

sifxprime/kodelyth-ecc · 87 tokens