Overview
Thehapi doctor command provides comprehensive system diagnostics to help troubleshoot issues with the HAPI CLI, runner, and sessions.
Commands
hapi doctor
Run full system diagnostics.- CLI version and installation
- Runner status and health
- Active HAPI processes
- Configuration and settings
- Hub connectivity
- Log file locations
- Machine registration
hapi doctor clean
Kill all runaway HAPI processes.Doctor Output
Full Diagnostics
When you runhapi doctor, you’ll see output like this:
Problem Detection
When issues are detected,hapi doctor provides specific guidance:
Clean Output
When you runhapi doctor clean, processes are terminated:
With Errors
If some processes cannot be killed:What Gets Checked
CLI Version
- Current installed version
- Installation path
- Binary modification time
- Whether CLI executable is valid
Runner Status
- Whether runner is running
- Runner process ID (PID)
- Runner version
- Whether version matches CLI
- HTTP control port
- Uptime since start
- Last heartbeat timestamp
- Number of active sessions
Runner Health
- Process alive: Verifies runner PID exists
- Version matches: CLI and runner versions match
- State file valid:
runner.state.jsonis readable and valid JSON - Lock file present: Runner lock file exists
- Heartbeat recent: Last heartbeat within 120 seconds
Configuration
HAPI_HOMEdirectory pathHAPI_API_URLsettingCLI_API_TOKENstatus (set or missing)- Token source (environment vs settings file)
- Machine ID
- Experimental features status
Active Processes
- All HAPI-related processes (runner + sessions)
- Process IDs
- Memory usage (RSS)
- CPU usage
- Command line arguments
Log Files
- Runner log path and size
- Session log paths and sizes
- Whether log files are readable
- Recent log entries (last 10 lines)
Hub Connection
- Hub URL configuration
- Connection status (connected/refused/timeout)
- Last successful ping
- Socket.IO connection state
Common Issues
Issue: Runner Not Running
Diagnostic output:Issue: Version Mismatch
Diagnostic output:Issue: Stale Heartbeat
Diagnostic output:Issue: Token Not Set
Diagnostic output:Issue: Cannot Connect to Hub
Diagnostic output:Issue: Orphaned Sessions
Diagnostic output:Issue: Corrupted State File
Diagnostic output:Interpreting Process List
Process Types
Runner:- Background daemon managing sessions
- Typically low CPU usage
- Memory usage: 30-60 MB
- Active Claude Code session
- Memory usage: 80-200 MB
- CPU varies based on activity
- Active Codex session
- Memory usage: 60-150 MB
- CPU varies based on activity
- Active Cursor Agent session
- Memory usage: 50-120 MB
- CPU varies based on activity
Normal vs Abnormal
Normal:- Runner: < 100 MB RAM, < 1% CPU (idle)
- Sessions: < 300 MB RAM, < 5% CPU (idle)
- Sessions: < 800 MB RAM, < 50% CPU (active)
- Runner: > 200 MB RAM, > 5% CPU
- Sessions: > 1 GB RAM
- Sessions: > 90% CPU for extended periods
- Any process consuming swap memory
Log Inspection
Diagnostics shows log file locations. Inspect them for detailed troubleshooting:Runner Logs
Session Logs
Session logs are in~/.hapi/logs/session-*.log:
Debug Mode
For verbose diagnostics, enable debug mode:- Full stack traces for errors
- Detailed state file contents
- HTTP request/response logs
- Socket.IO connection details
When to Use doctor clean
Use hapi doctor clean in these scenarios:
1. Complete Reset Needed
When you want to stop everything and start fresh:2. Orphaned Processes
When sessions are running but not tracked by runner:3. Version Upgrades
After upgrading HAPI CLI:4. State Corruption
When state files are corrupted:5. Frozen Processes
When processes are not responding:Automated Health Checks
For monitoring HAPI in production, script the doctor command:Related Commands
Runner Commands
Manage the runner daemon
Authentication
Check token and connection status
Next Steps
- Runner Commands - Manage background service
- Environment Variables - Configure HAPI CLI
- Settings File - Understand local storage