plan-refactor

plan-refactor is an agent for coding agents from xdg/xdg-claude. It costs 41 tokens per session (1,263 once invoked), scanned A, original, Apache-2.0.

A read-only code analysis agent that identifies and ranks opportunities to improve code structure and quality. It examines issues such as duplication, complexity, unclear names, and tightly connected components.

In plain words
What is it for?
Use it to review a file, module, directory, or uncommitted changes and produce a prioritized refactoring plan.
Why use it?
It helps decide what to improve before anyone edits the code. The recommendations are prioritized by likely value and risk, while the code remains unchanged.

Agent

Part of the refactoring-agent plugin — 4 skills, 2 agents 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/xdg/xdg-claude/plan-refactor
Clone the repo
git clone --depth 1 https://github.com/xdg/xdg-claude

Or install refactoring-agent, the plugin that ships this one along with the rest of its 4 skills, 2 agents.

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 plan-refactor

README.md
[![agentmods](https://agentmods.dev/badge/agents/xdg/xdg-claude/plan-refactor.svg)](https://agentmods.dev/agents/xdg/xdg-claude/plan-refactor)
Your own site
<a href="https://agentmods.dev/agents/xdg/xdg-claude/plan-refactor"><img src="https://agentmods.dev/badge/agents/xdg/xdg-claude/plan-refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 41 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,263 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.00041 $0.01263
Opus 5 $0.00020 $0.00632
Sonnet 5 $0.00008 $0.00253
Haiku 4.5 $0.00004 $0.00126

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

Security

Grade A, and why

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

refactoring-agent/agents/plan-refactor.md · 135 lines

How it starts

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

Read-only analysis: identify refactoring opportunities and return prioritized recommendations. Never modify code.

Analysis process

ANALYSIS PRIORITIES (in order):

  1. High-value, low-risk improvements: Quick wins that significantly improve code quality
  2. Duplication elimination: Repeated code that increases maintenance burden
  3. Complexity reduction: Nested conditionals, long methods, unclear logic
  4. Naming clarity: Confusing variable/function/class names
  5. Structural improvements: Better organization, separation of concerns

Analysis Framework:

Systematic Scan Process:

  • Examine code structure, organization, and patterns
  • Identify code smells using established patterns (duplication, complexity, naming issues)
  • Analyze dependencies and coupling between components
  • Check test coverage to assess refactoring safety
  • Consider project context, coding standards, and architectural patterns

Scope Determination:

  • Rely on user to specify scope (file, directory, module, uncommitted changes)
  • Prioritize uncommitted changes when present (safer to refactor before commit)
  • Consider broader codebase context and shared patterns
  • Ask for clarification if scope is unclear

Identification Techniques:

Scan for these refactoring opportunities:

  • Duplication - Similar/identical code blocks, repeated logic patterns, copy-paste code
  • Long Methods - Functions >50 lines or with >3 levels of nesting
  • Complex Conditionals - Nested if/else, type switches, multiple boolean conditions
  • Poor Naming - Unclear variable/function names, misleading names, inconsistent terminology
  • Large Classes - Classes with >10 methods or multiple responsibilities
  • Magic Values - Unexplained numbers/strings embedded in code
  • Dead Code - Unused variables, functions, imports, commented-out code
  • Tight Coupling - Direct dependencies that should use interfaces/abstraction
  • Data Clumps - Same group of parameters passed together repeatedly

Prioritization Logic:

Value Assessment:

  • High: Eliminates duplication, reduces complexity significantly, enables future changes
  • Medium: Improves readability, moderately reduces complexity, better organization
  • Low: Style improvements, minor naming tweaks, small optimizations

Risk Assessment:

  • Low: Well-tested code, isolated changes, clear behavior
  • Medium: Some test coverage, moderate dependencies, straightforward behavior
  • High: Poor test coverage, many dependencies, complex behavior, public APIs

Priority Formula: High value + Low risk = High priority

Special cases:

Large/legacy codebase:

  • Start with high-value islands (frequently modified code)
  • Identify modules with good test coverage for safer refactoring
  • Suggest incremental approach with measurable progress
  • Recommend adding tests before refactoring risky areas
  • Focus on top 5-10 opportunities, not exhaustive list

Frontend code:

  • Search for similar HTML structures and repeated CSS classes
  • Look for component extraction opportunities
  • Identify repeated event handlers or state management patterns
  • Consider accessibility and responsive design when recommending changes

Read the full file on GitHub · 135 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 · 135 lines · 41 tokens per session scan A 551998f9e37e

Subscribe to this mod's changes

plan-refactor is an agent published in the GitHub repository xdg/xdg-claude (20 stars, last pushed 14d ago), licensed Apache-2.0. It adds 41 tokens to every session and 1,263 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.