r/ClaudeCode • • 1d ago

Discussion Coding agents need good architecture, not just good instructions.

After about a year of building a large software platform with CC, one of the biggest lessons I learned was that a good coding agent harness is only half the equation. The codebase architecture matters just as much.

I had spent a lot of time improving agent instructions, workflows, reviews, and testing. The agents were productive, features worked, and progress looked great.

But when I started investigating the codebase as a whole, I found a different story. (And not once did even Fable ever even hint at this being a solution while brainstorming how to make things better)

There were dozens of implementations of things that should have been shared components. Multiple ways to accomplish the same operation. Duplicated systems, inconsistent naming, unclear ownership, and features scattered across whatever files or modules had been convenient at the time.

Individually, the agents had done their jobs. Collectively, they had created a maintenance nightmare.

Local optimization at the expense of global coherence.

The problem compounded. As the architecture became less consistent, agents had a harder time finding the right patterns to follow. They created new implementations, worked around existing systems, and added more complexity.

Better instructions alone didn't solve it. You could give agents all the rules and standards in the world, but if the repository contradicted those rules, the agents often followed the code in front of them or found whatever path made the task work.

What actually needed fixing?

The solution wasn't just improving the agents. It was cleaning up the environment they worked in.

Establish clear domains, boundaries, and ownership so everything had an obvious place to belong.

Consolidate duplicate functionality into shared, canonical implementations.

Standardize how systems communicated instead of allowing every feature to integrate differently.

Untangle dependencies and remove conflicting patterns and obsolete code.

Enforce those boundaries with automated checks, tests, and architectural reviews.

The architecture and the agent harness needed to reinforce each other.

The architecture provided the structure, contracts, and predictable patterns. The harness guided agents to follow them and prevented changes that violated them.

Neither could compensate indefinitely for the absence of the other.

This wasn't a problem unique to AI. Software teams had always accumulated technical debt. But AI agents made it possible to accumulate architectural entropy at unprecedented speed.

The biggest realization for me was that architecture wasn't just a blueprint for building software. It was a control system for maintaining and evolving it.

AI made writing code faster and cheaper. But without architectural discipline, that speed eventually became the very thing that slowed development down.

Has anyone else found that improving their AI coding workflow eventually meant spending more time fixing the structure of the codebase than improving the agents themselves?

14 Upvotes

40 comments sorted by

•

u/AutoModerator 1d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

6

u/Vargonaught 1d ago

I have been preaching this for months and I'm glad the industry is starting to converge on this idea.

The hilarious thing (for me) is that this is in no way new. DevOps, DevEx, DevProd, CI, Linting and plenty more have all been doing this in spirit for years.

What has happened is that as AI code has proliferated, these practices have become EVEN MORE important. If an agent can't be successful in your repo without you yelling at it, you have a problem and you are the bottle neck.

The best part is this is real engineering with interesting, unique problems! The amount of tooling I've built to steer my agents in my repos correctly with deterministic controls has exploded haha. The reliability, verification, and acceleration gains are worth it

2

u/Bavwu 1d ago

Agreed! Sometimes I find it hard to find the balance for time spent on tools and "real engineering" vs just "Yelling" at the agent to give the illusion of progress on the project lol

6

u/mblauberg 1d ago

This has always been the case before AI agents…

2

u/Bavwu 1d ago

Very true, not even totally specific to software development either.

AI has brought "systems management" problems into alot more people's lives lol

1

u/carson63000 Senior Developer 1d ago

Indeed, there’s a huge overlap between the factors that make a codebase good for human devs to work on, and the factors that make a codebase good for AI agents to work on.

The good news is, Claude can definitely help you to carefully refactor your code to get it into a more maintainable shape.

9

u/Living_Cell7304 1d ago

Why did you use ai to write this? Do you really think everyone is going to read all this? Literal dunning Kruger goofy shit all over this sub

-6

u/Bavwu 1d ago

This sub has a wide range of people in it, from new vibe coders to senior developers etc.

