Vibe coding with Claude Code course ยท Module 3: Twitter clone
The rat in the hold: debugging with Claude Code
In this lesson10
After lesson 2_5 you gave Claude a short request: "Show a New badge on the captain's newest post". Claude put the badge into the post through the children from lesson 2_4, the build and lint passed, and you made a commit. The next day you liked your post about the course to the west three times, added a second post and saw something strange: the new post has three likes, and the old one zero. Not a single error in the browser console, and in the terminal only GET /feed 200. A bug that does not shout is a rat in the hold: you hear it only when you know where to listen.
First reproduce it
Before you write anything to Claude, check whether you can trigger the bug on demand. Write down the steps that end the same way every time:
1. Open /feed and add post A.
2. Click Like on post A three times.
3. Add post B.
Expected: B has Like (0), A has Like (3).
Actual: B has Like (3), A has Like (0).These five lines are the most valuable part of the report. They say what to do, what should happen and what really happens, so Claude does not have to guess. On top of that the same steps become the test: after the fix you repeat them and see at once whether the rat is gone.
How to give Claude a bug
The rule from lesson 0_5 says: show, do not describe. With bugs you have three kinds of evidence, and the choice depends on how the bug shows itself:
- a message: when something shouts, you copy the exact text from the terminal or from the Console panel of the browser's developer tools, with the file name and line number, not your own summary. The result of a command is easiest to attach with the exclamation mark from lesson 0_3, for example
! npm run build; - reproduction steps: when the bug is silent, like today, you give the steps, the expected result and the actual one;
- a screenshot: when it is about looks, you save the screenshot in the project folder and give its path in the request. Afterwards delete the file so it does not end up in a commit.
A note on the name: the /debug command in Claude Code is for trouble with Claude Code itself (it turns on writing its log), not for bugs in your app.
Request for Claude Code
Today you ask for hypotheses, that is possible causes, not for a fix. Whoever fixes before understanding the cause often patches the symptom.
Request for Claude Code:
Bug on /feed: likes jump to the new post. Steps: 1) add post A,
2) click Like on A three times, 3) add post B. Expected: B has Like (0),
A has Like (3). Actual: B has Like (3), A has Like (0). Console and
terminal show no errors, screenshot in the file screenshot-likes.png.
The bug appeared after the last commit with the New badge in
@components/Feed.tsx. Give me three hypotheses, from the most likely,
and for each a way to check it without changing code. Do not fix
anything yet.The request has the building blocks from lesson 0_5: symptom, steps, place and a hint about when the bug appeared. The last sentence stops Claude from patching, and in Manual mode every edit waits for your approval anyway.
What Claude answered: hypotheses
Your answer will have different words but a similar shape:
1. Index key in Feed.tsx. With the New badge, map got index and
<li key={index}>. The new post on top takes key 0, and React
keeps the LikeButton state with the key, not with the post.
Check: the line with key in Feed.tsx and the diff of the last commit.
2. LikeButton reads initialLikes only on the first render.
Check: useState(initialLikes) in LikeButton.tsx.
3. Likes are saved in localStorage under the position number.
Check: search localStorage in components/.Hypothesis two describes a real property of the button, but on its own it does not explain the bug, because before the badge everything worked. You rule out the third in a minute: searching the project in Cursor shows localStorage only in Feed.tsx, with the posts, not with the likes. The first remains.
Check one hypothesis
You check without changing code. Ask Claude: "Show the diff of the last commit for Feed.tsx", or type yourself in the session ! git show HEAD -- components/Feed.tsx, the last commit limited to one file. The change you are looking for looks like this:
- {posts.map((post) => (
- <li key={post.id}>
+ {posts.map((post, index) => (
+ <li key={index}>Claude needed index for the badge and changed the key along the way. From lesson 2_2 you know an index does not make a good key, because it changes when a new post jumps to the top. Now you see the effect: key tells React which element is which between renders. Post B gets key 0, which a moment earlier belonged to A, so React hands it A's button together with its state. The React docs warn that an index as a key often leads to subtle and confusing bugs. Hypothesis confirmed.
Fixing the cause
Only now the repair, named outright and narrow:
Hypothesis 1 confirmed. In @components/Feed.tsx restore key={post.id},
and keep index only for the New badge. Change nothing else.
Then npm run lint and npx tsc --noEmit, show the results.The diff has one line: <li key={post.id}>. Repeat the steps from the start of the lesson: B has zero, A has three, and the New badge travels to the newest post. The reproduction steps turned into a test that has just passed.
A typical agent mistake: fixing by hiding the symptom
When the cause is not obvious, an agent is tempted to silence the symptom. With this bug Claude may propose a random key and the report "likes no longer jump":
- <li key={index}>
+ // eslint-disable-next-line react-hooks/purity
+ <li key={Math.random()}>The report is true and the fix is bad. A random key changes on every render, so React builds the list from scratch every time. It is enough to type one letter into the field and all the likes of the captain's posts drop to zero. Lint reports the error Cannot call impure function during render here, and the eslint-disable comment silences it. The same trick has three other disguises: try/catch with an empty catch that swallows the error, a ?. placed where the value should not be empty, and as any or @ts-ignore known from lesson 1_4. You recognise them by the fact that the fix does not name the cause. Then ask: "What was the cause and why does this change remove it?".
A hand on the helm
Debugging is a good moment for three habits from lesson 0_5, this time in practice:
- Esc when Claude strays. If instead of hypotheses it starts rewriting
LikeButtonto save inlocalStorage, press Esc. Claude stops, keeps what it did and waits for a hint, and/rewindundoes the edits if it already saved any. - After two failed fixes,
/clear. If two fixes in a row did not help, the third only adds to a conversation full of wrong trails. Start a new conversation with one request that gathers what you learned: the symptom, the steps, the ruled-out hypotheses and a ban on silencing the linter. - Higher effort for a hard bug. The default effort level is
medium(as of November 2026). The docs advise raising it with/effort highor/effort xhighwhen the result depends on easy-to-miss cases, for example a bug in code you did not write. When only one message is hard, add the wordultrathinkto it: it asks for deeper thinking in that one turn and does not change the session setting.
Captain's review
Before you commit, check:
- The fix names the cause. In the diff the
keyline changed, not the button, an effect or the data inlocalStorage. - The steps pass. Repeated reproduction steps give the expected result, also after adding a third post.
- Nothing was silenced. In the diff there is no
eslint-disable,@ts-ignore, emptycatchor new?.. - The screenshot is outside the repository.
screenshot-likes.pngis not on the list in Source Control.
Next step
Ask for a commit with a message like "Post key from id: likes no longer jump to the new post". You have made this mistake once already, so it deserves a line in the ship's rules:
Add one line to the Pitfalls part of @CLAUDE.md: a list item key only
from a stable id, never from the map index. Change nothing else.Next time Claude will follow this rule without a reminder. And in lesson 2_9 you will see how a fresh reviewer catches such changes before they reach a commit. In the editor below waits a feed with a key switch: reproduce the bug on the index key, then repeat the steps on the id key.
Remember: you catch the rat in the hold by its tracks, not by covering your ears so you do not hear it.
Code for this lesson: App.jsx
// Debugging: likes that jump to the new post.
// Reproduction steps: 1) add post A, 2) click Like on A three times,
// 3) add post B. Expected: B has 0, A has 3.
// First reproduce the bug with the index key, then switch to the id key
// and repeat the same steps.
import { useState } from 'react';
import LikeButton from './components/LikeButton';
export default function App() {
const [posts, setPosts] = useState([]);
const [draft, setDraft] = useState('');
const [indexKey, setIndexKey] = useState(true);
const handleSubmit = (e) => {
e.preventDefault();
if (!draft.trim()) return;
const newPost = { id: String(Date.now()), content: draft.trim() };
setPosts([newPost, ...posts]);
setDraft('');
};
return (
<div className="min-h-screen bg-gray-50 p-6 text-gray-900">
<h1 className="text-3xl font-bold">Captain's feed</h1>
<label className="mt-4 flex items-center gap-2 text-sm">
<input type="checkbox" checked={indexKey} onChange={(e) => setIndexKey(e.target.checked)} />
Index key, key={'{index}'} (the buggy version)
</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)}
rows={2}
placeholder="Post A, then post B"
className="w-full rounded border border-gray-300 p-2"
/>
<button type="submit" className="mt-2 rounded bg-blue-600 px-4 py-2 font-semibold text-white">
Send
</button>
</form>
<ul className="mt-4 space-y-4">
{posts.map((post, index) => (
// The rat lives here: the key tells React which element is which
<li key={indexKey ? index : post.id} className="rounded-lg border border-gray-300 bg-white p-4">
<p>{post.content}</p>
<LikeButton initialLikes={0} />
{index === 0 && (
<span className="ml-2 rounded bg-amber-100 px-2 py-1 text-xs font-bold text-amber-800">
New
</span>
)}
</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. You asked Claude twice to fix the same bug and it is still wrong. What do you do?
2. Which of Claude's reports about fixing the jumping likes should worry you?
Hands-on tasks in the game
- Vertical ordering
Put the steps of debugging a silent bug with Claude Code in order: