Claude Code is robust, but problems can occur. Here's a complete guide to diagnose and solve the most common errors.
Connection Problems
Error: "API Key invalid"
Error: Invalid API key
Solutions:
- Verify the key:
echo $ANTHROPIC_API_KEY
- Reconfigure:
claude config set apiKey sk-ant-...
- Check permissions on console.anthropic.com
Error: "Rate limit exceeded"
Error: Rate limit exceeded. Please retry after X seconds.
Solutions:
- Wait for the indicated delay
- Reduce request frequency
- Upgrade to a higher plan (Max 20x)
- Use
/compactto reduce tokens
Error: "Connection timeout"
Error: Request timed out
Solutions:
- Check internet connection
- Check status: status.anthropic.com
- Retry with longer timeout:
claude --timeout 120000
Context Problems
Error: "Context window exceeded"
Error: Maximum context length exceeded
Cause: Conversation + files exceed token limit.
Solutions:
- Use
/compactimmediately:
/compact
- Start a new session:
/clear
- Limit referenced files:
❌ @src/**/*.ts (too many files)
✅ @src/api/auth.ts (specific file)
Claude "forgets" instructions
Cause: Context is saturated and old instructions are truncated.
Solutions:
- Add instructions to CLAUDE.md:
# CLAUDE.md
## Important rule
Always use early returns
- Repeat critical instructions:
> Reminder: use strict TypeScript.
> Now, implement feature X.
- Use
/compactthen reformulate
File not found
Error: File not found: @src/missing.ts
Solutions:
- Verify the path:
ls src/missing.ts
- Use correct relative path:
@./src/missing.ts (with ./)
@src/missing.ts (without ./)
- Check read permissions
Execution Problems
Bash command blocked
Claude is waiting for permission...
Solutions:
- Accept or reject manually
- Add to permissions:
{
"permissions": {
"allow": ["Bash(npm run:*)"]
}
}
- Use Accept Edits mode (Shift+Tab)
Error: "Tool not available"
Error: Tool 'WebFetch' is not available
Cause: Tool is disabled or unavailable.
Solutions:
- Check permissions:
/permissions
-
Enable tool in settings.json
-
Verify tool exists (some are experimental)
Infinite loop
Claude continues endlessly on a task.
Solutions:
- Interrupt with
Ctrl+C - Use
Esc Escto go back - Reformulate with a limit:
> Do this task in maximum 3 steps
Performance Problems
Very slow responses
Possible causes:
- Context too large
- High server load
- Slow network connection
Solutions:
- Reduce context:
/compact
- Limit files:
> Analyze only @src/api/auth.ts
- Use a faster model:
claude --model haiku
High costs
Diagnosis:
/cost
Solutions:
/compactregularly- Be more precise in prompts
- Avoid massive file reads
- Use Haiku for simple tasks
Installation Problems
npm install fails
npm install -g @anthropic-ai/claude-code
# Error: EACCES permission denied
Solutions:
- Use npx:
npx @anthropic-ai/claude-code
- Fix npm permissions:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
- Use a Node version manager:
nvm use 20
npm install -g @anthropic-ai/claude-code
Incompatible Node version
Error: Unsupported Node.js version
Solution:
nvm install 18 # or 20
nvm use 18
Hook Problems
Hook doesn't execute
Checks:
- Hook syntax:
{
"hooks": {
"PreToolUse": [{
"matcher": "Edit",
"hooks": [{
"type": "command",
"command": "echo 'Hook triggered'"
}]
}]
}
}
- Debug logs:
CLAUDE_CODE_DEBUG=1 claude
- Script permissions:
chmod +x ./scripts/hook.sh
Hook blocks Claude
Hook returned: BLOCK
This is intentional if the hook detects a problem.
Solutions:
- Check hook conditions
- Modify the file to satisfy the hook
- Temporarily disable the hook
MCP Problems
MCP server won't start
Error: Failed to connect to MCP server
Solutions:
- Verify installation:
npx postgres-mcp-server --version
- Test manually:
npx postgres-mcp-server
- Check environment variables:
echo $DATABASE_URL
MCP timeout
Error: MCP server timed out
Solutions:
- Increase timeout:
{
"mcpServers": {
"postgres": {
"timeout": 30000
}
}
}
- Check network connectivity to the service
General Diagnosis
Debug mode
CLAUDE_CODE_DEBUG=1 claude
Displays detailed logs to identify the problem.
Check configuration
claude config list
Reset configuration
rm -rf ~/.claude
claude config set apiKey sk-ant-...
Check logs
cat ~/.claude/logs/claude-code.log
Troubleshooting Checklist
□ Internet connection OK?
□ API Key valid?
□ Node.js version compatible (≥18)?
□ Claude Code up to date?
□ File permissions OK?
□ Context not saturated?
□ Hooks configured correctly?
□ MCP servers accessible?
Getting Help
Official documentation
/help
Community
- GitHub Issues: github.com/anthropics/claude-code/issues
- Anthropic Discord
- Stack Overflow tag
claude-code
Anthropic Support
For Enterprise customers: support.anthropic.com
What's Coming Tomorrow
In Day 18, we'll explore the status line and terminal customization - configure Claude Code display according to your preferences.
This article is part of the "Master Claude Code in 20 Days" series. Day 16: Billing and costs

