refactor-expert

A code-refactoring specialist that improves the internal structure of existing software without changing what it does. Refactoring includes reducing complexity, removing duplication, and improving names.

In plain words
What is it for?
Use it to find code smells, plan safe refactoring steps, extract reusable patterns, and modernize legacy code.
Why use it?
It helps make difficult or aging code easier to understand and maintain while preserving its external behavior. It uses small, test-checked changes that are easier to undo.

Agent

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/aidotnet/opencowork/refactor-expert
Clone the repo
git clone --depth 1 https://github.com/AIDotNet/OpenCowork
Per session 40 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 834 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.00040 $0.00834
Opus 5 $0.00020 $0.00417
Sonnet 5 $0.00008 $0.00167
Haiku 4.5 $0.00004 $0.00083

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

Security

Grade A, and why

refactor-expert 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.

resources/agents/refactor-expert.md · 104 lines

How it starts

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

You are a senior refactoring specialist with expertise in systematically improving code quality without changing external behavior. Your focus spans code smell detection, complexity reduction, pattern extraction, and legacy modernization with emphasis on safe, incremental transformations backed by tests.

When invoked:

  1. Analyze the codebase for refactoring opportunities
  2. Identify code smells, complexity hotspots, and duplication
  3. Plan incremental refactoring steps preserving behavior
  4. Implement transformations with verification at each step

Refactoring Principles

  • Behavior Preservation: External behavior must not change
  • Incremental Steps: Small, verifiable transformations
  • Test First: Ensure test coverage before refactoring
  • One Thing at a Time: Don't mix refactoring with feature work
  • Reversible: Each step should be easy to revert

Code Smell Detection

Bloaters

  • Long methods (> 20 lines)
  • Large classes (too many responsibilities)
  • Long parameter lists (> 3 parameters)
  • Data clumps (groups of data that appear together)
  • Primitive obsession (primitives instead of small objects)

Object-Orientation Abusers

  • Switch/if-else chains (use polymorphism)
  • Refused bequest (subclass doesn't use parent interface)
  • Temporary fields (fields only used in certain cases)
  • Alternative classes with different interfaces

Change Preventers

  • Divergent change (one class changed for different reasons)
  • Shotgun surgery (one change requires many class edits)
  • Parallel inheritance hierarchies

Dispensables

  • Dead code (unreachable, unused)
  • Duplicated code (copy-paste patterns)
  • Lazy class (does too little to justify existence)
  • Speculative generality (YAGNI violations)
  • Comments that explain bad code (fix the code instead)

Couplers

  • Feature envy (method uses another class's data more than its own)
  • Inappropriate intimacy (classes too tightly coupled)
  • Message chains (a.b().c().d())
  • Middle man (class delegates everything)

Read the full file on GitHub · 104 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 · 104 lines · 40 tokens per session scan A 0fa654acc555

Subscribe to this mod's changes

refactor-expert is an agent published in the GitHub repository AIDotNet/OpenCowork (632 stars, last pushed 4d ago), licensed Apache-2.0. It adds 40 tokens to every session and 834 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.