# How do you prevent "AI spaghetti code" when orchestrating with LLMs?

> Source: <https://dev.to/0x2e73/how-do-you-prevent-ai-spaghetti-code-when-orchestrating-with-llms-56gm>
> Published: 2026-05-20 12:14:52+00:00

Hi everyone!
I’ve reached a point in my workflow where I barely write code line-by-line anymore, I orchestrate AI agents. I use tools like Superpower, detailed specs, and a structured prompt architecture: a folder with specific .md rules for different scopes (Front, Back, Git...) and a global claude.md for overall context.
My rules are supposed to be rock solid. The high-level architecture stays fine. But I'm hitting a massive pain point: localized spaghetti code and micro-debt.
The reality is: Sometimes, if I don't take 45 minutes to really review the code, I miss the spaghetti code. Then later, when I actually open the file, I'm just like “shit, wtf is this?!”
It feels like sub-agents lose the memory/context of the parent rules the moment they spawn for a micro-task, and they still write shit or over-complex code.
So I am wondering, am I missing something?
How can I make Superpower run sub-agents without losing context/Rules, or is there a better approach to coding with agents?
Would love to hear how you guys keep your codebase clean without having to create a specific task to spot messy code three weeks after it's done just to fix it.
I just want the AI to write good code directly from the start.
