agentleFS
philoserfphiloserf/claude-code-config/skills/code-refactor/SKILL.md

code-refactor

Skill13 starsChanged 2 months agoMITView on GitHub

Produces a target design and an incremental migration sequence for a codebase, backed by an architectural review. Use when asked how a system should be refactored, restructured, or reorganized, or what it should look like afterward. Writes its findings and plan to `.issues/`; recommends changes but does not apply them.

10 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use git-doc-updater, git-precommit and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • u9401066Skill

    git-doc-updater

    Auto-check and update key documentation before Git commits to keep docs in sync with code. Triggers: docs, 文檔, 更新文檔, sync docs, release, 發布.

    Also in 3 projects that use this

  • u9401066Skill

    git-precommit

    Orchestrate pre-commit workflow including Memory Bank sync, README/CHANGELOG/ROADMAP updates. Triggers: GIT, gc, push, commit, 提交, 準備 commit, 要提交了, git commit, pre-commit, 推送.

    Also in 3 projects that use this

  • alirezarezvaniSkill

    readme-updater

    Keep README files current with project changes. Use when project structure changes, features added, or setup instructions modified. Suggests README updates based on code changes. Triggers on significant project changes, new features, dependency changes.

    Also in 3 projects that use this

  • alirezarezvaniSkill

    test-generator

    Automatically suggest tests for new functions and components. Use when new code is written, functions added, or user mentions testing. Creates test scaffolding with Jest, Vitest, Pytest patterns. Triggers on new functions, components, test requests, testing mentions.

    Also in 3 projects that use this

  • GoogleSkill

    code-reviewer

    Also in 3 projects that use this

  • +7 more from u9401066

The file

We split this skill into the rules it gives an agent

11 rules. 0 are common, 6 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do not assume that more abstraction, more layering, more interfaces, more files, or more design patterns constitute improvement.

    line 20
  2. Very specific:

    If THEORY.md exists, read it first and treat it as a hypothesis, not a fact.

    line 47
  3. Very specific:

    If .issues/ exists, read all of it.

    line 50
  4. Very specific:

    Only where neither exists do the domain and repository survey yourself, and do them as input to the target design rather than as a …

    line 54
  5. Very specific:

    Follow issues-protocol.md, the canonical copy shared across the code-* review skills, for the file layout, finding format, dedup checks …

    line 95
  6. Distinctive:

    Use specific files, packages/modules, types, functions, and execution paths as evidence.

    line 113
  7. Distinctive:

    Avoid generic advice that could apply to any repository.

    line 114
  8. Distinctive:

    What the codebase does well: Before the changes. Specific, not courtesy.

    line 126
  9. Very specific:

    The target design: Not a list of local fixes — what the codebase should look like after refactoring: the proposed conceptual model, major …

    line 128
  10. Distinctive:

    Prefer an evolutionary target that can realistically be reached from the current repository.

    line 135
  11. Distinctive:

    Write both artifacts to disk rather than only reporting them.

    line 167

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Conduct a deep technical review of this codebase with the goal of determining how it should be refactored.

Do not begin by changing code. First understand the system as it exists: what problem it solves, how it is organized, what constraints appear to have shaped it, and where its current design helps or hinders future work. This is an architectural and implementation review, not a linting exercise.

Do not assume that more abstraction, more layering, more interfaces, more files, or more design patterns constitute improvement. Prefer the simplest design that accurately expresses the domain and satisfies the real requirements.

Scope the review to $ARGUMENTS if provided, otherwise treat the whole repository as in scope. Examples: the storage layer, cmd/, the plugin system.

Skip vendored dependencies, build output, generated code, and lockfiles (node_modules/, dist/, vendor/, *.min.js, go.sum).

Phase one — understand before recommending

Work the dimensions this codebase actually raises — the problem domain, the repository survey, language and ecosystem conventions, correctness, architecture, readability, efficiency, tests, dependencies. A dimension with nothing to report gets no section in the output. Do not invent requirements that the repository does not support.

On ecosystem conventions specifically: judge the code by the conventions of its own language and contemporary community, and name what is technically valid but culturally unusual enough to raise maintenance cost. Name too the places where conventional wisdom should not be followed, because the domain or the repository has a legitimate reason to differ — that judgment is the part no checklist makes for you.

Start with what the repository already knows about itself. THEORY.md, .issues/, an existing WALKTHROUGH.md, ADRs and design notes are evidence, and prior passes by sibling skills are the cheapest context available:

  • If THEORY.md exists, read it first and treat it as a hypothesis, not a fact. Verify its central claims against the code. Where it is right, build on it instead of re-deriving the domain. Where it is wrong, that is a finding.
  • If .issues/ exists, read all of it. Known correctness bugs are input to the target design — a module you are proposing to delete makes its open bugs moot, and that is worth saying.

Only where neither exists do the domain and repository survey yourself, and do them as input to the target design rather than as a deliverable. This skill does not write THEORY.md.

