
My first experiments with AI review on merge requests were a bit disappointing. A long list of comments came back: a few real bugs, many opinions about naming and “consider extracting a method”, and some claims about TYPO3 that were simply true for an older version only. When the real bug is comment number eleven, nobody reads that far.
That is the problem with AI code review in one paragraph. The model is not bad at finding bugs; it is bad at knowing what you want from it. So this post is about the brief: what I hand over, what I ask for, and what I keep for humans.
Problems I faced
- Too much input. Pasting the whole repository “for context” made the reviews slower and vaguer, not better.
- Too broad a question. “Review this code” invites style comments, because style is always available.
- Missing project facts. The model does not know your TYPO3 version, your coding rules or which defaults the core gives you, so it guesses, and it guesses from older versions.
- No way to say “I am not sure”. Every finding sounded equally confident.
Solution
Step 1: Hand over the diff, the facts and the tests, nothing else
What the reviewer gets from me:
- The diff of the merge request against its target branch.
- Read access to the repository, so it can open a file when the diff is not enough. Read only, no shell, no edits.
- The facts: TYPO3 and PHP versions from
composer.lock, and the project rules fromCLAUDE.md. - What the pipeline already checked. If PHPStan and the tests are green, I say so, then the model does not waste comments on type errors the tooling already rules out.
What it does not get: secrets, production dumps, the ticket discussion with customer names. It does not need them to find a bug.
Step 2: A prompt that asks only for correctness
I keep the prompt in the repository as .claude/review-prompt.md, so it is reviewed like code:
You review one merge request of a TYPO3 v14 project (PHP 8.4).
Report only defects that change behaviour: wrong results, crashes,
security holes (SQL injection, XSS, missing access checks), data loss,
broken upgrades. Do not report style, naming, formatting or design
preferences. PHPStan level 8 and the test suite already passed.
For every finding give:
- file and line
- what goes wrong, with a concrete input or situation that triggers it
- the smallest fix
- confidence: high / medium / low
Before you report something about TYPO3 core behaviour, open the core
source in vendor/typo3/ and check it. If you cannot confirm it, mark the
finding low. If you find nothing, answer "No defects found." and stop.The last paragraph is the most important one. “Check the core source before you claim” removed most of the wrong TYPO3 comments, because the model now reads vendor/typo3 of exactly the version we use instead of remembering an old one. And “No defects found” as an allowed answer stops it from inventing something to look busy.
Step 3: Run it the same way every time
Locally or in a CI job, the call is the same. The diff goes in through stdin, the review comes out as text:
git diff origin/main...HEAD
| claude -p "Review this merge request diff."
--append-system-prompt-file .claude/review-prompt.md
--tools "Read"
--permission-mode dontAsk
--max-turns 20
--output-format json
| jq -r '.result'--tools "Read" limits the built-in tools to reading files, and dontAsk denies anything that would need a permission prompt, which nobody can answer in a pipeline anyway. The details of running this in CI are in my post about headless mode.
A sample review
Here is a small, made-up but very typical change: a repository method for an events extension.
public function findUpcomingByCity(string $city, int $limit = 10): array
{
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('tx_events_event');
return $queryBuilder
->select('uid', 'title', 'start_date', 'city')
->from('tx_events_event')
->where(
$queryBuilder->expr()->like('city', "'%" . $city . "%'"),
$queryBuilder->expr()->lt('start_date', time()),
)
->orderBy('start_date')
->setMaxResults($limit)
->executeQuery()
->fetchAllAssociative();
}A review of this method with the prompt above typically comes back with findings like these. I wrote them down in short form, because they show the good and the bad side together:
- High: SQL injection.
$cityis concatenated into theLIKEexpression. A city likex' OR '1'='1changes the query. Fix:$queryBuilder->createNamedParameter('%' . $queryBuilder->escapeLikeWildcards($city) . '%'). - High: wrong comparison. The method is called “upcoming” but
lt('start_date', time())returns events that already started. It should begte. - Medium: deleted and hidden records are returned, because there is no
deleted = 0condition. - Low: use the Context API instead of
time()so tests and previews can set the date.
Finding 1 and 2 are real bugs, and exactly the kind I want. Finding 3 is a false positive: the QueryBuilder applies the DefaultRestrictionContainer unless you remove it, and that container includes the deleted, hidden, start time and end time restrictions. This is exactly the kind of claim the “check the core source” rule is for: a reviewer that really opens DefaultRestrictionContainer.php in vendor/typo3 should drop it or at least mark it low. When it does not, a human has to. Finding 4 is a reasonable suggestion, but it is design, not a defect, so by my own rules it should not be in the list.
Two real bugs out of four findings is not a perfect score. But two real bugs on top, with a concrete input and the fix, is a review I read to the end. A long list of style remarks is not.
What stays with humans
I do not ask the AI whether the feature is a good idea, whether the events should be a separate table, or whether the change fits the architecture of the project. These decisions depend on things the diff does not show: the customer, the budget, the next two features, the person who maintains it after me. The human reviewer reads the AI findings first, deletes the noise, and then does the part only humans can do: behaviour, architecture and “do we really want this”.
And the AI review never approves. It is one more voice in the merge request, never the button.
If you try this in your team, start with the prompt above and keep a short list of false positives. After a few weeks that list tells you which facts are still missing from the brief. Cheers!