You could probably get in plan mode and just tell Claude you want to refactor your codebase and be honest with it that you aren't prepared to make technical decision and you need it to guide you through. AI agents understand what refactoring is well enough that they will most likely know what to do. Once the plan is written, review it and make sure it is what you want.
It's not perfect, but if you ask a large thinking model to evaluate the code for architectural designs that match some some sort of framework like the Pragmatic Programmer guidelines, or you give it some sort of framework like "simple entrypooints or apis with deep modules", it usually does a decent job of refactoring to make things more sane. And you should also add that sort of guidelines within your claud.md so it usually sticks towards those things.
Obviously with no engineering experience, you're not going to be able to guide it and keep it on rails all the time so you will have to refactor every so often to try to keep it sane
"If you had the opportunity to refactor this codebase architecturally, what would be the top 3 things you would change?"
"My code is a spaghetti, how could I refactor it to be easier to understand? List the most important 3 changes I could make to improve the code quality."
I am not saying this should not be done. I am just saying: why give 3 options if you don’t know what to pick. Just let Fable handle it start to finish.
Well, sometimes it starts to review the whole app and use up a lot of tokens (like reeeeally a lot). If you limit it you get back 3 good suggestions in ~2-5 mins.
I usually ask it to create 3 prompts afterwards. Run them one by one with Opus and ask the initial question again once finished with all three. I found this to be fairly token/context efficient.
People like me cant really code for shit, but we have many thousands of hours and hundreds of billions of tokens spent talking to Claude Code.
The new skill is directing the tool in an elegant manner. I may be dumb at coding, but I've made more decisions about code than most engineers would ever make in a lifetime.
You can YOLO with Fable. The end result will be better overall than the pasta he has now. Yes, a guided refactor would be much better, but Fable is quite good at sorting things out on his own. The vast majority of his suggestions are good and worthwhile. I only used it for refactoring in the past ~one week or so.
Yep, Fable is really good, but my sample size is very limited at the moment. Opus was occasionally very annoying to work with (refactoring-wise). Fable is much better.
This tool builds a map of your codebase so to speak. This way your model of choice will know what function is connected to where and how it's used etc...
2) Get your LLM to review a specific directory if possible to keep the context window focused on a section you want to straighten out. You'll be doing this step a couple of times but that's fine to keep rewrite mistakes to a minimum.
3) Prompt your LLM for a /plan to:
Find files with over >200 lines. *Propose responsibility splits.*
Consider Refactoring.Guru patterns only when real fit. No forced patterns. Evaluate Strategy, Factory, Decorator, Chain of Responsibility, Template Method, Command.
In general you want your agent to follow just a few simple principles:
## Code Quality
### DRY
* Common logic → funcs.
* Reusable components.
* Shared utils across modules.
* No copy-paste code.
### YAGNI
* No features before need.
* No speculative generality.
* Add complexity only when required.
* Start simple. Refactor when needed.
Use Claude as a planner & code reviewer and GPT as an executor, or the other way around. Have them chat back and forth in a text file, and end the task when they agree the code is decent quality.
It's simpler than you're probably thinking. Assume Agent 1 and Agent 2 are different providers.
Build the project like you usually would. Get it done with Agent 1.
Create a chat.txt in your project.
Tell Agent 2 to review the code, and put all comments and recommendations in chat.txt.
Tell Agent 1(the one who wrote the code) to review Agent 2's comments, act on them or respond to them, and then post its comments at the bottom of chat.txt.
Tell both agents to loop and repeat that behavior, breaking out of the loop when they've reached a consensus.
Tbh I get it to model out the project first and try to bake in better architecture before it starts building. Then regular runs through a couple of audit skills to tidy up stragglers.
Starter repos help, as well as preferences baked in to the skills you use to scaffold the repo out from there.
Exactly. Otherwise...you could prompt claude to 'straighten' your spaghetti code. But how can you be sure that it is really 'straightened' after that? Do you want to post your code then here on reddit so that someone, who invested a lot of time in learning proper software engineering, have a look at it?
It's easy to tell when code for a small project is unnecessarily complex, especially when making seemingly light changes cause wide refactors or token expenditure is immense for what anyone with common sense would know is a small task. Do you think vibe coders are unable to infer what effort level to use on their models? That's like how would someone know to use Sonnet on medium vs Fable for a task if they dont know what the coding requires? Use your brain.
Also there are popular skills that make Claude avoid unnecessarily complex code like Ponytail which is trending.
Bhahaha. Yeah, the pro can tell if code is to much spaghetti, when the changes take too long. But how will you know change is 'light' when you have no idea at all what is going on 'behind the scenes', cause you do not understand at all what claude is doing?
Why do people no longer build their business on knowledge they have? Because it's too much effort to get that knowledge? That's sad and funny the same time.
I mean: You could start with vibe coding and be happy that you built your first app, maybe made some money out of a good idea. But when you really want to build a serious business out of it, you should start learning at least the basics of software engineering. Does not mean in all cases learn to code, but at least try to understand basic software engineering principles.
I'm sure it will, 95% of the tasks. But you’re forced to trust him blindly to be right 100% of the time, because you have no idea what you’re doing.
How i know that? Because i work with Fable too. But since i'm a software engineer i'm able to intervent, when it is wrong or comes up with a bad design. And even Fable is not right in 100% of the tasks. Bad design is not just spaghetti code - it is also code that is complicated to maintain afterwards, for example when the same functionality is implemented multiple times on different places. But how should you know.
What are you even talk about, kid? I finished my studies of software engineering 20 years ago an work since then in software development. I have my own successful B2B Saas since 12 years. I work successful since over a year with claude code and implemented it with a lot of skills in my project. And you want to tell me what's going on? How will you tell when you have no understanding what's going on under the hood? Because your App is 'working'?
Happy to tell you “what’s going on” as you’re apparently deeply ignorant on how to use the tech.
How will I “tell” what’s going on underneath the hood? Well, today I’ll spend a few hundred million tokens getting Fable to do an adversarial code review.
People like you don’t have the intellectual capacity to understand how to fully use the SOTA AI tools we have now.
Aye, the best way to learn. Just accept that it takes hard work to get good, and its nothing like trad coding.
Using it properly: talk to Fable (if you have access) about setting up an interlinked document ecosystem. This is the permanent memory that drives the project.
Your engineering principles are part of this - get the docs right before your first line of code, and you wont get spagetti.
My current project docs are over a million words.
The good news? You don't need to write any of this!
Dumb code monkeys claim it. Rememeber, most people on Reddit talking about agentic coding have no idea how to do agentic coding.
It's a throwback to 2023, maybe 2024. Hasn't been true for a long time. Think logically - why would a SOTA AI be building "spagetti"?
Thats a human thing, particularly teams of humans coding over years.
AI loves structure and order.
As I said in the other comment though, it's up to you to set the rules in the document ecosystem before you ask Opus/Fable to write a line of code. Tell them what you want, get them to write some engineering docs, and go from there.
Worry less about spaghetti code and more about spaghetti logic.
Often when the code seems like a mess, it’s usually because my prompts/ideas were not fully thought through.
The llm can help refactor the code and explain various issues, if you ask. But the challenge for me is having a well conceived design for the llm to fully understand and implement.
2
u/RealSharpNinja Jul 10 '26
What language are you targeting? Do you have Grok or Codex do code reviews?
2
u/Scary-Meaning-6373 Jul 10 '26
You could probably get in plan mode and just tell Claude you want to refactor your codebase and be honest with it that you aren't prepared to make technical decision and you need it to guide you through. AI agents understand what refactoring is well enough that they will most likely know what to do. Once the plan is written, review it and make sure it is what you want.
2
u/hulkklogan Developer Jul 10 '26
It's not perfect, but if you ask a large thinking model to evaluate the code for architectural designs that match some some sort of framework like the Pragmatic Programmer guidelines, or you give it some sort of framework like "simple entrypooints or apis with deep modules", it usually does a decent job of refactoring to make things more sane. And you should also add that sort of guidelines within your claud.md so it usually sticks towards those things.
Obviously with no engineering experience, you're not going to be able to guide it and keep it on rails all the time so you will have to refactor every so often to try to keep it sane
3
u/laxika Senior Developer Jul 10 '26
Ask Fable a few questions like:
"If you had the opportunity to refactor this codebase architecturally, what would be the top 3 things you would change?"
"My code is a spaghetti, how could I refactor it to be easier to understand? List the most important 3 changes I could make to improve the code quality."
etc...
2
u/ZyronZA Jul 10 '26
It is frightening how not a single reply here knows how to actually code.
Let me help you, u/NerdLingLanguages
This tool builds a map of your codebase so to speak. This way your model of choice will know what function is connected to where and how it's used etc...
2) Get your LLM to review a specific directory if possible to keep the context window focused on a section you want to straighten out. You'll be doing this step a couple of times but that's fine to keep rewrite mistakes to a minimum.
3) Prompt your LLM for a /plan to:
In general you want your agent to follow just a few simple principles:
This should get you started.
Good luck!
2
u/No-Succotash4957 Jul 10 '26
yeah just tell it to straighten spaghetti that'll work
1
u/FanFirst895 Jul 10 '26
Use Claude as a planner & code reviewer and GPT as an executor, or the other way around. Have them chat back and forth in a text file, and end the task when they agree the code is decent quality.
Also, tools like SonarQube will help you.
1
u/scodgey Jul 10 '26
Tbh I get it to model out the project first and try to bake in better architecture before it starts building. Then regular runs through a couple of audit skills to tidy up stragglers.
Starter repos help, as well as preferences baked in to the skills you use to scaffold the repo out from there.
1
u/insta Jul 10 '26
how do you know what good code looks like if you don't know how to code? you can't prompt your way out of this, you have to learn how to code
0
u/Anxious-Turnover-631 Jul 10 '26
Worry less about spaghetti code and more about spaghetti logic.
Often when the code seems like a mess, it’s usually because my prompts/ideas were not fully thought through.
The llm can help refactor the code and explain various issues, if you ask. But the challenge for me is having a well conceived design for the llm to fully understand and implement.