how-to-plan-refactor

how-to-plan-refactor is a skill for Claude Code from xdg/xdg-claude. It costs 51 tokens per session (579 once invoked), scanned A, original, Apache-2.0.

A guide for deciding how to handle requests about improving code structure. It distinguishes requests for finding refactoring opportunities from requests to carry out one specific refactoring.

In plain words
What is it for?
Use it when someone asks what should be refactored, where code smells exist, or whether to plan improvements before making changes.
Why use it?
It helps route broad code-quality analysis and focused code changes to the appropriate workflow.

Skill for Claude Code

Written for Claude Code: user-invocable in frontmatter. Also seen: mentions subagents.

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

Good fit Use it when someone asks what should be refactored, where code smells exist, or whether to plan improvements before making changes.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/xdg/xdg-claude/how-to-plan-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.

Any agent
npx skills add xdg/xdg-claude --skill how-to-plan-refactor
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 how-to-plan-refactor

README.md
[![agentmods](https://agentmods.dev/badge/skills/xdg/xdg-claude/how-to-plan-refactor/github.svg)](https://agentmods.dev/skills/xdg/xdg-claude/how-to-plan-refactor)
Your own site
<a href="https://agentmods.dev/skills/xdg/xdg-claude/how-to-plan-refactor"><img src="https://agentmods.dev/badge/skills/xdg/xdg-claude/how-to-plan-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 how-to-plan-refactor

Your own site · 80×15
<a href="https://agentmods.dev/skills/xdg/xdg-claude/how-to-plan-refactor"><img src="https://agentmods.dev/badge/skills/xdg/xdg-claude/how-to-plan-refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 51 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 579 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.00051 $0.00579
Opus 5 $0.00026 $0.00290
Sonnet 5 $0.00010 $0.00116
Haiku 4.5 $0.00005 $0.00058

Measured 10d ago against content hash a174d7825ee7, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-10, from the pricing page.

Security

Grade A, and why

how-to-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 10d 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/skills/how-to-plan-refactor/SKILL.md · 42 lines

How it starts

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

Handling refactoring-planning requests

Delegate to the plan-refactor subagent (Agent tool, subagent_type: plan-refactor) when the user wants analysis of refactoring opportunities — not execution. The subagent scans for code smells (duplication, long methods, complex conditionals, poor naming, magic values, dead code, tight coupling, data clumps) and returns a prioritized list under a strict 400-word budget.

For executing a specific refactoring, use refactor instead — see how-to-refactor.

When to delegate vs. handle inline

Delegate when:

  • The user asks "what should I refactor?", "find code smells", "where can this be improved?", "analyze this for refactoring opportunities".
  • The user wants prioritized recommendations before deciding what to act on.
  • The scope is large enough (a file, directory, or module) that reading inline would burn context.

Handle inline (do not delegate) when:

  • The user is asking about a specific identified problem ("is this function too long?") — that's a single judgment, not a survey.
  • The scope is a short snippet already visible in conversation.
  • The user is asking for design feedback or architectural input rather than refactoring opportunities — that is conversation, not scanning.

Crafting the delegation prompt

State the scope. The subagent's defaults handle priority and reporting format — don't reproduce them.

Examples:

  • User: "what should I refactor?" → Delegate with empty prompt if the working set is the implicit scope; otherwise ask the user to narrow scope first.
  • User: "find smells in src/api/" → "Analyze src/api/ for refactoring opportunities."
  • User: "analyze the auth module" → "Analyze the auth module (src/auth/) for refactoring opportunities."
  • User: "review my uncommitted changes for refactor opportunities" → "Analyze the uncommitted changes (staged + unstaged) for refactoring opportunities."

Anti-patterns

  • Delegating without a scope when the working set is unclear. Ask the user to point at something first.
  • Asking the subagent to fix what it finds. It only recommends; pass items to the refactor subagent for execution.
  • Expecting an exhaustive list. The subagent caps output at 10 items and 400 words — top opportunities only.
  • Delegating for tiny scopes (a single short function). The signal-to-overhead is poor.

Read the full file on GitHub · 42 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. 10d ago First seen · 42 lines · 51 tokens per session scan A a174d7825ee7

Subscribe to this mod's changes

how-to-plan-refactor is a skill published in the GitHub repository xdg/xdg-claude (20 stars, last pushed 3d ago), licensed Apache-2.0. It adds 51 tokens to every session and 579 once invoked, about $0.0003 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.