refactor

refactor is a command for Claude Code from nmime/motiv-buy. It costs 0 tokens per session (1,824 once invoked), scanned A, original, MIT.

A command for refactoring only the files marked with @ in a user's request. It checks that each file exists, reads related code, and chooses an approach based on the project's structure and documentation.

In plain words
What is it for?
Use it to reorganize or improve named source files while considering nearby patterns, dependencies, and the project's documented conventions.
Why use it?
Refactoring can change behavior or miss surrounding dependencies if a file is handled in isolation. This command limits the target files and requires their surrounding code and project context to be examined first.

Command for Claude Code

Written for Claude Code: $ARGUMENTS substitution. Also seen: mentions CLAUDE.md; mentions subagents.

Good fit Use it to reorganize or improve named source files while considering nearby…

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/nmime/motiv-buy/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/nmime/motiv-buy

Made for: Claude Code.

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/commands/nmime/motiv-buy/refactor.svg)](https://agentmods.dev/commands/nmime/motiv-buy/refactor)
Your own site
<a href="https://agentmods.dev/commands/nmime/motiv-buy/refactor"><img src="https://agentmods.dev/badge/commands/nmime/motiv-buy/refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 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.00000 $0.01824
Opus 5 $0.00000 $0.00912
Sonnet 5 $0.00000 $0.00365
Haiku 4.5 $0.00000 $0.00182

Measured 2d ago against content hash 3e72bb9febac, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, 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 2d 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.

.claude/commands/refactor.md · 217 lines

How it starts

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

You are working on the current project. The user has requested to refactor specific files tagged with @ symbols in their arguments: "$ARGUMENTS"

Auto-Loaded Project Context:

@/CLAUDE.md @/docs/ai-context/project-structure.md @/docs/ai-context/docs-overview.md

Step 1: Parse Tagged Files

Extract all @ tagged file paths from the user's arguments. Only process files that are explicitly tagged with @ symbols.

Example parsing:

  • Input: "refactor @src/big-file.ts @components/Large.svelte"
  • Extract: ["src/big-file.ts", "components/Large.svelte"]

Step 2: Validate and Analyze Files

For each tagged file:

  1. Verify file exists - If file doesn't exist, inform user and skip
  2. Read file contents - Understand the structure and dependencies
  3. Analyze current directory structure - Map existing patterns around the file

Step 3: Intelligent Analysis Strategy Decision

Think deeply about the safest and most effective refactoring approach based on the auto-loaded project context. Based on the initial analysis from Step 2 and the auto-loaded project context, intelligently decide the optimal approach for each file:

Strategy Options:

Direct Refactoring (0-1 sub-agents):

  • Simple files with clear, obvious split points
  • Files with minimal external dependencies
  • Standard refactoring patterns (e.g., extract utils, split large classes)
  • Low risk of breaking changes

Focused Analysis (2-3 sub-agents):

  • Moderate complexity with specific concerns
  • Files with moderate dependency footprint
  • When one aspect needs deep analysis (e.g., complex dependencies OR intricate file structure)

Comprehensive Analysis (3+ sub-agents):

  • High complexity files with multiple concerns
  • Extensive dependency networks
  • Novel refactoring patterns not seen in project
  • High risk of breaking changes
  • Files that are central to multiple systems

Step 4: Execute Chosen Strategy

For Direct Refactoring:

Proceed with straightforward refactoring using the initial analysis and project context.

Read the full file on GitHub · 217 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. 2d ago First seen · 217 lines · 0 tokens per session scan A 3e72bb9febac

Subscribe to this mod's changes

refactor is a command published in the GitHub repository nmime/motiv-buy (0 stars, last pushed 7mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,824 tokens. 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-09-04.