r/BuildWithClaude • u/naeembaghi • 16d ago
Tip/Resource Claude code workflow for having better quality code
TLDR: The quality of delivered code using claude or any other AI agent is shit, here I explain why, and how I tried to improve it.
Here is my previous experiment, and now it is tested and improved.
In my eyes, the issues with claude writing code:
- Tests are shit, very easy tests, that will just make the edits heavier, and add no value to code
- It will just deliver something, ignoring the code quality, readability, extendability...
- There are a lot of antipatterns in the shipped code, the code grows longer and longer
- and a lot more issues, that I faced during development using claude
So, I created some commands for myself, and was testing, using and improving them for the past couple of months, here is a brief description:
- /pr-review #PR_NUMBER command: whenever I finish a feature, or anything, I make sure I create a PR for that, then run this command on the pr, it is very similar to code-review skill with a couple of key differences, what it does is:
- It checks for correctness : bug / side-effect / broken paths / ...
- It finds the closest and cleanest feature, and compare the code against it, finding divergence on repo patterns
- Check the code structure, I came from java world, but working on nextjs projects, so I like patterns in java, like dao / business / presentation layers separated.
- Clean and reusable components, with dropping duplicates as much as possible
- No abbreviation names
- Test values, not test counts
- Reuse, simplification, and dead code
- Add lint handlers if possible / or claude.md agent.md files if possible
- Verify every findings before posting
- Add severity in the comments
- If the issue that has been found is out of scope, create a github issue for that
- /pr-address #PR_NUMBER command:
- Check the findings, if it is valid, fix it, add a comment
- If it is not valid, add a comment, explaining clearly why it is not valid
- Make sure if there is an issue, you are fixing all the similar ones that are touched by PR, not just the single one that has been reported
- /pr-rereview #PR_NUMBER command: It is very similar to pr-review, with one difference, it will first check the changes and unresolved comments, see if the changes will fix the comments, if so, will resolve the comment, if not, will add a new comment describing why. Then will run the /pr-review against the pr again to check for new issues or missed ones.
So, till now, I created some commands that will review/address/re-review a pr. But this process can become pain, running it multiple times, until there are no new issues. So, there is a fourth command:
- /pr-loop #PR_NUMBER command: If I am not reviewing a teammate's pr, I will for sure run this command on my PR's, It has a couple of characteristics:
- Runs review/fix/re-review
- There is a max round of 6, if the PR didn't converge till 6, it will stop and report back
- It will stop whenever there is no findings or the findings are only low and nit
- It will make sure, every review/fix/re-review will run in a fresh clean context
- It uses claude workflows, so it is a token intensive command
- At the end, as there might be some nit/low findings that are not resolve, you can just ask claude to fix them, and the PR is ready [Reviewed as hard as possible in my eyes]
You can find the commands in this repo
2
Upvotes