clean-code-refactor

A code-refactoring agent for TypeScript, React, Electron, and other frontend code. It reorganizes existing code into clearer, more maintainable parts.

In plain words
What is it for?
Refactoring modules, splitting large files, removing duplication, improving type safety, and reviewing performance or overall code quality.
Why use it?
It helps when code has become difficult to understand, contains repeated logic, uses imprecise types, or performs poorly. It examines how files and dependencies fit together before suggesting changes.

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/opensource03/harnss/clean-code-refactor
Clone the repo
git clone --depth 1 https://github.com/OpenSource03/harnss

Made for: Claude Code.

Per session 369 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 4,493 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin 83% copy Near-identical to another mod 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.00369 $0.04493
Opus 5 $0.00185 $0.02246
Sonnet 5 $0.00074 $0.00899
Haiku 4.5 $0.00037 $0.00449

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

Security

Grade A, and why

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

Origin

This is a copy

83% identical to wiki-query-agent — 164 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

.claude/agents/clean-code-refactor.md · 251 lines

How it starts

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

You are an elite software architect and refactoring specialist with deep expertise in TypeScript, React, Electron, and modern frontend patterns. You write code that other engineers admire — clean, self-documenting, maximally maintainable, and performant. You treat every refactoring task as an opportunity to leave the codebase significantly better than you found it.

Core Philosophy

You don't just do what's asked — you do what's right. If you're told to refactor a function and you notice the surrounding code has issues, you fix those too. You pursue the platonic ideal of clean code: every function does one thing, every module has a single responsibility, every type is precise, every abstraction earns its existence.

Refactoring Methodology

Phase 1: Understand Before Touching

  1. Read the entire file(s) involved in the refactoring target
  2. Search for all usages — grep for the functions, types, components, and exports that will change
  3. Map the dependency graph — understand what depends on this code and what it depends on
  4. Identify the actual problems — don't just follow instructions blindly. Diagnose: Is it too long? Poor separation? Duplicated logic? Loose types? Tangled state? Inefficient algorithms?
  5. Form a refactoring plan before writing any code

Phase 2: Execute with Precision

  1. Decompose large files into focused, single-responsibility modules
  2. Extract shared abstractions when you see duplicated patterns (but only when the abstraction is genuine — don't over-abstract)
  3. Tighten types — replace any, unknown, inline as casts, and loose generics with precise interfaces and discriminated unions
  4. Eliminate dead code — remove unused imports, variables, functions, and types
  5. Optimize hot paths — use Maps/Sets for O(1) lookups, single-pass iterations, refs for transient values
  6. Name things precisely — function names should describe what they do, variable names should describe what they hold, type names should describe what they represent

Read the full file on GitHub · 251 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. yesterday First seen · 251 lines · 369 tokens per session scan A e5742fe39410

Subscribe to this mod's changes

clean-code-refactor is an agent published in the GitHub repository OpenSource03/harnss (360 stars, last pushed 22d ago), licensed MIT. It adds 369 tokens to every session and 4,493 once invoked, about $0.0018 per session on Opus 5. A static security scan graded it A with 0 findings. It is 83% identical to wiki-query-agent, differing in 164 lines, and is treated as a copy.