Overview
HAPI CLI stores local configuration insettings.json located in the HAPI home directory (default: ~/.hapi/settings.json).
File Location
The settings file path depends on theHAPI_HOME environment variable:
File Structure
Basic Example
Fields
machineId
Unique identifier for this machine, used by the hub to track sessions and permissions.Unique machine identifier (UUID format).Generated: Automatically on first connection to hubFormat:
machine-{random-hex}Example: machine-abc123def456ghi789jkl012mno345- First run: Not present, CLI generates temporary ID
- Hub connection: Hub confirms and assigns persistent ID
- Subsequent runs: Reuses saved machine ID
machineIdConfirmedByServer
Indicates whether the hub has confirmed this machine ID.Whether the hub has validated this machine ID.Values:
true: Machine ID confirmed by hubfalseor absent: Pending confirmation
- First connection:
machineIdConfirmedByServernot present - Hub responds: Sets to
trueand saves machine ID - Subsequent connections: Uses confirmed ID
cliApiToken
The authentication token for connecting to the HAPI hub.Saved authentication token.Source: Set by
hapi auth login commandPriority: Environment variable CLI_API_TOKEN takes precedenceCLI_API_TOKENenvironment variablecliApiTokenin settings.json- Interactive prompt (first run)
apiUrl
Custom hub URL stored in settings (optional).Hub server URL.Priority: Environment variable
HAPI_API_URL takes precedenceDefault (if not set): http://localhost:3006HAPI_API_URLenvironment variableapiUrlin settings.json- Default:
http://localhost:3006
serverUrl (Legacy)
Legacy field name forapiUrl. Read-only for backward compatibility.
Old field name for hub URL. Replaced by
apiUrl.Migration: Automatically migrated to apiUrl when readIf you have old settings with
serverUrl, it will be automatically migrated to apiUrl.runnerAutoStartWhenRunningHappy
Controls whether the runner should auto-start when launching sessions.Enable automatic runner startup.Default: Not set (runner starts automatically)Values:
trueor absent: Runner auto-startsfalse: Manual runner management required
File Operations
Reading Settings
View entire file:Editing Settings
Safe editing:-
Stop runner:
-
Edit file:
-
Validate JSON:
-
Restart runner:
Backing Up Settings
Create backup:Resetting Settings
Clear specific fields:File Locking
HAPI uses atomic file locking to prevent corruption from concurrent access.Lock File
When updating settings, HAPI creates a temporary lock:- Process attempts to acquire lock
- If locked, waits up to 5 seconds (50 attempts × 100ms)
- If stale lock detected (> 10 seconds old), removes it
- Acquires lock, updates settings, releases lock
Multiple Environments
Use separate settings files for different environments (dev/staging/prod).Method 1: Separate HAPI_HOME
settings.jsonrunner.state.jsonlogs/
Method 2: Shell Aliases
Add to~/.bashrc or ~/.zshrc:
Troubleshooting
Settings File Not Found
Symptom:Corrupted Settings File
Symptom:Machine ID Conflict
Symptom:Lock File Issues
Symptom:Token Not Being Used
Symptom: Token is in settings.json but authentication fails. Check priority:Advanced Usage
Programmatic Access
Read settings in shell script:Migration Between Systems
Export settings from old system:When migrating, the
machineId will move with the settings. If you want a fresh machine ID on the new system, remove it from settings.json after import.Security
File Permissions
Check permissions:Best Practices
-
Don’t commit settings files:
-
Don’t share settings files:
Each machine should have its own
machineId - Use environment variables in CI/CD: Don’t store tokens in settings.json on build servers
-
Backup encrypted:
-
Rotate tokens periodically:
Related Documentation
Environment Variables
Configure via environment variables
Authentication
Manage tokens via CLI commands
Next Steps
- Environment Variables - Override settings with env vars
- Authentication Commands - Manage tokens via CLI
- Diagnostics - Troubleshoot configuration issues