Trace several representative operations end to end. Pay particular attention to boundaries between components — many important design problems occur at boundaries rather than inside individual functions.

Phase two — judge

Identify what the codebase does well before considering major changes. Preserve good decisions unless there is a concrete reason to replace them.

Distinguish demonstrated defects from plausible risks.

Refactoring philosophy

The desired outcome is not a theoretically perfect architecture. It is a smaller, clearer, more correct, more idiomatic system whose structure reflects the actual problem.

Favor refactorings that reduce concepts, reduce indirection, clarify ownership, make invariants explicit, make state transitions easier to understand, improve locality, expose important behavior through clearer APIs, remove duplication of knowledge, separate genuinely independent concerns, consolidate things that should never have been separated, make tests easier to write at meaningful boundaries, and reduce the number of ways the same task can be accomplished.

Be suspicious of refactorings that merely move complexity around.

Phase three — write it up

Two artifacts, and the split is the thing most easily gotten wrong: a finding is a defect at a location; the design is what the system should become.

Both live under .issues/: the findings as their own files, everything else as the overview at .issues/000-refactor.md. Nothing goes to the repository root. A refactoring plan is working state that expires the moment it is executed — it does not belong beside the standing documents (README.md, CLAUDE.md, THEORY.md, WALKTHROUGH.md), which answer questions that stay answered.

Findings → .issues/

Follow issues-protocol.md, the canonical copy shared across the code-* review skills, for the file layout, finding format, dedup checks against .issues/ and GitHub, and re-run rules. File each with **Source:** code-refactor.

A finding is a specific problem at a specific location — a correctness risk, a cohesion or coupling failure, an abstraction that leaks, a dependency that does not earn its cost. Severity uses the protocol's four levels and their meanings; there is no second scale here.

The protocol's ## Description and ## Suggested fix already ask for what you observed, where it appears, why it matters, and the change you propose. A refactor finding adds three things to them:

  1. Which kind of issue it is — correctness, design, maintainability, performance, ecosystem-convention, or operational, or some combination
  2. The cost, risk, or trade-off of making the change
  3. Your confidence in the recommendation

Use specific files, packages/modules, types, functions, and execution paths as evidence. Avoid generic advice that could apply to any repository.

Do not inflate severity. A long list of minor style observations should not obscure a small number of consequential design problems.

The overview → .issues/000-refactor.md

Regenerated in place on each pass, per the protocol. Cover, in this order:

The system as you understand it. Concise, in terms of the problem it solves rather than the technologies it uses. Then the current architecture, explained against that problem.

What the codebase does well. Before the changes. Specific, not courtesy.

The target design. Not a list of local fixes — what the codebase should look like after refactoring: the proposed conceptual model, major packages/modules/components, ownership of important state, principal interfaces and boundaries, dependency direction, major data flows, error propagation, concurrency model if relevant, configuration model, where domain logic should live, where infrastructure concerns should live, which existing abstractions remain, which disappear, and which new ones are justified.

Prefer an evolutionary target that can realistically be reached from the current repository. If the existing architecture is already fundamentally sound, say so and recommend localized improvement rather than redesign.

The refactoring sequence. The target design as an incremental migration plan that keeps the codebase working throughout wherever reasonably possible. Per stage: the objective, affected areas, prerequisites, tests or safeguards required first, specific changes, expected simplification, risks, and how to tell the stage is complete.

Order the work so early changes reduce uncertainty or make later changes safer. Separate behavior-preserving refactoring from intentional behavioral changes. Where possible, establish tests around existing behavior before restructuring it.

What not to change. Explicitly identify areas that may look imperfect but should probably remain as they are, and why. A useful review protects good existing decisions as well as identifying bad ones.

Unresolved questions. Questions that materially affect the recommended architecture but cannot be answered from the repository alone. Do not use unresolved questions as an excuse to avoid conclusions the available evidence supports.

End with the protocol's index table covering the findings you filed.

Questions and delivery

This skill is advisory and does not apply changes. You run inline and can ask, but a design question rarely has a cheap answer mid-pass, and stopping to collect several would cost more than it returns — so default to putting a question that would change the recommendation in Unresolved questions, naming the answer that would move you and which way it would move you rather than leaving it open-ended. Ask outright only when the answer would invalidate the plan rather than adjust it. Where a premise is load-bearing enough that guessing wrong would invalidate the target design, stop and report that instead of proceeding on a guess. Write both artifacts to disk rather than only reporting them.

Do not use when

  • The user needs to understand the system before changing it — use code-theory, which builds the theory this skill consumes. Run it first when no THEORY.md exists and the design rationale is unclear
  • The ask is how the system runs today, told linearly — use code-walkthrough
  • The ask is a bug and security sweep rather than a design — use code-audit or /code-review
  • The ask is deletion — what to remove, inline, and flatten, with no target architecture behind it — use code-reduction
  • Reviewing a staged diff or recent changes — use /code-review for defects, /simplify to apply cleanups
  • The architecture is already sound and the user wants it changed anyway. Say it is sound and stop; that is the finding

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.