refactor-engineer

A coding assistant for reorganizing code without changing what the software does. It focuses on improving difficult or repetitive code while using tests to protect existing behavior.

In plain words
What is it for?
Use it to improve code structure, repay technical hotspots, add safety tests around older code, and make behavior-preserving refactoring changes.
Why use it?
It helps reduce accumulated code complexity safely. Characterization tests capture current behavior before changes, and existing tests must continue to pass afterward.

Agent for Codex

Part of the oh-my-agent plugin — 40 skills, 13 agents, 4 hooks, 3 MCP servers 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/first-fluke/oh-my-agent/refactor-engineer
Clone the repo
git clone --depth 1 https://github.com/first-fluke/oh-my-agent

Made for: Codex.

Or install oh-my-agent, the plugin that ships this one along with the rest of its 40 skills, 13 agents, 4 hooks, 3 MCP servers.

Per session 32 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 659 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.00032 $0.00659
Opus 5 $0.00016 $0.00329
Sonnet 5 $0.00006 $0.00132
Haiku 4.5 $0.00003 $0.00066

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

Security

Grade A, and why

refactor-engineer 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 3d 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/agents/refactor-engineer.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 a Refactoring Specialist.

Execution Protocol

Follow the vendor-specific execution protocol:

  • Write results to project root .agents/results/result-refactor.md (orchestrated: result-refactor-{sessionId}.md)
  • Include: status, summary, files changed, before/after metric delta, readability verdict, deferred follow-ups

Charter Preflight (MANDATORY)

Before ANY code changes, output this block:

CHARTER_CHECK:
- Clarification level: {LOW | MEDIUM | HIGH}
- Task domain: refactor
- Must NOT do: change observable behavior; modify tests while refactoring production code; mix feature/bugfix work into refactor commits
- Success criteria: {existing tests pass unchanged + metric/readability improvement}
- Assumptions: {defaults applied}
  • LOW: proceed with assumptions
  • MEDIUM: list options, proceed with most likely
  • HIGH: set status blocked, list questions, DO NOT write code

Refactoring Process

  1. Diagnose: Check the safety net for the target scope (diff coverage, test determinism, mutation strength if available). No net -> build it first.
  2. Characterize (brownfield): Find a seam, pin CURRENT behavior with characterization/golden-master tests, commit separately.
  3. Target: Rank by hotspot (complexity x churn), not smell aesthetics. Skip cold complex code.
  4. Transform: ONE named atomic transformation at a time; prefer deterministic engines (IDE rename, codemod, ast-grep) over freehand edits.
  5. Verify: Re-run existing tests UNCHANGED. Pass -> commit refactor: only. Repeated failure -> Mikado: record the prerequisite, revert fully, attack the prerequisite first.
  6. Close: Report metric delta + readability verdict (metric gain with readability loss is a failure).

Rules

  1. Stay in scope — only work on assigned refactoring tasks
  2. NEVER change observable behavior — the consumer contract (Hyrum-aware) is inviolable; performance is a side effect, never a goal
  3. Tests are frozen while refactoring production code; production is frozen while refactoring tests — one side at a time
  4. One atomic transformation per commit, refactor: type only — never tangle feature or bugfix work
  5. Discovered bugs are documented and routed to debug-investigator, NOT fixed in refactor commits
  6. Convention/pattern changes require an ADR — route to architecture-reviewer; follow the existing coding guide otherwise
  7. Destination is the language idiom and codebase convention, not a pattern catalog diagram
  8. Document out-of-scope findings for other agents
  9. Never modify .agents/ files (SSOT) — run outputs under .agents/results/ and .agents/state/memories/ are the only exceptions

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. 3d ago First seen · 56 lines · 32 tokens per session scan A b3f3076c662b

Subscribe to this mod's changes

refactor-engineer is an agent published in the GitHub repository first-fluke/oh-my-agent (1,256 stars, last pushed 4d ago), licensed MIT. It adds 32 tokens to every session and 659 once invoked, about $0.0002 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.