AI code review without losing your code-reading skills
How to use AI code review without losing your own skills: review first yourself, ask the AI second, and turn each comment into a test that finds wrong claims.
Using an AI for code review well means treating each of its comments as a hypothesis to check, not as a verdict. You read the code yourself first, ask the AI second, and then turn every comment into a test you can run. Are you afraid your code reading will get worse now that AI exists? Let's try it.
Now that AI exists, who reads this code?
In the previous post, every commit of the expense tracker app already had a message that says why it exists. Now there is a new pull request: a function that computes the total spending in one month. Before merging it, somebody has to read it, and in a one-person side project that "somebody" is usually an AI. I think this is reasonable, but there is a trap: if every time you hand code to an AI and only read its result, then after a few months your own ability to spot bugs has not grown. This post is how I use an AI review and still train my own eye.
Here is the function to review. It takes a list of expenses, each with a time, an amount and a note, and returns the total for one month (for example "2026-12"). It runs, and it reads as reasonable:
// The code under review: the total spending in one month for the expense tracker app.
// This is the "pull request" that needs a review. It runs and looks reasonable, but it has real bugs (see check-comments.ts).
export type Expense = { at: string; amount: number; note: string };
// month looks like "2026-12". Returns the total amount of the expenses that fall in that month.
export function totalForMonth(expenses: Expense[], month: string): number {
expenses.sort((a, b) => a.at.localeCompare(b.at));
let total = 0;
for (const expense of expenses) {
const date = new Date(expense.at);
const key = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}`;
if (key === month) total += expense.amount;
}
return total;
}Before you read on, I invite you to stop for one minute. Read it line by line and write down on paper every place you feel suspicious, even if you are not sure. That is step one of the process I describe below, and it only works if you do it before you see anybody's answer.
A three-step process
I split a review into three steps in a fixed order.
Step one is your own review, without tools. The code review guide of Google, in the section what to look for in a code review, puts design first (does this change belong here, is it the right time), then functionality: does it do what the author intended, and the reviewer should still think about edge cases and about bugs that can be seen just by reading. I use that list as a frame: design, functionality and edge cases, complexity, tests, naming. For the function above, the most worthwhile edge case is: which expense sits right on the border between two months, and in which time zone is "month" measured?
Step two is to ask an AI, but with a structure. I do not ask "please review this" and get an essay back. I ask it to give every comment with one concrete input that triggers the bug, so step three has something to run. Here is the template I use:
Review the code below. For each problem, give me: (1) the line involved, (2) a concrete input that makes the bug happen and the wrong result I should expect,
(3) the severity: bug, risk, or only a matter of style. If you are not sure about something, say you are not sure instead of stating it as fact.
Do not fix the code, only describe the problems. Do not praise.Step three is to check each comment. This is the step that most people skip, and it is the most important one, because an AI review can be wrong. I will show you right away.
Turn each comment into a test
I do not run a real model in this post. The list of comments below is an example I wrote by hand, imitating one AI review of the code above: three correct comments, one comment that is wrong about the current behaviour, and one opinion about style. I deliberately mixed real bugs with a wrong comment, because in real life the result of an AI review is mixed in the same way.
Each comment is written with a check function: a piece of code that returns true if the described problem is real. A comment that is only about style (for example naming) has no such function, because it cannot be checked by running:
// Every comment from a reviewer (or from an AI) is a HYPOTHESIS. Here I turn each comment into a test you can run.
// The list of comments below is an illustrative example that I wrote by hand, imitating one AI review of the code in month-total.ts.
import { totalForMonth, type Expense } from "./month-total.ts";
export type ReviewComment = {
number: number;
text: string;
// A function that returns true if the described bug is real. undefined: a comment about style, which cannot be checked by running.
check?: () => boolean;
};
// 6:30 a.m. on 1 December 2026 in Vietnam, which is 23:30 on 30 November in UTC.
const MORNING_OF_DEC_1: Expense = { at: "2026-12-01T06:30:00+07:00", amount: 29_000, note: "coffee" };
export const COMMENTS: ReviewComment[] = [
{
number: 1,
text: "getFullYear/getMonth use the time zone of the machine that runs the code. On a server running UTC, the expense at 6:30 a.m. on 1 December Vietnam time is counted in November.",
check: () => totalForMonth([{ ...MORNING_OF_DEC_1 }], "2026-12") === 0, // this expense belongs to December: getting 0 means it was put in the wrong month
},
{
number: 2,
text: "expenses.sort changes the order of the array of the caller (sort works in place), so a function that only computes a total has a side effect.",
check: () => {
const input: Expense[] = [{ at: "2026-12-02T10:00:00+07:00", amount: 1, note: "b" }, { at: "2026-12-01T10:00:00+07:00", amount: 1, note: "a" }];
totalForMonth(input, "2026-12");
return input[0].note === "a";
},
},
{
number: 3,
text: 'An invalid month such as "2026-13" will make the function throw an error.',
check: () => {
try {
totalForMonth([{ ...MORNING_OF_DEC_1 }], "2026-13");
return false; // it did not throw: the comment is wrong
} catch {
return true;
}
},
},
{
number: 4,
text: "The sort is not needed: the total does not depend on the order of the expenses, so it can be removed completely.",
check: () => {
const expenses: Expense[] = [{ at: "2026-12-02T10:00:00+07:00", amount: 5, note: "b" }, { at: "2026-12-01T10:00:00+07:00", amount: 7, note: "a" }];
// If reversing the input does not change the total, the order has no effect, so the sort really is redundant.
return totalForMonth([...expenses], "2026-12") === totalForMonth([...expenses].reverse(), "2026-12");
},
},
{ number: 5, text: "The variable `key` should have a clearer name, for example `monthOfExpense`." },
];There is one technical detail: comment number 1 depends on the time zone of the machine that runs the code, and Node reads the time zone at startup. So the script runs the checks twice, in two child processes with a different TZ environment variable (UTC like a server in the cloud, and Vietnam time like your own machine):
// Run every comment as a test, twice: once with the UTC time zone (like a server), once with Vietnam time.
// Run: node check-comments.ts
import { execFileSync } from "node:child_process";
import { COMMENTS } from "./src/comments.ts";
// Child mode: run the tests in the current process and print the result as JSON (the time zone comes from the TZ variable of the process).
if (process.argv[2] === "--child") {
console.log(JSON.stringify(COMMENTS.map((comment) => (comment.check ? comment.check() : null))));
process.exit(0);
}
// Node reads the time zone at startup, so to change the time zone you must start a new process with a different TZ variable.
const run = (tz: string): (boolean | null)[] =>
JSON.parse(execFileSync(process.execPath, [import.meta.filename, "--child"], { env: { ...process.env, TZ: tz }, encoding: "utf8" }));
const resultUtc = run("UTC");
const resultVn = run("Asia/Ho_Chi_Minh");
for (const [i, comment] of COMMENTS.entries()) {
const utc = resultUtc[i];
const vn = resultVn[i];
const verdict = utc === null ? "an opinion about style, cannot be checked by running" : utc || vn ? "CONFIRMED: the comment is right" : "NOT REPRODUCED: the comment is wrong";
console.log(`#${comment.number} ${verdict}${utc !== vn && utc !== null ? ` (UTC: ${utc}, Vietnam time: ${vn})` : ""}\n "${comment.text.slice(0, 90)}${comment.text.length > 90 ? "…" : ""}"`);
}To run it, you need Node.js 22.18 or newer (Node runs .ts files directly from that version, so nothing else to install) and this folder layout:
ai-review/
package.json ({ "type": "module" } is enough)
check-comments.ts
compare-versions.ts (used in the next section)
src/month-total.ts
src/comments.ts
src/month-total-fixed.ts (used in the next section)
src/month-total-fixed.test.tsnode check-comments.ts#1 CONFIRMED: the comment is right (UTC: true, Vietnam time: false)
"getFullYear/getMonth use the time zone of the machine that runs the code. On a server runn…"
#2 CONFIRMED: the comment is right
"expenses.sort changes the order of the array of the caller (sort works in place), so a fun…"
#3 NOT REPRODUCED: the comment is wrong
"An invalid month such as "2026-13" will make the function throw an error."
#4 CONFIRMED: the comment is right
"The sort is not needed: the total does not depend on the order of the expenses, so it can …"
#5 an opinion about style, cannot be checked by running
"The variable `key` should have a clearer name, for example `monthOfExpense`."Look at each line. Comment number 1 is only true on a machine in UTC (UTC: true) and does not show up on a machine in Vietnam time (Vietnam time: false). This is exactly the kind of bug you never see when you test on your own machine: the code is right on your machine and wrong once it reaches the server. Comments 2 and 4 are right: the function reorders the array of the caller, and that sort is redundant because the total does not depend on the order. Those two comments are really two sides of one thing, and removing the sort fixes both.
Comment number 3 is the one most worth learning from: it claims that an invalid month will make the function throw, but in reality the function does not throw, it silently returns 0. If you believe this comment without checking, you relax because you think the function already handles that case, when in fact it does not. A wrong comment that sounds confident is more dangerous than a missing comment, because it lulls you into a feeling of safety. Number 5 is an opinion, and it is yours to decide.
Fix what was confirmed
I make three changes. First, compute the month in Vietnam time explicitly, through Intl.DateTimeFormat with the time zone Asia/Ho_Chi_Minh, instead of the machine-dependent getMonth(). Second, remove the sort. Third, comment number 3 was wrong about the current behaviour but it raises a design question worth thinking about: what should the function do when it receives a meaningless month? Returning 0 silently hides the mistake of the caller, so I choose to throw a clear error. A wrong comment can still be useful, as long as you do not believe it and instead keep thinking from the question it raised:
// The version fixed according to the confirmed comments: the month is always computed in Vietnam time, the array of the caller is not changed
// (and the redundant sort is gone), and a month in the wrong format raises a clear error instead of silently returning 0.
import type { Expense } from "./month-total.ts";
const MONTH_FORMAT = /^\d{4}-(0[1-9]|1[0-2])$/;
// The locale "sv-SE" is only there to get the form "2026-12"; the time zone is what decides the result.
const vietnamMonth = new Intl.DateTimeFormat("sv-SE", { timeZone: "Asia/Ho_Chi_Minh", year: "numeric", month: "2-digit" });
export function totalForMonth(expenses: readonly Expense[], month: string): number {
if (!MONTH_FORMAT.test(month)) throw new RangeError(`Month must look like YYYY-MM, got "${month}"`);
let total = 0;
for (const expense of expenses) {
if (vietnamMonth.format(new Date(expense.at)) === month) total += expense.amount;
}
return total;
}I verify it in two ways. The first is to compare the old and the new version on the same four expenses, running on a machine in two time zones. These four expenses include two that sit right at a month boundary: 6:30 a.m. on 1 December Vietnam time, and 0:00 on 1 January of the next year Vietnam time:
// The December 2026 total of the same four expenses, computed with the old version and the fixed version, on a machine in two different time zones.
// Run: node compare-versions.ts
import { execFileSync } from "node:child_process";
import { totalForMonth as oldTotal, type Expense } from "./src/month-total.ts";
import { totalForMonth as newTotal } from "./src/month-total-fixed.ts";
if (process.argv[2] === "--child") {
const expenses: Expense[] = [
{ at: "2026-12-01T06:30:00+07:00", amount: 29_000, note: "coffee" },
{ at: "2026-11-30T23:59:59+07:00", amount: 10_000, note: "banh mi" },
{ at: "2026-12-31T23:59:59+07:00", amount: 5_000, note: "tea" },
{ at: "2027-01-01T00:00:00+07:00", amount: 7_000, note: "bac xiu" },
];
console.log(JSON.stringify({ old: oldTotal([...expenses], "2026-12"), fixed: newTotal(expenses, "2026-12") }));
process.exit(0);
}
for (const tz of ["Asia/Ho_Chi_Minh", "UTC"]) {
const out = JSON.parse(execFileSync(process.execPath, [import.meta.filename, "--child"], { env: { ...process.env, TZ: tz }, encoding: "utf8" }));
console.log(`machine on ${tz.padEnd(16)}: old version ${out.old}, fixed version ${out.fixed}`);
}
console.log("the correct answer is 34000 (29000 + 5000)");node compare-versions.tsmachine on Asia/Ho_Chi_Minh: old version 34000, fixed version 34000
machine on UTC : old version 12000, fixed version 34000
the correct answer is 34000 (29000 + 5000)The second line is the evidence. On a machine in UTC, the old version returns 12,000 instead of 34,000 (amounts are in Vietnamese đồng, so 34,000 is about $1.30). It is wrong in two directions at once: the expense of 29,000 at 6:30 a.m. on 1 December Vietnam time (23:30 on 30 November in UTC) is pushed into November and disappears from the total, while the expense of 7,000 at 0:00 on 1 January Vietnam time (17:00 on 31 December in UTC) is wrongly pulled into December. The total of 12,000 is 5,000 that is right plus 7,000 that is wrong. The fixed version returns 34,000 in both time zones.
The second way is a test. The test below runs twice, once with TZ=UTC and once with TZ=Asia/Ho_Chi_Minh (in PowerShell you set the variable with $env:TZ = "UTC" before the command), and both runs must give the right result. It checks the month boundaries, that the array of the caller is not changed, and that a month in the wrong format is reported as an error:
import assert from "node:assert/strict";
import { test } from "node:test";
import type { Expense } from "./month-total.ts";
import { totalForMonth } from "./month-total-fixed.ts";
const expense = (at: string, amount: number): Expense => ({ at, amount, note: "x" });
test("month boundaries in Vietnam time, whatever time zone the machine runs in", () => {
// Run this file twice: TZ=UTC and TZ=Asia/Ho_Chi_Minh. Both must give the same result.
const expenses = [
expense("2026-12-01T06:30:00+07:00", 29_000), // December (23:30 on 30 November in UTC)
expense("2026-11-30T23:59:59+07:00", 10_000), // still November
expense("2026-12-31T23:59:59+07:00", 5_000), // still December
expense("2027-01-01T00:00:00+07:00", 7_000), // January of the next year
];
assert.equal(totalForMonth(expenses, "2026-12"), 34_000);
assert.equal(totalForMonth(expenses, "2026-11"), 10_000);
assert.equal(totalForMonth(expenses, "2027-01"), 7_000);
});
test("does not change the order of the array of the caller", () => {
const expenses = [expense("2026-12-02T10:00:00+07:00", 1), expense("2026-12-01T10:00:00+07:00", 1)];
const before = expenses.map((e) => e.at);
totalForMonth(expenses, "2026-12");
assert.deepEqual(expenses.map((e) => e.at), before);
});
test("a month in the wrong format throws, a month with no expenses returns 0", () => {
for (const bad of ["2026-13", "2026-00", "2026-1", "12/2026", ""]) assert.throws(() => totalForMonth([], bad), RangeError, bad);
assert.equal(totalForMonth([], "2026-12"), 0);
});TZ=UTC node --test src/month-total-fixed.test.ts
TZ=Asia/Ho_Chi_Minh node --test src/month-total-fixed.test.ts# tests 3
# pass 3
# fail 0How do you keep your skills when an AI reviews for you?
I have no data on this, so everything below is a personal habit, not a scientific conclusion. In my view, the order "read it yourself first, ask the AI second" matters more than any other trick. If you look at the list of the AI first, your mind is anchored to that list, and you only judge what it already pointed out instead of searching yourself. If you write your own suspicions first, then when you compare, you know exactly what you caught and what you missed.
I record the result of the comparison in a small table, one row per review: did you catch it before asking the AI, only the AI caught it, or did the AI say something wrong. A plain text file is enough:
| Date | Code | I caught first | Only the AI caught | The AI was wrong | Lesson |
|---|---|---|---|---|---|
| 16/11 | totalForMonth | (write a number) | (write a number) | 1 (comment #3) | Always run it when the AI says "will throw" |The number "only the AI caught" tells you which kind of bug you are weak at, and following it over a few weeks shows whether you are improving or depending more and more on the tool. Besides that, from time to time I review a whole change myself without an AI, like an exercise, and if I have teammates, I ask them to review so I can learn how other people read code.
What can AI review not do for you yet?
The tests above can only check what can be checked by running. The first question in the list of Google, design, cannot be run: does this change belong here, should we add this feature now, will a later feature be blocked by it. That is where an AI lacks the most context, because it does not know your plans. I can still ask an AI about design, but I treat the answer as an opinion and not as verification.
There is one more obvious limit: comment number 3 was wrong yet sounded very convincing. Any time an AI says "definitely" or "will", that is a signal for you to run it, not a signal to relax.
You almost pasted the API key into the prompt
The process above needs you to hand code to an AI. And this is where a small habit can do big damage: when in a hurry, people paste a whole config file, or a chunk of log, into the chat box and forget that it contains an API key, a password or customer data. What you should and should not give to an AI tool is the topic of the next posts.
You can follow the whole journey in Build a side project with AI. If you are preparing for interviews, the questions about using AI while programming and about code review are in the interview question bank.