Course navigation
Claude CodeLesson 8 of 25

Debugging & Troubleshooting

Every Claude Code user hits a wall at some point — an auth error, a session that runs out of context, a tool that fails, or a rate limit mid-task. Each problem has a clear fix below.

When something goes wrong

Most errors fall into five categories. Read the error message, identify which category it belongs to, then jump to the right section.

StepWhat to do
1. Read the full errorThe first line usually says exactly what failed.
2. Identify the categoryAuth, context, tool, rate limit, or other.
3. Apply the specific fixUse the section below for your error type.
4. Verify and continueRe-run the same task — most errors clear immediately.

Authentication errors

Auth errors prevent Claude Code from starting or making requests. They look alarming but almost always have a fast fix.

Not authenticated / login required

Error: Not authenticated. Please run 'claude auth login' to authenticate.

Why: Your session has expired or you have never signed in on this machine.

  1. Run claude auth login in the terminal.
  2. Complete the browser flow — paste the code back when prompted.
  3. Run claude --version to confirm.
Terminal — fixing auth
$ claude auth login
Opening browser for authentication…
Paste the code from your browser:
(paste code here, press Enter)
Authenticated successfully
$ claude --version
Claude Code 1.x.x — logged in as you@example.com

Invalid or expired API key

AuthenticationError: invalid_api_key — The provided API key is invalid.

  1. Go to console.anthropic.com → API Keys and create a new key.
  2. Update ANTHROPIC_API_KEY in your shell profile or .env file.
  3. Restart the terminal and run claude auth status.
Never commit API keys to git. Add .env to .gitignore before your first commit.

OAuth redirect fails (VS Code extension)

Sign-in window opens but redirects to an error page or just closes.

  1. Try signing in again — sometimes one retry is enough.
  2. Disable browser extensions that block redirects (uBlock, Privacy Badger).
  3. Use Command Palette: “Claude Code: Sign Out”, then sign in fresh.
  4. If still failing, run claude auth login in the integrated terminal.

Context overflow

Every conversation has a context window — a limit on how much text Claude can hold in memory at once. Long sessions eventually hit this limit.

$ claude
You: add pagination to the orders table
Claude: I'm sorry, but this conversation has exceeded the context limit.
Or Claude starts giving inconsistent answers that ignore earlier instructions.
FixHow
Start a new conversationPress Ctrl+N (with enableNewConversationShortcut: true) or open a new Claude tab. Re-attach the relevant file with @filename and summarise the task.
Use /compactType /compact in the prompt box. Claude compresses history into a short summary and continues with more room.
Use CLAUDE.mdPut stack, conventions, and folder structure in CLAUDE.md so you never lose that context when starting fresh.
Claude panel — /compact
/compact
Conversation compacted — 3,200 tokens freed
Claude: Ready to continue. What would you like to do next?
Prevention: Keep individual sessions focused on one feature or task. Start a new conversation for each new feature rather than continuing a 10-turn conversation indefinitely.

Tool failures

Claude Code uses tools to read files, run commands, and write code. When a tool fails, Claude either reports an error or silently falls back to guessing.

ErrorCauseFix
EACCES: permission deniedClaude tried to access a file your user cannot read or write.Check ownership with ls -la, then chown or chmod. Retry the same request.
bash: npm: command not foundThe tool is not installed or not on PATH in Claude's shell.Install the tool, verify PATH with echo $PATH, restart VS Code.
Claude describes the change but does not editPlan mode is active, or the file was not mentioned.Switch to Default mode, add @filename, or approve the plan first.
Terminal — diagnosing a missing tool
$ which node
node not found
$ nvm install --lts
Now using node v22.x.x (npm v10.x.x)
$ which node
/Users/you/.nvm/versions/node/v22.x.x/bin/node

Rate limits

Rate limits are temporary pauses — not permanent errors. Claude Code tells you exactly how long to wait.

RateLimitError: You have exceeded your request rate.
Please wait 42 seconds before retrying.
Claude Code will automatically retry after the cooldown.
PlanDefault limitWhat to do
FreeLow (shared pool)Wait the cooldown — usually under 60 s
Pro / TeamHigher per-minute quotaWait a few seconds; most limits reset quickly
API keySet on your consoleIncrease limits at console.anthropic.com
Rate limits during long-running tasks are normal. Break large tasks into smaller feature requests to stay within per-minute quotas.

Other common issues

ProblemQuick fix
Claude edits the wrong fileAlways include @filename in your prompt. Do not rely on Claude inferring the right file.
Claude installed a package you didn't wantRewind to the checkpoint before that message, then re-prompt with the exact package name.
The VS Code extension panel won't openRun "Developer: Reload Window" from the Command Palette, then try again.
Claude loops or repeats itselfUse /compact to clear the context, or start a fresh session with a precise single-task prompt.
claude command not found in terminalThe extension bundles the CLI but it may not be on PATH. Run: which claude. If missing, install via npm i -g @anthropic-ai/claude-code.
Network error / ECONNREFUSEDCheck your internet connection. If behind a proxy, set HTTPS_PROXY in your environment.
TypeScript errors after Claude editsAsk Claude: 'Fix TypeScript errors in @filename' — share the exact error from the Problems panel.

Quick diagnosis checklist

CheckDetail
Read the full error messageThe first sentence usually contains the fix
Check authenticationclaude auth status — takes 2 seconds
Check the permission modeDefault for most tasks; not Plan or Auto-accept by mistake
Verify the file was mentioned@filename prevents almost all wrong-file edits
Look at context lengthLong session? Run /compact or start fresh
Check installed toolswhich node, which npm, which git — confirm they're on PATH
Rewind if something brokeHover a message → rewind code — undo without losing history

Before you continue

  • Read the full error first — the first line usually points to the fix.
  • Auth errors clear with claude auth login.
  • Context overflow: run /compact or start fresh with @filename and CLAUDE.md.
  • Tool failures often mean a missing binary or wrong permission mode.
  • Next: writing and running tests with Claude Code.

What's Next

You've built a real app end-to-end with Claude Code. The next lesson goes deeper on testing — how to write, run, and iterate on tests for any project.