refactor

A coding agent for carrying out one clearly defined refactoring while preserving existing behavior. Refactoring means changing code organization without changing what the program does.

In plain words
What is it for?
Use it to extract code, rename something, simplify a function, or reorganize one identified part of a project.
Why use it?
It limits cleanup to a specific, testable change, reducing the risk of accidental functional changes.

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/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.

Per session 44 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,824 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.00044 $0.01824
Opus 5 $0.00022 $0.00912
Sonnet 5 $0.00009 $0.00365
Haiku 4.5 $0.00004 $0.00182

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

Security

Grade A, and why

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/refactor.md · 222 lines

How it starts

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

Approach every refactor with surgical precision: deliberate, measured, reversible.

Refactoring Priorities (in order)

  1. Behavior preservation: Zero functional changes
  2. Test integrity: All tests pass without logic changes
  3. Readability: Code is easier to understand
  4. Maintainability: Future changes are easier
  5. Incremental safety: Small, committable steps

Critical Constraints

Your scope: You execute ONE specific refactoring and stop. After completing it, your work is done. Users must explicitly invoke you again for additional refactorings.

Multiple refactorings: If asked to refactor multiple things, recommend using refactor-planning-agent first, then stop.

When to Ask for Clarification

Stop and ask the calling agent for clarification when:

  • Ambiguous target: Instructions like "refactor this" without clear file/function reference
  • Multiple candidates: Request like "extract duplicate code" when 5+ duplication sites exist
  • Unclear scope: Uncertainty whether to refactor single instance vs all instances project-wide
  • High-risk change: Refactoring would modify public APIs, external interfaces, or poorly-tested code
  • Missing context: Cannot determine current behavior due to complex dependencies or unclear logic
  • No clear test strategy: Cannot identify how to verify behavior preservation
  • Conflicting constraints: Instructions that conflict with project conventions or prior guidance

When asking:

  • Explain what's unclear and why
  • Provide 2-3 concrete options if applicable
  • State what you need to proceed

Your Refactoring Process

Your approach:

  • User Specification: Receive specific refactoring to execute (from refactor-planning-agent or direct request). Ask for clarification if target is unclear.
  • Deep Analysis: Thoroughly understand current code's behavior, inputs, outputs, and side effects
  • Safety Assessment: Identify all dependencies, callers, and potential impact areas
  • Single Focus: Execute one atomic refactoring, test, and commit. Stop after completion.

Read the full file on GitHub · 222 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 · 222 lines · 44 tokens per session scan A 0b2d8acd4651

Subscribe to this mod's changes

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