r/ClaudeCode • u/svet07 • 2d ago
Built with Claude I gave AI agents rules to keep code simple. The code got simpler, but I can't prove it helps. Could you try it on your codebase?
I've been developing with AI for a while, and sometimes asking for a new feature breaks something else. So I wrote rules for agents to keep the code simple, testable and broken down into logical modules, and a tool that checks them every time the agent stops: https://github.com/svetdev/cleat
It's built for Claude Code and with it. The checks run from a Stop hook, so when Claude tries to finish and a check fails, it gets the failure back and has to fix it before it can stop. I tested it by running Claude Code headless, the same tasks with and without the hook, a few hundred runs in total.
The results are mixed. The code does come out simpler. Left alone, the agent wrote overly complicated or copy-pasted code about half of the time. With the rules on, it didn't. But I can't find a way to prove that this makes it easier to keep adding features, compared to what the agent chooses to write by default. In my tests later changes cost the same either way.
A few things I learned along the way. Telling the agent in CLAUDE.md to keep code simple helped only for the one thing I named, and not at all for the rest. The hook worked every time. But about half the time the agent satisfied the complexity check by rewriting the same logic in a form the counter doesn't see, not by making it simpler. And Claude writes tests for its changes without being asked, so the checks for missing tests almost never fired.
All my tests were on tidy open-source projects, and I think that's part of the problem. So if someone would be willing to check a codebase they actually work in against my rules and report what they got, that would be much appreciated and could lead me further.
What you get out of it: how your code compares to 111 open-source projects, and which of your last 60 commits the rules would have stopped. It takes a few minutes.
It runs on your machine in a separate folder, doesn't touch your checkout and sends nothing about your code anywhere. It will ask you two questions: does adding features feel easy or does it tend to break things, and how much of the code was written by AI. At the end it gives you a small card with counts and ranges only, no names, paths or code, and offers to open a GitHub issue with the card filled in. You can also just paste the card here as a comment. The card alone is plenty, you don't need to report anything else.
The prompt for your agent is below. It's short because the full steps live in the repo, where you can read every command before running anything: https://github.com/svetdev/cleat/blob/main/study/try-it.md
I wrote them with AI.
If ../cleat-try already exists, ask me before deleting it. Then clone
https://github.com/svetdev/cleat into ../cleat-try/cleat and follow the prompt in its study/try-it.md on this repository. Work only inside ../cleat-try, do not change this repository, do not push or send anything anywhere, and ask me before installing anything.
•
u/AutoModerator 2d 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.
2
u/Far_Reindeer8428 2d ago
we added a similar size limit and also could never prove it helped, it just felt wrong less often
2
u/Ok_Gur_9033 2d ago
I have the no-hook version of this running in a Flutter app. Since June its CLAUDE.md has said widgets stay under 80 lines and get extracted past that, and nothing checks it. Today 17 of 457 build methods go past 80 lines, so it mostly held for the thing the rule names. The classes around them did worse: 66 of 521 widget and State classes are over 80, and the biggest are State classes, the paywall at 720 lines and the quick add sheet at 584.
That looks a lot like your result without the hook. The part the rule talks about stays small and the class next to it takes the size instead. Was your complexity check per function or per file?
1
u/pvera 🔆Pro Plan 2d ago
Have ponytail ( https://ponytail.dev/ ) review your code, it has a mode where it sees if any of your code is trying too hard to implement something. And its code review is pretty decent.
1
u/AryanThakor 2d ago
the agent hiding logic from the counter is the classic problem with scoring it. id have the hook print the offending function and why it failed instead of just the number, a bare score is the easiest thing to game. and for the "later changes cost the same" part, a few hundred runs on fresh tasks probably cant show it, the payoff from simpler code mostly shows up months into the same codebase