refactor

A command for making a focused code refactor while preserving existing behaviour and following the project's documented decisions. A refactor changes code structure without intentionally changing what the software does.

In plain words
What is it for?
Use it to address duplication, oversized modules, performance hot paths, or code that conflicts with an architecture decision record.
Why use it?
It keeps cleanup from expanding into unrelated work and uses tests and project rules to reduce the risk of breaking behaviour.

Command

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 commands/ainsteinsbr/renata/refactor
Clone the repo
git clone --depth 1 https://github.com/AInsteinsBR/renata
Per session 24 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,291 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.00024 $0.01291
Opus 5 $0.00012 $0.00646
Sonnet 5 $0.00005 $0.00258
Haiku 4.5 $0.00002 $0.00129

Measured 2d ago against content hash 8bb126ad4bee, 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 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.

commands/refactor.md · 147 lines

How it starts

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

/renata:refactor — Guides a refactor following the project's patterns

You are a pragmatic senior engineer. You guide a refactor with controlled scope, safety through tests, and respect for ADRs.

A refactor is NOT "cleaning everything up". It is a disciplined change with a clear objective, preserved behavior, and easy rollback.

Respond to the user and generate content in the user's language (the language they are writing in).

When to use

  • The current code violates a recently created (or recently noticed) ADR.
  • A file/module grew too large (>400 lines / function >50 lines).
  • Duplication reached the point where the next change becomes a nightmare (rule of 3: the 3rd time you duplicate, make it a function).
  • A pattern emerged organically — a precondition for the next feature.
  • A performance audit identified a hot path that needs a redesign.

When NOT to use

  • ❌ "I want to touch it because I didn't like the code" without a concrete pain → not a refactor.
  • ❌ Refactor + new feature in the same branch → breaks atomicity. Do them in separate PRs.
  • ❌ Refactor without test coverage on the target code → write the test first, then refactor.
  • ❌ Refactor while in a critical release → postpone.

Before generating

  1. Read @CLAUDE.md and @docs/decisions/ (understand patterns and ADRs).

  2. Read the code to refactor (explicit scope — file, folder, or function).

  3. Ask ONE question at a time:

    • Target: which file/module/function will change?
    • Concrete pain: what problem does this code cause today? (1-2 examples)
    • Objective: after the refactor, what new/better capability exists?
    • ADRs involved: which ADR does this refactor implement? Or does it uncover a pending ADR?
    • Current test coverage: is there a test? What % covers the path being refactored?
    • Estimated effort: XS/S/M/L (an L+ refactor should be broken into pieces).
    • Risk if it breaks: what stops working? Who is affected?

Quality rules

Read the full file on GitHub · 147 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 · 147 lines · 24 tokens per session scan A 8bb126ad4bee

Subscribe to this mod's changes

refactor is a command published in the GitHub repository AInsteinsBR/renata (10 stars, last pushed 11d ago), licensed MIT. It adds 24 tokens to every session and 1,291 once invoked, about $0.0001 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-31.