auto-refactoring
Skill0 starsChanged 8 months agoMITView on GitHub
Runs an autonomous refactoring loop that picks files, applies behavior-preserving changes, runs the test suite, measures a quality metric (lint warnings, test coverage, type errors, complexity), and keeps improvements or reverts failures. Loops indefinitely. Triggers on "auto-refactor", "refactor loop", "clean up my codebase", "improve code quality", "reduce complexity", or requests to iteratively improve code health metrics.
In this repository4 other files it gives its agents.
- AGENTS.mdAGENTS.md
- auto-researchingSkill
- auto-testSkill
- fuzz-fixingSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
If refactor.json exists, skip to Setup Phase.
- Distinctive: line 32
Agent 2 — Quality Tools: Test suites, linters, type checkers, coverage tools.
- Very specific: line 55
Create branch autorefactor/<tag> (append -2, -3 if exists)
- Distinctive: line 56
Verify tests pass and record baseline metric
- Very specific: line 57
Add results.tsv and run.log to .gitignore
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Auto-Refactoring
Autonomous refactoring loop: pick a file, refactor it, run tests + measure a metric, keep improvements, discard failures.
Contract: every change either improves the codebase or gets thrown away.
Discovery Flow
If refactor.json exists, skip to Setup Phase.
Explore with 2 parallel subagents:
Agent 1 — Structure & Stack: Directory tree, language/framework, build system, project purpose.
Agent 2 — Quality Tools: Test suites, linters, type checkers, coverage tools. What's configured and how to run it.
Present findings and ask one question:
Here's what I found:
- [project summary]
- [quality tools/metrics]
What do you want to optimize?
- Lint warnings ([N] current)
- Test coverage ([X]%)
- Type errors ([N])
- Cyclomatic complexity
- Custom metric
Infer config from exploration — see CONFIG.md for fields and metric catalog.
- Write
refactor.json, show for confirmation, then proceed.
Setup Phase
- Parse
refactor.json - Create branch
autorefactor/<tag>(append-2,-3if exists) - Verify tests pass and record baseline metric
- Add
results.tsvandrun.logto.gitignore - Initialize
results.tsvwith header row - This is the last interaction. From here, fully autonomous.
The Loop
LOOP FOREVER. NEVER stop. NEVER ask permission to continue.
1. PICK: Scan target_files, prefer worst per-file metric, cooldown files
that failed last 3 attempts. Review results.tsv for trends.
2. ANALYZE: Read file, identify issues, pick a strategy from STRATEGIES.md,
form a concrete hypothesis.
3. EDIT: One conservative, behavior-preserving change. No behavior changes.
4. TEST: Run test_command > run.log 2>&1. Fail → revert, log, move on.
5. MEASURE: Run metric_command. Improved or equal → keep. Regressed → revert.
Exception: equal metric + simpler code → keep.
6. COMMIT (if kept): Descriptive message with strategy, metric delta, hypothesis.
Do NOT commit results.tsv or run.log.
7. LOG: Append to results.tsv (iteration, timestamp, file, strategy,
hypothesis, metric_before, metric_after, status, reason).
8. Every 10 iterations, print progress summary. GOTO 1.Critical Rules
- Protect context window — see CONTEXT.md. Always redirect output.
- results.tsv is your memory — survives git resets, full history.
- One change per iteration — isolate variables.
- Never change behavior — structure only.
- Respect the revert — don't fix a failing refactoring with more changes.
- When stuck — see STRATEGIES.md.
Output
- Git history on
autorefactor/<tag>— each improvement is a commit - results.tsv — full experiment log
- run.log — most recent test output
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
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.

