| name | local-debugging |
| description | Debug local development issues by analyzing logs, checking processes, and diagnosing errors. Use when servers won't start, errors occur, or behavior is unexpected. |
Local Development Debugging
Knowledge for debugging local development environment issues.
Log File Locations
Worktree Log Files
For worktrees (non-main branches), logs are written to the worktree's logs/ directory:
<worktree>/logs/
├── backend.log # Backend server output (nodemon/ts-node)
├── frontend.log # Frontend server output (vite)
Reading logs:
tail -f logs/backend.log
tail -f logs/frontend.log
tail -100 logs/backend.log
grep -i "error\|fail\|exception" logs/backend.log
Main Branch (PM2)
Main branch uses PM2 for process management:
pm2 logs
pm2 logs app-backend
pm2 logs app-frontend
pm2 logs --lines 100
~/.pm2/logs/app-backend-out.log
~/.pm2/logs/app-backend-error.log
~/.pm2/logs/app-frontend-out.log
~/.pm2/logs/app-frontend-error.log
Common Error Patterns
Backend Won't Start
| Error | Cause | Fix |
|---|
EADDRINUSE | Port already in use | lsof -ti:PORT | xargs kill |
TS1005: ')' expected | TypeScript syntax error | Check for merge conflicts in index.ts |
P2021: Table does not exist | Missing migration | npx prisma migrate dev |
Cannot find module | Missing dependency | npm install in backend/ |
ECONNREFUSED to DB | Database not running | Check DATABASE_URL, start postgres |
Frontend Won't Start
| Error | Cause | Fix |
|---|
EADDRINUSE | Port already in use | lsof -ti:PORT | xargs kill |
spawn xdg-open ENOENT | Trying to open browser on headless server | Remove --open flag from vite command |
Module not found | Missing dependency | npm install in frontend/ |
VITE_* undefined | Missing env var | Check frontend/.env |
Database Errors
| Error Code | Meaning | Fix |
|---|
| P2002 | Unique constraint violation | Check for duplicate data |
| P2003 | Foreign key constraint failed | Referenced record doesn't exist |
| P2021 | Table does not exist | Run migrations |
| P2022 | Column does not exist | Schema/migration mismatch - run migration |
| P2025 | Record not found | Query for non-existent record |
Process Debugging
Check Running Processes
lsof -i:3001
lsof -i:3100
lsof -i:4001
lsof -i:4100
lsof -ti:PORT | xargs kill
ps aux | grep node | grep -v grep
pm2 status
Check Worktree Port Allocation
cat .worktree-info
cat ../.worktree-configs/ports.json
cat ../.worktree-configs/dev-env.json
Quick Diagnostics
Full Health Check
ps aux | grep -E "node|vite|nodemon" | grep -v grep
lsof -i:3001 -i:3100 -i:4001 -i:4100 2>/dev/null | head -10
ls -la logs/*.log 2>/dev/null || echo "No log files"
tail -20 logs/backend.log 2>/dev/null | grep -i error
tail -20 logs/frontend.log 2>/dev/null | grep -i error
Backend Startup Verification
cd backend && npm run type-check
cd backend && npx prisma db pull --print
Frontend Startup Verification
cd frontend && npx vite --version
grep VITE_ frontend/.env | head -5
Debugging Workflow
- Identify the symptom - What's not working?
- Check the logs - Read relevant log file for errors
- Check processes - Is the server even running? Port conflicts?
- Check recent changes - What was modified? Merge conflicts?
- Verify dependencies -
npm install, prisma generate
- Check configuration -
.env files, .worktree-info
TMux Pane Layout
For worktrees, the tmux session has 3 panes:
+---------------------------+
| Claude (pane 1) |
+-------------+-------------+
| Frontend(2) | Backend (3) |
+-------------+-------------+
Panes 2 and 3 tail the log files. Refresh with:
dev-refresh <worktree-name>
Anti-Patterns
Never Do:
- Kill processes without knowing what they are
- Delete log files while debugging
- Restart everything without understanding the error
- Ignore TypeScript errors and hope they go away
Always Do:
- Read the actual error message first
- Check if the error relates to recent changes
- Verify builds pass before assuming other issues
- Check for merge conflicts after pulls/merges
Production Debugging
If the issue isn't local, use these skills for production:
| Skill | Use For |
|---|
betterstack-logs | Query production logs via BetterStack MCP |
render-infrastructure | SSH into production/staging instances |
/debug-production | Combined production debugging workflow |
Quick Production Log Check
1. Create BetterStack connection:
mcp__betterstack__telemetry_create_cloud_connection_tool
team_id: <your-team-id>, source_id: <your-source-id>
2. Query recent errors:
SELECT dt, JSONExtract(raw, 'message', 'Nullable(String)') AS message
FROM remote(<your-table>_logs)
WHERE JSONExtract(raw, 'level', 'Nullable(String)') = 'error'
ORDER BY dt DESC LIMIT 20
Quick SSH Check
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=30 \
<your-production-service-id>@ssh.frankfurt.render.com "whoami && pwd"
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=30 \
<your-staging-service-id>@ssh.frankfurt.render.com "whoami && pwd"