CC
0 XP
0

Chapter 1: Ground Zero

When Things Go Wrong

concept5 min

When Things Go Wrong

Claude Code is powerful, but it's not perfect. Things will go wrong — wrong code, confusing errors, unexpected behavior. This section teaches you how to handle it like a pro.

💡Info

This is normal. Even experienced developers deal with errors constantly. The skill isn't avoiding errors — it's knowing how to recover from them quickly.

Claude Code generated wrong code

This happens. Maybe the component doesn't look right, the logic is off, or it used an approach you didn't want. You have three options:

  1. Reject it — say "no" or press n when Claude Code shows you the diff. Nothing gets written.
  2. Give feedback — instead of accepting or rejecting, type what's wrong: "Use a dropdown instead of radio buttons" or "The sort is backwards, it should be newest first."
  3. Accept and iterate — accept the code, see how it works, then ask Claude Code to fix specific things: "The delete button is too small. Make it an icon button with a trash icon."
⚠️Warning

The #1 beginner mistake: approving every diff without reading it. Always review what Claude Code writes. You don't need to understand every line, but scan for things that look wrong — files in the wrong place, deleted code that shouldn't be deleted, approaches that don't match what you asked for.

Prevent wrong code before it happens

One powerful technique: give Claude an out. Instead of "Build the search feature," try:

"Build the search feature. If you're unsure about how to handle the filtering logic with our existing category system, explain your options and ask me before implementing."

This prevents Claude from guessing when it's uncertain. It tells Claude it's OK to pause and check with you rather than generating code that might be wrong.

Tip

This technique — called "giving Claude an out" — comes from Anthropic's prompt engineering research. When you explicitly tell Claude it's OK to say "I'm not sure," it produces more accurate results because it stops trying to fill gaps with guesses.

Common errors and how to fix them

"command not found: claude"

Your terminal can't find Claude Code. This usually means npm's global bin directory isn't in your PATH.

Terminal
$npm list -g @anthropic-ai/claude-code

If it shows the package, your PATH needs fixing. Try running it with npx instead:

Terminal
$npx @anthropic-ai/claude-code

"EACCES: permission denied"

npm doesn't have permission to install globally. On macOS/Linux:

Terminal
$sudo npm install -g @anthropic-ai/claude-code

"Port 3000 is already in use"

Another process is using that port. Either kill it or use a different port:

Terminal
$npx next dev -p 3001

Dev server errors

If the dev server crashes or shows errors, try the basics:

  1. Stop the server with Ctrl+C
  2. Ask Claude Code: "I got this error: [paste the error]. What's wrong?"
  3. Let Claude Code fix it
  4. Restart the dev server

Context window filling up

Claude Code has a limited context window — it can only hold so much conversation in memory. Signs it's filling up:

  • Responses get shorter or less detailed
  • Claude Code forgets decisions from earlier in the conversation
  • It starts repeating itself or contradicting earlier choices

What to do:

Terminal
$/compact

This summarizes the conversation and frees up space. If things are really degraded, start a fresh session — your CLAUDE.md gives Claude Code all the project context it needs.

When to start fresh vs. keep going

SituationAction
Small fix or follow-upKeep going
Switching to a different featureStart fresh
Context seems degraded/compact first, then fresh if it doesn't help
Something went badly wrongStart fresh — clean slate
Long session (20+ back-and-forths)/compact or start fresh

The error-paste trick

When you hit an error you don't understand, paste it directly into Claude Code:

"I got this error: [paste the full error message] What went wrong and how do I fix it?"

💡Info

Wrapping the error in <error> tags helps Claude distinguish your instructions from the error text. Claude is specifically trained to recognize XML tags as boundaries between different types of content. This is called separating data from instructions — a core prompting technique.

Claude Code is excellent at diagnosing errors — it can read stack traces, identify the root cause, and fix the code. This alone makes it worth using.

Tip

Don't try to fix errors yourself by Googling first. Paste the error into Claude Code. It's faster and it learns your project context, so it gives better fixes than a generic Stack Overflow answer.

Try it: debug a real error

Let's practice the error-paste trick with a real bug. In your todo-app project, try this:

  1. Open Claude Code in your todo-app folder
  2. Ask: "Add a console.log to page.tsx that logs window.innerWidth at the top of the component function, outside any useEffect"
  3. Accept the change and check your browser — you'll see an error about window is not defined
  4. Copy the full error from the terminal or browser
  5. Paste it into Claude Code: "I got this error: [paste the error] What went wrong and how do I fix it?"
  6. Claude Code will explain that window doesn't exist during server-side rendering and fix it by wrapping it in a useEffect or adding a typeof window check
Important

You just debugged a real Next.js error — one of the most common ones beginners hit. The pattern is always the same: encounter error, paste it into Claude Code, let it explain and fix. You'll use this workflow hundreds of times.