Tuesday, February 3, 2026

Auto-Reviewing Claude’s Code – O’Reilly


A well-crafted system immediate will improve the standard of code produced by your coding assistant. It does make a distinction. For those who present tips in your system immediate for writing code and exams, coding assistants will comply with the rules.

Though that will depend on your definition of “will comply with.” In case your definition is “will comply with typically,” then it’s correct. In case your definition is “will comply with all the time” and even “will comply with more often than not,” then it’s inaccurate (until you’ve discovered a solution to make them dependable that I haven’t—please let me know).

Coding brokers will ignore directions within the system immediate frequently. Because the context window fills up and begins to intoxicate them, all bets are off.

Even with the newest Opus 4.5 mannequin, I haven’t seen a serious enchancment. So if we will’t depend on fashions to comply with system prompts, we have to spend money on suggestions cycles.

I’ll present you the way I’m utilizing Claude Code hooks to implement automated code overview on all AI-generated code in order that code high quality is larger earlier than it reaches the human within the loop.

You will discover a code instance that demonstrates the ideas mentioned on this submit on my GitHub.

Auto Code Evaluation for Quick, Semantic Suggestions

Once I speak about auto code overview on this submit, I’m describing a quick suggestions mechanism meant to overview widespread code high quality points. This will likely be run at any time when Claude has completed making edits, so it must be quick and environment friendly.

I additionally use coding assistants for detailed code evaluations when reviewing a PR, for instance. That may spin up a number of subagents and take a bit longer. That’s not what I’m speaking about right here.

The aim of the auto code overview is to bolster what’s in your system immediate, challenge documentation, and on-demand abilities. Issues that Claude might have ignored. A part of a multipronged method.

Wherever attainable, I like to recommend utilizing your lint and take a look at guidelines to bake in high quality, and depart auto code overview for extra semantic points that instruments can’t verify.

If you wish to set a most size on your information or most stage of indentation, then use your lint instrument. If you wish to implement a minimal take a look at protection, use your take a look at framework.

Semantic Code Evaluation

A semantic code overview seems at how nicely the code is designed. For instance, naming: Does the code precisely describe the enterprise ideas it represents?

AI will typically default to names like “helper” and “utils.” However AI can also be good at understanding the nuance and discovering higher names in the event you problem it, and it could possibly do that shortly. So it is a good instance of a semantic rule.

You’ll be able to ban sure phrases like “helper” and “utils” with lint instruments. (I like to recommend doing that.) However that received’t catch all the things.

One other instance is logic leaking out of the area mannequin. When a use case/software service queries an entity after which decides, it’s extremely seemingly your area logic is leaking into the applying layer. Not really easy to catch with lint instruments, however price addressing.

Domain logic leak

One other instance is default fallback values. When Claude has an undefined worth the place a price is anticipated, it is going to set a default worth. It appears to hate throwing exceptions or difficult the kind signature and asking, “Ought to we enable undefined right here?” It desires to make the code run it doesn’t matter what and irrespective of how a lot the system immediate tells it to not.

Default fallback values

You’ll be able to catch a few of this with lint guidelines nevertheless it’s very nuanced and will depend on the context. Generally falling again to a default worth is right.

Constructing an Auto Code Evaluation with Claude Hooks

For those who’re utilizing Claude Code and wish to construct an auto code overview for checks you could’t simply outline with lint or testing instruments, then an answer is to configure a script that runs on the Cease hook.

The Cease hook is when Claude has completed working and passes management again to the consumer to decide. So right here, you possibly can set off a subagent to carry out the overview on the modified information.

To set off the subagent it’s worthwhile to return the error standing code which blocks the primary agent and forces them to learn the output.

Trigger the subagent

I feel it’s usually thought of a finest follow to make use of a subagent centered on the overview with a really vital mindset. Asking the primary agent to mark its personal homework is clearly not an excellent method, and it’ll expend your context window.

The answer I exploit is obtainable on GitHub. You’ll be able to set up it as a plug-in in your repo and customise the code overview directions, or simply use it as inspiration on your personal answer. Any suggestions is welcome.

Within the instance above you possibly can see it took 52 seconds. In all probability faster than me reviewing and offering the suggestions myself. However that’s not all the time the case. Generally it could possibly take a couple of minutes.

For those who’re sitting there blocked ready for overview, this could be slower than doing it your self. However in the event you’re not blocked and are engaged on one thing else (or watching TV), this protects you time as a result of the tip outcome will likely be larger high quality and require much less of your time to overview and repair.

Scanning for Up to date Information

I need my auto code overview to solely overview information which were modified because the final pull request. However Claude doesn’t present this data within the context to the Cease hook.

I can discover all information modified or unstaged utilizing Git, however that’s not ok.

What I do as a substitute is to hook into PostToolUse by maintaining a log of every modified file.

PostToolUse

When the Cease hook is triggered, the overview will discover the information modified because the final overview and ask the subagent to overview solely these. If there aren’t any modified information, the code overview is just not activated.

Challenges with the Cease Hook

Sadly the Cease hook is just not 100% dependable for this use case for just a few causes. Firstly, Claude would possibly cease to ask a query, e.g. so that you can make clear some necessities. You may not need the auto overview to set off right here till you’ve answered Claude and it has completed.

The second cause is that Claude can commit adjustments earlier than the Cease hook. So by the point the subagent performs the overview, the adjustments are already dedicated to Git.

That may not be an issue, and there are easy methods to resolve it whether it is. It’s simply additional issues to bear in mind and setup.

The best answer could be for Anthropic (or different instrument distributors) to supply us hooks which are larger stage in abstraction—extra aligned with the software program improvement workflow and never simply low-level file modification operations.

What I’d actually love is a CodeReadyForReview hook which supplies all of the information that Claude has modified. Then we will throw away our customized options.

Let Me Know If You Have a Higher Strategy

I don’t know if I’m not trying in the proper locations or if the knowledge isn’t on the market, however I really feel like this answer is fixing an issue that ought to already be solved.

I’d be actually grateful in the event you can share any recommendation that helps to bake in code high quality earlier than the human within the loop has to overview it.

Till then I’ll proceed to make use of this auto code overview answer. Whenever you’re giving AI some autonomy to implement duties and reviewing what it produces, it is a helpful sample that may prevent time and scale back frustration from having to repeat the identical suggestions to AI.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles