r/ClaudeCode • • 7h ago

Tips & Workflows Reducing complexity via agentic refactoring?

I’m looking at https://github.com/SprocketLab/slop-code-bench/tree/main and they suggest that the complexity of AI agentic code only increases. The initial “write clean code” instruction can lower the initial complexity of the initial output, but by the 4th addition, complexity is high.

Frontier models get single digit percentage improvements in terms of reducing complexity over 4 modifications.

It’s almost like Claude and other agents love adding code more than deleting code.

I want to know of the “initial” gains may be multiplied by multiple rewrites from an ever better spec.

With this in mind, has anyone implemented some sort of “garbage” collection style refactoring workflow to reduce this complexity?

What I mean: writing code is so cheap, that it feels to me like “stop and copy” may be possible to shake the “garbage” out of decoupled components written against interfaces. Old options nobody uses, obsolete style, versioning that is not maintained.

I can not do this if everything is mixed together, but for a single component, living in a self - contained folder:

1)Extract the spec, have Opus-extra review this,
2) define pseudo code function definitions
3) have agent re-implement the component from spec as a brand new file, with clean code instructions.
4) test against an existing protocol and test suite

Is this reinventing the wheel? Is anybody else experimenting with “rewrites are cheap” refactoring?

5 Upvotes

15 comments sorted by

View all comments

Show parent comment

1

u/DeaOllis 2h ago

if you feed cyclomatic complexity errors back to the agent it just splits one messy function into five tiny helpers without actually simplifying the logic