refactor

A command for removing unused code and reorganizing code so it is easier to maintain. Dead code is code that is no longer used or cannot be reached.

In plain words
What is it for?
Use it to find unused exports, imports, variables, unreachable code, commented-out blocks, long functions, deep nesting, and hard-to-understand patterns.
Why use it?
It reduces clutter and duplication while checking that removals do not break builds, tests, public interfaces, or dynamically loaded code.

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/versoxbt/claude-initial-setup/refactor
Clone the repo
git clone --depth 1 https://github.com/VersoXBT/claude-initial-setup
Per session 10 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 429 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.00010 $0.00429
Opus 5 $0.00005 $0.00215
Sonnet 5 $0.00002 $0.00086
Haiku 4.5 $0.00001 $0.00043

Measured 2d ago against content hash 6c137ea47d89, 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 · 55 lines

What it actually says

Refactor

Identify and remove dead code, then refactor for improved maintainability and readability.

Steps

  1. Identify dead code:

    • Search for unused exports — functions, classes, constants, and types that are never imported.
    • Search for unused imports in each file.
    • Search for unreachable code after return, throw, or break statements.
    • Search for commented-out code blocks.
    • Search for unused variables and parameters.
  2. Verify before removing:

    • For each candidate, search the entire codebase for references.
    • Check for dynamic usage patterns (string-based imports, reflection, config-driven loading).
    • Check if the code is used in tests — remove test code only if the production code is also removed.
    • Do not remove public API surface without confirming it is safe.
  3. Remove dead code safely:

    • Remove one item at a time.
    • Run the build after each removal to catch breakage.
    • Run the test suite after each removal.
    • If removal breaks something, revert and investigate the dependency.
  4. Refactor for clarity:

    • Extract functions longer than 50 lines into smaller, well-named functions.
    • Reduce nesting depth to 4 levels or fewer.
    • Replace magic numbers and strings with named constants.
    • Apply immutable patterns — replace mutations with spread operators or functional updates.
  5. Refactor for structure:

    • Split files larger than 800 lines into focused modules.
    • Group related functions into cohesive modules.
    • Move shared utilities to a common location.
  6. Final verification:

    • Run the full build.
    • Run all tests and confirm they pass.
    • Verify no new lint warnings were introduced.

If Removal Breaks the Build

  • Revert the removal immediately.
  • Investigate the reference that was missed.
  • Add the item back and mark it for later review if the dependency is complex.

Output

A cleaner codebase with dead code removed, files properly sized, and all tests passing.

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 · 55 lines · 10 tokens per session scan A 6c137ea47d89

Subscribe to this mod's changes

refactor is a command published in the GitHub repository VersoXBT/claude-initial-setup (4 stars, last pushed 3mo ago), licensed MIT. It adds 10 tokens to every session and 429 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.