Common issues and solutions for the Claude Code course.
Cause: The API key environment variable isn't configured.
Solutions:
-
Check your .env file:
cat .env # Should show: ANTHROPIC_API_KEY=sk-ant-... -
Load the environment:
# macOS/Linux source .env # or export $(cat .env | xargs) # Windows (PowerShell) Get-Content .env | ForEach-Object { if ($_ -match '^([^=]+)=(.*)$') { [Environment]::SetEnvironmentVariable($matches[1], $matches[2]) } }
-
Set directly in terminal:
export ANTHROPIC_API_KEY=sk-ant-your-key-here
Cause: The API key format is incorrect or the key has been revoked.
Solutions:
- Verify key format starts with
sk-ant- - Check key status at console.anthropic.com
- Generate a new key if needed
Cause: Too many API requests in a short time.
Solutions:
- Wait a few minutes and retry
- Implement exponential backoff (the SDK does this automatically)
- Upgrade your API tier if needed
Note: This course has no root tsconfig.json. Demos run via npx tsx (JIT compilation), so npm run build (tsc) is not part of the workflow. The tsconfig.json snippets below apply only if you scaffold your own standalone TypeScript MCP project.
Cause: Dependencies not installed or import path issues.
Solutions:
-
Reinstall dependencies:
rm -rf node_modules package-lock.json npm install
-
Check import extensions:
// Wrong import { something } from './module'; // Correct (ES modules require extensions) import { something } from './module.js';
Cause: ES module resolution issues.
Solutions:
-
Ensure package.json has type module:
{ "type": "module" } -
Check tsconfig.json module settings:
{ "compilerOptions": { "module": "NodeNext", "moduleResolution": "NodeNext" } }
Cause: TypeScript version mismatch or outdated types.
Solutions:
-
Update TypeScript:
npm install typescript@latest
-
Skip lib check:
{ "compilerOptions": { "skipLibCheck": true } }
Cause: CLI not installed or not in PATH.
Solutions:
-
Install globally:
npm install -g @anthropic-ai/claude-code
-
Check npm global path:
npm config get prefix # Add this to your PATH if needed -
Use npx instead:
npx @anthropic-ai/claude-code
Cause: Insufficient permissions for global npm install.
Solutions:
-
macOS/Linux - Fix npm permissions:
mkdir ~/.npm-global npm config set prefix '~/.npm-global' echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc source ~/.bashrc
-
Or use sudo (not recommended):
sudo npm install -g @anthropic-ai/claude-code
Cause: MCP server configuration or runtime issue.
Solutions:
-
Test the memory server manually (Python FastMCP, managed by UV):
cd segment_4_hero/memory_server uv run python server.py # Should show the server starting on stdio
-
Check Claude Code MCP config:
claude mcp list
Project-scoped servers (
microsoft-learn,oreilly-july20-documentmcp,oreilly-july20-memorymcp,github) are declared in.mcp.jsonat the repo root, not in.claude/settings.json. The CLI prompts you to approve them once on first launch. -
Remove and re-add the memory server:
claude mcp remove memory claude mcp add memory -- bash segment_4_hero/memory_server/start.sh
Cause: Network connectivity issues.
Solutions:
-
Check internet connection
-
Test API endpoint:
curl https://api.anthropic.com/v1/messages -I
-
Check proxy settings:
# If behind a proxy export HTTPS_PROXY=http://proxy:port
Cause: Corporate proxy or outdated certificates.
Solutions:
-
Update Node.js to latest version
-
For corporate environments:
# Not recommended for production export NODE_TLS_REJECT_UNAUTHORIZED=0
Cause: Hook script permissions or path issues.
Solutions:
-
Make hooks executable:
chmod +x .git/hooks/* -
Check hook script:
cat .git/hooks/pre-commit
Cause: Running full review on every commit.
Solutions:
-
Only review changed files:
git diff --cached --name-only | head -10 -
Skip hooks when needed:
git commit --no-verify -m "Quick fix"
Cause: Processing too large a file or codebase.
Solutions:
-
Increase Node.js memory:
export NODE_OPTIONS="--max-old-space-size=4096"
-
Process files in chunks
-
Use streaming for large responses
Cause: Large context or model processing time.
Solutions:
-
Reduce context size:
- Only include relevant files
- Summarize instead of including full content
-
Use streaming:
const stream = client.messages.stream({...});
-
Choose appropriate model:
- Use Sonnet for most tasks
- Reserve Opus for complex reasoning
- Check the error message carefully - It often contains the solution
- Search the Anthropic Documentation
- Ask in the Anthropic Discord
- Check GitHub Issues on the SDK repositories
- During live training - Ask the instructor!
Run these to gather information for troubleshooting:
# System info
node --version
npm --version
npx tsc --version
# Check environment
echo $ANTHROPIC_API_KEY | head -c 10
# Verify dependencies
npm ls @anthropic-ai/sdk
npm ls @modelcontextprotocol/sdk
# Test API connection
npx tsx -e "
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
const msg = await client.messages.create({
model: 'claude-sonnet-5',
max_tokens: 10,
messages: [{role: 'user', content: 'Hi'}]
});
console.log('API works:', msg.content[0].text);
"