This is pretty obvious and basic stuff for some, but also something easily overlooked by many.

Sorry it didn't bring any value to you, but hope it helps inspire someone else!

8

u/Living_Cell7304 1d ago

Dude you’re having an ai bot write a bunch of garbage in an attempt to get upvotes

1

u/Desalzes_ 1d ago

I’m not working for a business or anything, just solo stuff and it’s incredibly inefficient and feels dumb every time I do it but I’ve found it works and saves me the hassle of looking for the things you pointed out, I have a session make a summary of a lot of what my project does, feed it to astra or 5.5 in browser not with the harness or local configs I have, rebuild either from the ground up pulling stuff from the old one. Takes less context somehow than fixing the old one and cleaning it up from what I’ve seen. Probably easier for sonnet to find what it needs than opus to make decisions as it combs the entire project

0

u/Bavwu 1d ago

Sometimes stopping to sharpen the axe cuts the tree down faster then just keeping on swinging

1

u/Desalzes_ 1d ago

Sometimes it’s more about the journey than the destination. Swinging is therapeutic

1

u/uduni 1d ago

This is called lack of coherent, searchable documentation

Just put some instructions in AGENTS.md about how to search docs, and build a doc for every feature. Simple

4

u/ILikeCutePuppies 1d ago

You can't write every single rule the agent or docs should know because a) it would be to much context and make it stupid b) you don't figure out some of these mistakes until it makes it c) many ideas are very hard to generalize and you can make the agent go very bespoke. d) progressive disclosure means that it will sometimes miss important things.

What does help is good CI and many review bots with different goals however that will only go so far and also slows everything down.

1

u/Bavwu 1d ago

Exactly, and I find they like to follow the unwritten repo rules/conventions more then the prompt anyways.

0

u/uduni 1d ago

But if each feature is organized carefully, its easier to find out where to put the code, and where the “seams” are (as opus like to say)

2

u/ILikeCutePuppies 1d ago

It can help but most projects are not greenfield projects. It can take a lot of work to understand what is going on. The agent can't have all the code in it's memory at once.

Deep modules is really just one of probably 10s of thousands of rules and a great number likey differ per project.

1

u/Bavwu 1d ago

Depending on size of things, I imagine that's a good option or at least much simpler, but it's more adding a layer on top to help vs fixing the issue isn't it?

1

u/uduni 1d ago

What so you mean “a layer on top vs the issue”

That is the issue. a human would do the same thing without any docs to follow

1

u/Bavwu 1d ago

The post was about when the code base is unorganised. Documenting the mess is just a layer on top of the issue, actually organizing the code would be the proper fix to the issue.

1

u/uduni 1d ago

Oh ya ok. I meant, documenting from the beginning is how you avoid the mess. Your right, refactoring now is more work than just documenting

1

u/Bavwu 1d ago

Oh, prevent the problem in the first place, yeah that's probably the best solution to the issue lol

1

u/uduni 1d ago

U gotta start sometime…

2

u/SawToothKernel 1d ago

Why use an LLM to build a document from code when the same LLM can just look at the same code and understand the feature?

Aren't you just creating an unnecessary second source of truth?

1

u/uduni 1d ago

Because the LLM is missing the big picture. Thats why it writes messy code.

Documentation helps it see more about how a project works, while using less tokens

1

u/Blockpair 1d ago

hey op, your post was very long so i havent read it, but i just wanted to say i hope you have a great day ^_^/

2

u/Bavwu 1d ago

Thanks! TD:DR code base hygiene and structure architecture can be half the battle vs just relying on rules and instructions for your coding agents to produce good results.

Have a great day yourself 😊 tomorrow too!

2

u/hieuphung97 1d ago

This hits home. Agents always take the path of least resistance. If you leave loose package boundaries, they will happily import internal utilities across four domains just to finish a prompt. Strict compiler checks and boundary linting beat prompt guidelines every single time.

1

u/Turbulent_Swimmer900 1d ago

Just made my code base searchable tonight! I swear Claude is snitching on me...

