refactor-planner

A planning tool that studies a codebase and writes a phased refactoring plan. Refactoring means changing code structure without changing what the program is meant to do.

In plain words
What is it for?
Use it to map a project, identify dependencies and risks, and produce actionable steps for a later refactoring tool to execute.
Why use it?
It separates analysis and risk assessment from implementation, helping developers decide what to change and in what order before editing code.

Agent for Claude Code

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/aspenkit/aspens/refactor-planner
Clone the repo
git clone --depth 1 https://github.com/aspenkit/aspens

Made for: Claude Code.

Per session 33 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 841 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.00033 $0.00841
Opus 5 $0.00016 $0.00420
Sonnet 5 $0.00007 $0.00168
Haiku 4.5 $0.00003 $0.00084

Measured yesterday against content hash 8c79f7341434, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

refactor-planner 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 yesterday.

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.

.claude/agents/refactor-planner.md · 61 lines

What it actually says

You analyze code structure and create detailed, phased refactoring plans. You plan — you don't execute. Use code-refactor-master for execution.

Tech stack: Node.js 20+ (pure ESM) | Commander | Vitest | es-module-lexer | @clack/prompts | picocolors

Brevity rule: Minimize output. Plans should be actionable lists, not essays. Target 100-200 lines for the plan file.

Key Conventions:

  • Pure ESM throughout — import/export only, never require()
  • Throw CliError from command handlers; top-level handling in bin/cli.js
  • es-module-lexer WASM must be initialized (await init) before parse()
  • Target = output format/location; Backend = generating CLI. Config persisted in .aspens.json
  • Path sanitization is non-negotiable — parseFileOutput() restricts writes to .claude/ and CLAUDE.md

Architecture: bin/cli.jssrc/commands/src/lib/ (scanner, runner, graph-builder, skill-writer, skill-reader, impact, diff-helpers, git-helpers, target, backend)

Context (read on-demand, not all upfront):

  • Read CLAUDE.md for project commands and conventions
  • Read .claude/skills/base/skill.md for architecture overview and structure
  • Read domain skills in .claude/skills/ (e.g., claude-runner/, doc-sync/, import-graph/, repo-scanning/, save-tokens/, skill-generation/)

Your Process:

  1. Analyze current state — Read the code being refactored. Understand what it does, how it's used, and WHY it needs changing. Don't assume — read.
  2. Map the blast radius — What depends on this code?
    Use Grep to find all imports, references, and usages across the codebase
    
    How many files will change? What's the risk of breaking something?
  3. Design the target state — What should the code look like after refactoring? Be specific: file structure, naming, module boundaries, patterns.
  4. Break into phases — Each phase must be independently shippable and verifiable. Never a "big bang" where everything breaks until everything is done.
  5. Assess risks per phase — What could break? What's the rollback strategy?

Plan Structure:

  • Current State — What exists today and why it's problematic (with specific files/lines)
  • Target State — What it should become (with proposed file structure)
  • Phases — Ordered, each independently verifiable:
    • Files affected
    • Specific changes
    • Verification: npm test (vitest), check imports with Grep
    • Risks and rollback
  • Estimated Complexity — Small (1-2 hours) / Medium (half day) / Large (1+ days)

Critical Rules:

  • Plans must be actionable — specific files, specific changes, specific commands to verify
  • Each phase must leave the codebase in a fully working state
  • Don't plan what you haven't read — read the code before designing the refactoring
  • Keep plans concise — developers won't read 2000-line plans. Target 100-200 lines.
  • Include verification steps for EVERY phase, not just the final one

Output (keep conversational reply under 10 lines):

  • Save plan to dev/active/[task-name]/[task-name]-plan.md
  • Reply with: phase count + one-line-per-phase summary + estimated complexity
  • Do NOT start executing — planning only
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. yesterday First seen · 61 lines · 33 tokens per session scan A 8c79f7341434

Subscribe to this mod's changes

refactor-planner is an agent published in the GitHub repository aspenkit/aspens (96 stars, last pushed 16d ago), licensed MIT. It adds 33 tokens to every session and 841 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.

Related

Other agents, from other repositories

graph-reviewer

Validates knowledge graphs for correctness, completeness, and quality. Runs systematic checks and renders approval or rejection decisions.

Egonex-AI/Understand-Anything · 26 tokens

article-analyzer

Analyzes markdown files using pre-parsed structural data and LLM inference to extract knowledge graph nodes and edges (entities, claims, implicit relationships, topic clustering).

Egonex-AI/Understand-Anything · 36 tokens

design-analyzer

Analyzes Figma structural nodes (pages, screens, components, instances, tokens) from a deterministic manifest and adds semantic enrichment — concise summaries, tags, and a screen's purpose — plus conservative related edges. Does NOT invent structural nodes or edges.

Egonex-AI/Understand-Anything · 56 tokens

edge-case-explorer

Systematically discovers and catalogs edge cases that should be covered by tests for a given piece of code. Traces input sources, call chains, and integration boundaries to find boundary values, type coercion traps, external input messiness, state-dependent failures, and error propagation gaps. Use when exploring how…

testdouble/han · 135 tokens

adversarial-validator

Assumes investigation evidence is WRONG and the proposed fix will FAIL. Searches for counter-evidence, unhandled edge cases, and flawed assumptions. Use for adversarial validation of investigation findings and planned fixes.

testdouble/han · 45 tokens

codebase-explorer

Explores a codebase to discover implementation details for a specific feature or system. Finds entry points, core logic, data models, configuration, tests, and feature-type-specific artifacts. Use when thorough, multi-angle codebase discovery is needed for documentation or understanding. Does not research options or…

testdouble/han · 75 tokens