Skip to content
Agentmart
Submit a tool

refactor

Multi-pass convergent refactoring of a specific piece of code.

Skill by cederberg

IndexedMIT
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/cederberg-refactor

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Multi-pass convergent refactoring of a specific piece of code. Use when code works but feels tangled, over-complicated, or like it hasn't found its natural form yet. Not for applying known patterns or fixing bugs — for discovering what the code wants to become through repeated small transformations.

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/refactor

Tools it pre-approves 4

From allowed-tools in SKILL.md: the agent may use these without asking you each time.

  • Read,
  • Write,
  • Glob,
  • Bash

What's inside

Skill name
refactor
Description
Multi-pass convergent refactoring of a specific piece of code. Use when code works but feels tangled, over-complicated, or like it hasn't found its natural form yet. Not for applying known patterns or fixing bugs — for discovering what the code wants to become through repeated small transformations.
License
MIT
Allowed tools
Read,, Write,, Glob,, Bash
Instructions
153 lines in SKILL.md · view on GitHub

Before installing

  • Pre-approves any shell command

Files (2)

  • SKILL.md
  • example-findmatch.md · references/

SKILL.md (first lines)

# Iterative Refactoring

## Background

Most refactoring advice is catalog-based: identify a smell, apply the fix. That
works for clear-cut problems — a method is too long, a name is misleading,
duplication exists. But some code isn't _broken_ in any catalogued way. It's
just not right yet. The logic is correct. The tests pass. But the structure
doesn't match the idea it's expressing.

This skill addresses that situation. The process is closer to sculpting than
engineering: remove a bit of material, step back, observe what's revealed, let
that observation guide the next cut. Each transformation is small and
behavior-preserving, but the sequence can produce a result that no single step
could have planned for.

### Why each step matters

The key difficulty is that **each step creates the conditions for the next**. A
transformation that seems minor — switching from a collected list to a stream —
can reveal that two separate code paths are actually the same path with
different predicates. That insight is invisible before the transformation
exists. You cannot plan the full sequence in advance because the intermediate
forms are what generate the ideas.

This means the process is fundamentally exploratory. There is no target state to
specify upfront. The code converges toward a form that feels inevitable — where
every line earns its place and the structure mirrors the intent — but you only
recognize that form when you arrive.

### What drives each step

The engine of the process is a question: **"What bothers me about this?"** Not
"what pattern can I apply?" but "what feels off, redundant, misaligned, or
unnecessarily complex?" The answer might be:

- A variable that exists only to be used once
- Two branches that feel like they should be one
- A name that no longer fits what the code does
- An imperative sequence hiding a declarative idea
- A null check masking a deeper design question
- Structural symmetry that isn't yet expressed in the code

These observations don't come from a checklist. They come from reading the code
with fresh eyes after each change — treating the current form as a new starting
point, not a waypoint toward a predetermined goal.

## Process

The process is a loop, not a pipeline. After each step, genuinely step back and
re-read the code as if seeing it for the first time. Don't rush to the next
transformation.

### 1. Understand

Read the code. Understand what it does and why. Identify the behavioral contract
— what must remain true across all transformations. If tests exist, note them.
If they don't, acknowledge the risk.

### 2. Observe

Look at the code's current form and ask: what's not quite right? What creates
friction when reading? What would you change if you were explaining this code to
someone? Name the observation specifically — not "it's messy" but "the ternary
on line 12 obscures the fallback logic."

If nothing stands out, the code may have reached its natural form. That is a
valid and desirable outcome.

### 3. Transform

Make one small, behavior-preserving change that addresses the observation.
Verify the change preserves behavior. Present the result.

### 4. Re-observe

Read the transformed code as if seeing it for the first time. The question is
not "did my change work?" but **"what does this new form reveal?"** Often the
answer is a new observation that was invisible before.

Return to step 2.

## Working with the user

This is a collaborative process. The human's aesthetic judgment is a primary
signal — often the most important one.

- After each transformation, present the new code and your observation about
  what it reveals. Invite the user's reaction.
- If the user says "that's not quite right" or "I don't like that direction,"
  treat this as the highest-priority signal. Ask what specifically bothers them.
- Be willing to try a direction, discover it doesn't improve things, and
  backtrack. Dead ends are information, not failure.
- When proposing a next step, explain what observation motivates it — not just
  what the change is, but what you noticed that suggested it.
- If you have multiple observations, share them and let the user choose the
  direction.

## Kinds of insight that drive convergence

These are not patterns to apply but categories of noticing — things to be alert
to when re-reading code after a transformation.

**Structural redundancy.** Two code paths that differ only in a predicate or a
constant. Often invisible until imperative code is rewritten functionally, or
vice versa.

**Latent unification.** A special case that is actually the general case with a
constant parameter. The classic: `if (x) return a.first()` and
`return a.filter(pred).first()` are the same operation when `pred` is
`_ -> true`.

**Name–reality drift.** After transformations, a name may no longer describe
what it holds or does. Renaming often triggers further observations about scope
or responsibility.

**Abstraction pressure.** A language idiom, utility, or standard library concept
that would express the intent more directly than the current code. Using
`Objects.equals` instead of manual null checks. Using `Optional.or()` instead of

From cederberg/incubator, MIT.

More from cederberg/incubator

Signals

Stars
0
Forks
0
Open issues
0
Last commit (this folder)
Oct 5, 2026 (23 days ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from cederberg

Cite this page

refactor skill. Agent Mart. https://agentmart.dev/skills/cederberg-refactor (last updated 2026-10-24)