1

u/Mithryn 1d ago

This is a great discussion and something I've been dealing with. I appreciate the conversation this launched.

1

u/Right-Performance-93 1d ago

i stopped adding rules for this. the check fails the build if a second copy of that function lands, and the prompt never mentions it.

1

u/m-ritter 1d ago

Duplicated implementations of shared components are hard to catch when each agent only sees its own task. A review pass that checks every new change against the components that already exist finds those duplicates before they merge. Writing the agreed boundaries and ownership rules into project memory also lets a fresh session start with them instead of rediscovering them. I'm the developer of QualityLayer, which does exactly this: https://github.com/maxritter/qualitylayer

1

u/Mithryn 1d ago

This looks good. Encoded, I understand you're selling a product. And it's a product a lot of people need, but don't know that they need until they've run into the problems at scale.

1

u/m-ritter 1d ago

Thanks! Agreed, most people only notice it once several agents work on the same codebase at the same time. Where did it start to hurt for you, duplicated components or drifting boundaries?

1

u/Mithryn 1d ago

Drifting. I have two computers (mac and PC) each with their own agents. The build projects from the same codebase with tasks split up by specialization.

Why?

Mostly to practice orchestration and work out kinks like this. I have my own solution but it looks very similar to what you've put together, but not quite as advanced.

My last job was Head of AI at an AI transcription company and I had 8 AI engineers who I had ro coordinate between, along with other departments using AI. So dialing in complex orchestration on repositories was a key focus early on

1

u/m-ritter 12h ago

Two machines with split specializations is a good way to surface drift early. That is where I care most about keeping the engineer in the loop: approve the plan before an agent starts, then check the diff against it, so drift shows up while it is still small. With 8 engineers plus agents, how did you keep the shared boundaries in sync, a doc in the repo or mostly through reviews?

1

u/Mithryn 6h ago

Several checkpoints.

First: know that a folder can have a claud.md or agent.md file at the route and any LLM will read it first (99% of the time, so we had a fallback in case it didn't). That meant that everyone's LLMs had the same understanding.

I have a system I call Gearbox for selecting agents on tasks (back then it was "clutch" because it was more manual) that selects the new agent (not a subagent) and gives it the instructions that include the particular folder.

We have an extensive Git repository set of skills for pull requests, merges who has priority. Any agent touching git has these skills.

Then we had "Mission Control"; a supabase instance that acted as a mailing system. Any engineer could ask questions and their claude could ping mission control. Every so many turns my Claude would check mission control for messages, but if my claude had the answer it could answer theirs directly. If not, it asked me, I answered, and it pushed the answer. Theirs woild check as they worked, get the answer amd continue working.

It was the reverse of "this meeting could have been an email". "This problem can be solved without a human" escalated to"this problem needs the head of AI".

But we also had a very liberal chat/slack/meeting policy. If you get stuck, I'm free to answer any time/place. This meant that the human side of understanding was just as able to flow in a similar way.

The final aspect: I have a skill called "Fullscope" that defines projects very thoroughly. We were a transcript AI company, so we'd have most the definitions from a meeting with the client. Plug those in, and then go rounds of questions with the engineers in the room to define the project to the edge cases and details.

  • upfront planning
  • well defined git practices
  • agent.md files in the root of every folder
  • realtime communication
  • changing the human aspects to match the new work.

This made my claude an orchestrator

1

u/m-ritter 1h ago

Thanks for writing this up, that is a really complete setup. An agent.md per folder plus a shared mailbox between the agents is a neat way to keep everyone's context the same. Fullscope sounds close to how I see it too: most of the quality is decided before the first line of code. Did the answers from Mission Control flow back into the agent.md files, or did they stay in the mailbox?

1

u/Mithryn 1h ago

Back then, mailbox. That was about a half year ago. You should see my setup now.

;-)

0

u/adelie42 1d ago

I think there is only so much you can do to protect a user from themselves and make sure they actually do all the work involved in telling Claude what to do for them.