refactor

refactor is an agent for Claude Code from xdg/xdg-claude. It costs 44 tokens per session (1,824 once invoked), scanned A, original, Apache-2.0.

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 for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: model in frontmatter; mentions CLAUDE.md.

Part of the refactoring-agent plugin — 4 skills, 2 agents shipped together

Good fit Use it to extract code, rename something, simplify a function, or reorganize one identified part of a project.

Compare 6 agents from other repositories ↓
Install with agentmods
npx agentmods add agents/xdg/xdg-claude/refactor
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.

Clone the repo
git clone --depth 1 https://github.com/xdg/xdg-claude

Made for: Claude Code.

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 refactor

README.md
[![agentmods](https://agentmods.dev/badge/agents/xdg/xdg-claude/refactor/github.svg)](https://agentmods.dev/agents/xdg/xdg-claude/refactor)
Your own site
<a href="https://agentmods.dev/agents/xdg/xdg-claude/refactor"><img src="https://agentmods.dev/badge/agents/xdg/xdg-claude/refactor/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for refactor

Your own site · 80×15
<a href="https://agentmods.dev/agents/xdg/xdg-claude/refactor"><img src="https://agentmods.dev/badge/agents/xdg/xdg-claude/refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
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. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00044 $0.01824
Opus 5.5 $0.00018 $0.00730
Sonnet 5.5 $0.00009 $0.00365
Haiku 4.5 $0.00004 $0.00182

Measured 2mo ago against content hash 0b2d8acd4651, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, 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 2mo 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. 2mo 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 6d 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.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

refactor compared with agents from other repositories

refactor next to 6 agents from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
refactorxdg/xdg-claudeAgent206d agoApache-2.0A44Claude Code
cpp-revieweraffaan-m/ECCAgent298k5d agoMITA41Claude Code, Kiro
thermo-nuclear-code-quality-review-subagentmichael-denyer/pstack-claudeAgent4.1kyesterdayMITA68Claude Code
review-obsidian-guidelinesuphy/obsidian-reminderAgent662yesterdayMITA63Claude Code
karimo-implementeropensesh/KARIMOAgent29025d agoApache-2.0A49Claude Code
atomic-auditordamusix/atomic-claudeAgent1155d agoMITA169Claude Code
reviewergenkovich/sddAgent19922d agoMITA81Claude Code