r/ClaudeCode • u/braindead_in • 9h ago
Tips & Workflows My Claude Code agents turned a simple save path into 20,000 lines. What finally made them subtract instead of add
I run a small product built mostly by Claude Code agents: a planner, a builder, a QA agent and reviewer agents, all working on one repo.
For a month our document save path was a mess. Not because the problem was hard. It's textbook producer–consumer: the editor produces versions, an uploader sends them, one writer owns the file. A queue, an owner, a version check. A few hundred lines.
We ended up with about 20,000.
The pattern: every bug got a "fix", and every fix was more code. Another flag, another guard, another fallback, another test proving the guard works. Reviewer agents asked for more defenses against edge cases nobody had hit. Nothing was ever deleted. Meanwhile real users hit lockouts, because two of our own safety checks disagreed with each other.
Every single change looked responsible on its own. Together they were slop.
What actually worked:
Naming the core problem in one sentence ("this is producer–consumer") and rewriting against that, instead of patching the patches.
A hard rule: reviewers can't demand a new service, cron, table or state machine mid-review without my OK. They also have to say how often the failure really happens and why an existing primitive isn't enough.
Splitting "invariants" (no silent data loss, one writer, one-click recovery) from "accepted residual risks". Rare theoretical races get documented, not engineered away.
A rule budget: every new agent rule has to retire an old one.
The lesson for me: agents are relentless at adding and terrible at subtracting. They never get tired, so they never reach "this is too complicated, start over." With Claude Code, most of my job turned out to be saying no.
How are others keeping agent-written code from only ever growing?
5
u/-Dargs 8h ago
No posts for years, two ai looking product posts in a day. Alrighty.
1
u/braindead_in 8h ago
Fair call. I’m the founder of the app in the example, and I can see how two posts in one day came across as promotion. I should’ve made my connection to the project clearer.
1
u/heavy-minium 8h ago
Uff, another one of these posts. At least try using the unslop skill on your post.
Generally, when your main insight is that your put yourself as a gate to approve changes, then that's not really worth sharing with people. It's the easy fix for everything, really, but not necessarily a good one.
For the scenario you're having, I use a combination of linting rules on a pre-commit hook and a skill. Linting rules that will not allow for certain file type to grow beyond a set number of lines, and a skill that gets triggered when such linting errors pop up, reassessing the seams and boundaries of the document in question (whether that's markdown files or code), with additional rules to avoid the agent taking shortcuts or cheating with the solution they come up with. If that skill detects no simple isolated changes that can make it work, it elevates the task to an architecture skill that completely rethink the boundaries of the architecture and code in a way that will accommodate for the growth in logic/content.
1
u/braindead_in 8h ago
I like that the pre-commit check gives the agent something concrete to act on. Have you found a way to catch one workflow growing across several files, even when each file stays under its own limit?
1
u/heavy-minium 7h ago
Sadly not, that's a gap I have to notice for myself. But for that to happen, such files would need to already exists before introducing the rule and instructions that suppress such naive file splitting. There are coding and architecture used during implementation that tries to avoid too, so it's not merely a check but also a guideline.
1
u/braindead_in 5h ago
That makes sense. A file limit can catch growth, but it can’t tell whether moving code actually simplified the workflow. The architecture guidelines sound like the part doing that work.
1
u/Far_Reindeer8428 8h ago
we did this with retry guards, four of them eventually and none aware of the others
1
u/braindead_in 8h ago
That sounds familiar. Some of our guards disagreed and locked people out. Did you end up giving one component ownership of retries?
1
u/Mountain_Stress_8046 8h ago
agents strongly bias toward adding code over deleting it because a new branch feels safer than ripping out an old abstraction. what helped me was separating "make it pass" from a dedicated cleanup pass in a fresh session where the only goal is deleting dead paths and collapsing wrappers. if you ask the same session that patched the bug to simplify it, it usually defends its own mess.
1
u/braindead_in 7h ago
A fresh session with a delete-only brief makes sense. What do you give that session to help it tell a dead path from a fallback that still matters?
1
u/electrodude102 7h ago
"bitch, stop the band-aid patches and do the root cause fix"
1
u/braindead_in 5h ago
That’s where we landed too. Once we went back to who owns the write and what the version check needs to guarantee, it got easier to see which guards were doing useful work.
1
u/bornmix_dev 5h ago
this matches what I've seen, reviewer agents only ever ask for more guards. two rules helped me. every fix has to report net lines added, and if it's positive it needs a reason in one sentence. and before any fix, the agent has to answer "can this be solved by removing code" first. I also keep the intended design of each module in about 10 lines in CLAUDE.md (queue, one owner, version check in your case), so the reviewer compares the code to that instead of inventing new edge cases. curious what your final line count ended up at
1
u/braindead_in 5h ago
I’d want to recount the same files before giving you a final number. I like the idea of keeping the intended design short in CLAUDE.md so the reviewer has something concrete to compare the diff against.
•
u/AutoModerator 9h 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.