Vibe coding with Claude Code course ยท Module 3: Twitter clone

The second mate's eye: reading the diff and /code-review

8 min read ยท
In this lesson11

The rat from lesson 2_8 got through the build, through lint and through your review because the change was a few characters and stood in the diff next to the badge you asked for. You read that code through the lens of the conversation in which you asked for the badge, and so did Claude. The Claude Code docs have advice for this: let someone who did not write the code look at it. The /code-review command starts a reviewer in a fresh subagent that has not seen your conversation, so it does not fall for the reasoning the code came from. Today you will take a new form feature through such a review before it reaches a commit.

A feature on its own branch

The captain writes a lot, so he wants to send a post from the keyboard, without reaching for the mouse. You start with a clean list in Source Control and a new branch from lesson 1_5: ask Claude for a branch feature/ctrl-enter, and in the permission prompt you will see git switch -c feature/ctrl-enter. On main the working version stays, and the branch will also be useful to the reviewer, as you will see in a moment.

Request for Claude Code:

In @components/Feed.tsx: Ctrl+Enter (on a Mac also Cmd+Enter) in the
post field sends the post the same way as the Send button. A plain
Enter still breaks the line. Change nothing else. At the end run
npm run build and npm run lint.

The request names the file, the behaviour and the boundary. The sentence about plain Enter protects what players already know, and "change nothing else" will be your measure when you read the diff.

What Claude wrote

In components/Feed.tsx the <textarea> field got keyboard handling:

onKeyDown={(e) => {
  if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
    e.preventDefault();
    e.currentTarget.form?.requestSubmit();
  }
}}

onKeyDown reacts to a key press. e.ctrlKey and e.metaKey tell you whether you hold Ctrl or Cmd together with Enter, and preventDefault() blocks a new line in the field. requestSubmit() submits the form as if someone clicked the submit button, so it runs the same handleSubmit. The ?. is honest here, because a text field does not have to lie inside a form, and then form is empty.

Reading the diff in Cursor

Open Source Control. You read the diff from the top: first the list of files, then each file separately. The list tells you about the scope before you read a single line: you asked for a change in one file, and the list shows two, Feed.tsx and LikeButton.tsx. Click the second one:

-      className="mt-3 text-sm text-gray-500 hover:text-red-600"
+      className="mt-3 text-sm font-semibold text-gray-500 hover:text-red-600"

Claude made the like button bold "while at it", probably to match the Send button. The change looks innocent, but it does not follow from the task: it mixes two matters in one commit and changes the look that nobody asked about. In every file on the list you look for three things: lines the task does not require, removed lines you did not expect, and tricks from lesson 2_8, such as eslint-disable. The /diff command in the session shows the same changes too.

Reject a change outside the scope

/rewind would undo the whole request, the Ctrl+Enter handling too. Here you need a rope for a single file, known from lesson 1_5:

! git restore components/LikeButton.tsx

git restore discards changes in a file that you have not added to a commit yet, and the exclamation mark runs the command straight from the session. On the list in Source Control only Feed.tsx remains. You can also tell Claude "Undo the change in LikeButton.tsx, it was not in the task" and see the same command in the permission prompt. Remember: Claude likes to tidy the surroundings, and the narrower the request, the easier it is to catch.

/code-review: fresh eyes

Now the review. Type in the session:

/code-review

Without an argument /code-review checks the commits of your branch that are not yet in its counterpart on GitHub, plus changes not saved in a commit. The branch feature/ctrl-enter has no counterpart yet, so Claude compares it with main: the review covers only your uncommitted change. On main with a few unpushed commits it would cover all of them. In the terminal the review runs in the background, in a subagent with its own context, and the results come to the conversation when they are ready. The reviewer looks for bugs in behaviour, reads your CLAUDE.md, and without the --fix flag changes nothing, it only compiles a report. Claude can also start a review itself when you simply ask: "review my changes".

What the reviewer found

Your report will have different words but a similar shape:

components/Feed.tsx: Ctrl+Enter bypasses the 280 character limit.
requestSubmit() submits the form even when the Send button is
disabled, and handleSubmit only checks for an empty post. A post
longer than 280 characters will land on the feed.

A finding is a hypothesis, as in lesson 2_8, so you check it before you believe it. Paste more than 280 characters into the field: the counter turns red and the button is disabled. Press Ctrl+Enter, and the too long post lands on the feed anyway. The button was only a lock on the door, and the keyboard shortcut came in through the window. Finding confirmed.

Fixing the finding

You order the fix in the conversation, with one narrow request:

Fix the review finding: handleSubmit in @components/Feed.tsx should
reject a post that is empty or longer than MAX_LENGTH, just like the
button. Nothing else. Then npm run lint and npx tsc --noEmit.

The diff has one changed line at the start of handleSubmit:

if (!draft.trim() || draft.length > MAX_LENGTH) return;

The rule "an empty or too long post does not pass" now lives where the form is really submitted, and the disabled button stays a hint for the eye. Repeat the test with 300 characters: Ctrl+Enter adds nothing, and a short post is sent from the keyboard as it should be.

Why not /code-review --fix? With this flag the reviewer makes the fixes itself, and when it runs in the background its edits bypass the session checkpoints: /rewind will undo only the files Claude changed earlier in the conversation, and the rest only Git can undo. To start with, I recommend the report route: you read the findings, check them and order the fixes one by one.

