refactor-clean

refactor-clean is a command for Claude Code from sefaertunc/Worclaude. It costs 7 tokens per session (969 once invoked), scanned B, original, MIT.

A focused code-cleanup command for recently changed files, working directly in the current project and leaving the edits uncommitted.

In plain words
What is it for?
Use it to clean a whole recent change or limit cleanup to a path such as src/core/merger.js.
Why use it?
It removes routine mess such as dead code, duplication, excessive complexity, and inconsistent patterns before review.

Command 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 commands/sefaertunc/worclaude/refactor-clean
Clone the repo
git clone --depth 1 https://github.com/sefaertunc/Worclaude

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-clean

README.md
[![agentmods](https://agentmods.dev/badge/commands/sefaertunc/worclaude/refactor-clean.svg)](https://agentmods.dev/commands/sefaertunc/worclaude/refactor-clean)
Your own site
<a href="https://agentmods.dev/commands/sefaertunc/worclaude/refactor-clean"><img src="https://agentmods.dev/badge/commands/sefaertunc/worclaude/refactor-clean.svg" alt="Measured on agentmods" height="20"></a>
Per session 7 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 969 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 1 finding. 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.00007 $0.00969
Opus 5 $0.00003 $0.00485
Sonnet 5 $0.00001 $0.00194
Haiku 4.5 $0.00001 $0.00097

Measured 4d ago against content hash ff33296725eb, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade B, and why

refactor-clean scanned grade B with 1 finding 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 4d 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.

Reads agent configuration directoriesmediumAgent snooping

.claude/, .codex/, .gemini/ hold keys, settings and other credentials a mod has no legitimate need for.

test -f .claude/scratch/last-review.md && head -10 .claude/scratch/last-review.md
.claude/commands/refactor-clean.md · 109 lines

How it starts

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

Run a focused cleanup pass on recently changed code. This command runs INLINE in your current session — it reads uncommitted changes, improves them in place, and leaves everything uncommitted for /commit-push-pr.

When invoked with arguments, use them to scope the cleanup. Example: /refactor-clean src/core/merger.js

Arguments: $ARGUMENTS

Do NOT spawn a subagent or worktree for this. Work directly on the files in the current working directory.

What to Clean

  1. Dead code — unused imports, commented-out blocks, unreachable branches, uncalled functions. Delete them — git has history.

  2. Duplication — identical or near-identical code blocks → extract shared function. Repeated validation → centralize. Copy-pasted error handling → extract helper.

  3. Complexity — functions over 30 lines → split by responsibility. Nesting deeper than 3 levels → early returns, guard clauses. Long parameter lists → group into option objects.

  4. Consistency — naming that doesn't match project conventions. Mixed patterns in the same module. Inconsistent error handling.

Process

0. Check for fresh /review-changes output

Before doing your own analysis, look for .claude/scratch/last-review.md:

test -f .claude/scratch/last-review.md && head -10 .claude/scratch/last-review.md

If the file exists AND its sha: frontmatter matches git rev-parse HEAD, use the review as your work plan. Skip steps 1-3 below; jump straight to step 4 with the review's findings as your candidate list.

If the SHA doesn't match, the review is stale — ignore it and proceed with your own analysis.

1-6. Self-analysis path (only if no fresh review)

  1. Identify changed files: git diff --name-only (unstaged) and git diff --cached --name-only (staged). If no changes, check git diff --name-only HEAD~5 for recent commits.
  2. Read each changed file fully — understand context before changing
  3. Check CLAUDE.md for project-specific conventions
  4. Make one improvement at a time, smallest meaningful change first
  5. Scoped tests after each change. Run only the tests related to the files you changed (don't run the whole suite each time):
    • Vitest: npx vitest run --related <changed-files>
    • Jest: npx jest --findRelatedTests <changed-files>
    • Other runners: scope to the relevant test directory or file pattern
  6. If scoped tests fail, revert immediately — your change broke behavior

Read the full file on GitHub · 109 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. 4d ago First seen · 109 lines · 7 tokens per session scan B ff33296725eb

Subscribe to this mod's changes

refactor-clean is a command published in the GitHub repository sefaertunc/Worclaude (4 stars, last pushed 25d ago), licensed MIT. It adds 7 tokens to every session and 969 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it B with 1 finding (reads agent configuration directories). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.