Troubleshooting Guide
This guide covers common issues and their solutions.
Quick Diagnostic Commands
# Check all services are running
launchctl list | grep habit-tracker
# Check daemon status
npm run daemon:status
# View daemon logs (most useful)
tail -f ~/.habit-tracker/logs/daemon.log
# Check what's currently blocked
cat /etc/hosts | grep -A20 "HABIT-TRACKER-START"
# Emergency unblock all websites
npm run daemon:restoreWebsite Blocking Issues
Websites Not Being Blocked
Verify daemon is running:
bashlaunchctl list | grep habit-tracker.daemon pgrep -f "packages/daemon/dist/index.js"Check hosts file has entries:
bashcat /etc/hosts | grep HABIT-TRACKERFlush DNS cache:
bashsudo dscacheutil -flushcache && sudo killall -HUP mDNSResponderCheck Chrome Secure DNS setting:
- Go to
chrome://settings/security - "Use secure DNS" must be set to "With your current service provider" (OS default)
- If set to Cloudflare/Google, the hosts file is bypassed
- Go to
Try a different browser:
- Some browsers cache DNS aggressively
- Close and reopen browser tabs after blocking changes
Websites Still Blocked After Completing Habits
Check blocking should have stopped:
bashnpm run daemon:statusShould show empty
blockedDomainsarray.Force daemon refresh:
bashcurl -X POST http://localhost:3000/api/daemon/syncCheck hosts file was cleaned:
bashcat /etc/hosts | grep HABIT-TRACKERShould show nothing between the markers.
Flush DNS cache:
bashsudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder
Emergency: Need Immediate Access
If you need to unblock immediately without completing habits:
# Option 1: Use the app's emergency reset
npm run daemon:restore
# Option 2: Manual removal
sudo sed -i '' '/# HABIT-TRACKER-START/,/# HABIT-TRACKER-END/d' /etc/hosts
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponderDaemon Issues
Daemon Not Starting
Check logs for errors:
bashcat ~/.habit-tracker/logs/daemon.error.log tail -20 ~/.habit-tracker/logs/daemon.logVerify plist is loaded:
bashlaunchctl list | grep habit-tracker.daemonManually restart:
bashlaunchctl unload ~/Library/LaunchAgents/com.habit-tracker.daemon.plist launchctl load ~/Library/LaunchAgents/com.habit-tracker.daemon.plistCheck for port/socket conflicts:
bashls -la ~/.habit-tracker/daemon.sockIf socket exists but daemon isn't running, remove it:
bashrm ~/.habit-tracker/daemon.sock
Permission Errors
The daemon needs sudo access to modify /etc/hosts. Check sudoers:
sudo cat /etc/sudoers.d/habit-trackerShould contain rules allowing passwordless sudo for specific commands. If missing, re-run the installation script.
Daemon Not Responding to IPC
Test socket manually:
bashecho "ping" | nc -U ~/.habit-tracker/daemon.sockShould respond with
pong.Check backend is notifying daemon: Look for "Refresh triggered" messages in daemon.log after completing a habit.
Backend/Frontend Issues
Services Not Starting
Check error logs:
bashcat ~/.habit-tracker/logs/backend.error.log cat ~/.habit-tracker/logs/frontend.error.logCheck ports are available:
bashlsof -i :3000 # Production backend lsof -i :3001 # Development backend lsof -i :5173 # Production frontend lsof -i :5174 # Development frontendKill conflicting processes:
bashkill -9 <PID>
Database Issues
Database locked error:
- Close any other running instances
- Check for multiple backend processes:bash
pgrep -f "packages/backend"
Database corruption:
bash# Backup first! cp ~/.habit-tracker/data/habit-tracker.db ~/.habit-tracker/data/habit-tracker.db.backup # Reset database rm ~/.habit-tracker/data/habit-tracker.db DB_PATH=~/.habit-tracker/data npm run db:migrate -w @habit-tracker/backend
API Errors
Check backend health:
bashcurl http://localhost:3000/healthShould return
{"status":"ok",...}Check CORS issues:
- Open browser DevTools → Network tab
- Look for CORS-related errors
Development vs Production Confusion
| Aspect | Development | Production |
|---|---|---|
| Backend | :3001 | :3000 |
| Frontend | :5174 | :5173 |
| Database | ./packages/backend/data/dev/ | ~/.habit-tracker/data/ |
| Command | npm run dev | npm run start:prod |
Check which environment you're in:
# Check running ports
lsof -i :3000 -i :3001 -i :5173 -i :5174 | grep LISTENBuild Issues
Type Errors
Build shared package first (other packages depend on it):
npm run build -w @habit-tracker/sharedTests Failing
Ensure shared package is built:
bashnpm run build -w @habit-tracker/sharedRun tests in isolation:
bashnpm test -w @habit-tracker/backend
Full System Reset
If all else fails, perform a clean reinstall:
# 1. Stop all services
launchctl unload ~/Library/LaunchAgents/com.habit-tracker.*.plist
# 2. Remove plist files
rm ~/Library/LaunchAgents/com.habit-tracker.*.plist
# 3. Clean hosts file
sudo sed -i '' '/# HABIT-TRACKER-START/,/# HABIT-TRACKER-END/d' /etc/hosts
# 4. Remove sudoers entry
sudo rm /etc/sudoers.d/habit-tracker
# 5. Flush DNS
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder
# 6. Optional: Remove all data (DESTRUCTIVE)
rm -rf ~/.habit-tracker
# 7. Rebuild
npm run build
# 8. Reinstall
bash scripts/install-production.shGetting Help
If you're still stuck:
- Check daemon logs:
tail -100 ~/.habit-tracker/logs/daemon.log - Check backend logs:
tail -100 ~/.habit-tracker/logs/backend.log - File an issue with logs at https://github.com/PaulBunker/habit-tracker/issues