/simplify is not /code-review

Next to the review there is a second command with a similar sound. /simplify goes through the changed code for tidying: repetition, things to simplify, performance and the level of abstraction, and applies the fixes at once. It does not look for bugs in behaviour; the docs send you to /code-review for those. In older tutorials the two names get mixed up, because what is today's review used to be called /simplify. Before committing a feature you need a bug hunter, that is /code-review.

When to commit

You commit when you can answer "yes" to each of these questions:

  1. On the list in Source Control there are only the files from the task.
  2. You have read the diff of each of them.
  3. Every review finding is fixed or deliberately rejected, with a reason.
  4. npm run build, npm run lint and npx tsc --noEmit pass, and you saw the results yourself.
  5. The feature works in the browser, also in the case the reviewer pointed out.

Then one request, known from lesson 1_8: a commit with a message like "Ctrl+Enter sends a post, 280 limit also in handleSubmit", merging feature/ctrl-enter into main and git push, with the commands shown before they run.

Captain's review

You will catch typical mistakes in a review by three symptoms:

  1. Fixes without questions. Claude rushes to fix every finding. The reviewer can be wrong too, so with a doubtful finding ask for steps that show the problem.
  2. An empty review as proof. A report without findings does not mean the feature works. The proof is still the build, lint and a walk through the app.
  3. A commit with ballast. A file outside the scope stayed on the list, because nobody read the list of files before the commit.

Next step

The messenger is ready for its first mentor review: routes, components, state, saving in localStorage, CLAUDE.md with conventions and a history of small commits. Send the link to the repository in the task at the end of the location. In the next location you will build an Instagram clone and take each of its features through the same loop, with a review before the commit. In the editor below waits the form from this lesson with a fix switch: paste a long post and compare what Ctrl+Enter does before the review and after it.

Remember: a second mate who did not hear the council sees the reef that the captain no longer sees.

Code for this lesson: App.jsx
// Ctrl+Enter (Cmd+Enter on a Mac) sends the post.
// Paste more than 280 characters: the Send button gets disabled.
// Without the review fix, Ctrl+Enter still sends a post that is too long.
import { useState } from 'react';

const MAX_LENGTH = 280;

export default function App() {
  const [posts, setPosts] = useState([]);
  const [draft, setDraft] = useState('');
  const [reviewFix, setReviewFix] = useState(false);

  const handleSubmit = (e) => {
    e.preventDefault();
    if (!draft.trim()) return;
    // Fix for the /code-review finding: the limit is checked here too
    if (reviewFix && draft.length > MAX_LENGTH) return;

    setPosts([{ id: String(Date.now()), content: draft.trim() }, ...posts]);
    setDraft('');
  };

  const tooLong = draft.length > MAX_LENGTH;

  return (
    <div className="min-h-screen bg-gray-50 p-6 text-gray-900">
      <h1 className="text-3xl font-bold">Post form</h1>

      <label className="mt-4 flex items-center gap-2 text-sm">
        <input type="checkbox" checked={reviewFix} onChange={(e) => setReviewFix(e.target.checked)} />
        Review fix: the limit also in handleSubmit
      </label>

      <form onSubmit={handleSubmit} className="mt-4 rounded-lg border border-gray-300 bg-white p-4">
        <textarea
          value={draft}
          onChange={(e) => setDraft(e.target.value)}
          onKeyDown={(e) => {
            if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
              e.preventDefault();
              e.currentTarget.form?.requestSubmit();
            }
          }}
          rows={4}
          placeholder="Write a post and press Ctrl+Enter"
          className="w-full rounded border border-gray-300 p-2"
        />
        <div className="mt-2 flex items-center justify-between">
          <span className={tooLong ? 'text-sm text-red-600' : 'text-sm text-gray-500'}>
            {draft.length}/{MAX_LENGTH}
          </span>
          <button
            type="submit"
            disabled={!draft.trim() || tooLong}
            className="rounded bg-blue-600 px-4 py-2 font-semibold text-white disabled:opacity-50"
          >
            Send
          </button>
        </div>
      </form>

      <ul className="mt-4 space-y-2">
        {posts.map((post) => (
          <li key={post.id} className="rounded border border-gray-300 bg-white p-3">
            <span className={post.content.length > MAX_LENGTH ? 'font-bold text-red-600' : 'text-gray-500'}>
              {post.content.length} characters:
            </span>{' '}
            {post.content.slice(0, 60)}
          </li>
        ))}
      </ul>
    </div>
  );
}

Spotted a mistake in this lesson?

Check yourself

Answer the questions from this lesson. Pick an answer to see right away whether it is correct.

  1. 1. What does /code-review check when typed without an argument?

  2. 2. You asked for Ctrl+Enter in Feed.tsx, and in Source Control you also see a changed class in LikeButton.tsx. What do you do before the commit?

These are 2 of 3 questions for this lesson. Solve the rest in the game.

  1. QuestionWhat /code-review reviews without an argument
  2. QuestionA change outside the scope in the diff
  3. Question/code-review or /simplify
  4. Project to submitSend Kraken's Call to the mentor
  5. VideoModule summary

Useful articles