Skip to main content
HAPI is configured through environment variables and a settings file. This page documents all available configuration options for both the CLI and Hub.

Configuration Priority

Configuration is loaded with the following priority (highest to lowest):
  1. Environment variables - Set in your shell or .env file
  2. Settings file - ~/.hapi/settings.json (or $HAPI_HOME/settings.json)
  3. Default values - Built-in defaults
Environment variables always override values in the settings file. When environment variables are used, they’re automatically saved to the settings file for future use.

CLI Configuration

Configuration options for the HAPI CLI client.

Required Variables

CLI_API_TOKEN

Shared secret for authenticating with the HAPI hub.
export CLI_API_TOKEN="your-secret-token"
Format:
  • Simple: your-secret-token
  • With namespace: your-secret-token:namespace
Configuration methods:
export CLI_API_TOKEN="your-secret-token"
The CLI token must match the hub’s CLI_API_TOKEN (base portion for namespaced tokens). Mismatch will result in authentication failures.

HAPI_API_URL

Base URL of the HAPI hub.
# Default
HAPI_API_URL="http://localhost:3006"

# Remote hub
HAPI_API_URL="https://hapi.example.com"

Directory Configuration

HAPI_HOME

Configuration and data directory for HAPI.
# Default
HAPI_HOME="~/.hapi"

# Custom location
HAPI_HOME="/opt/hapi-data"
Directory contents:
  • settings.json - User settings (machineId, token, onboarding)
  • runner.state.json - Runner state (PID, port, version, heartbeat)
  • runner.state.json.lock - Runner lock file
  • logs/ - CLI and runner log files
  • access.key - Private key (if used)

Optional Variables

HAPI_EXPERIMENTAL

Enable experimental features.
# Enable
export HAPI_EXPERIMENTAL="true"  # or "1" or "yes"

# Disable (default)
unset HAPI_EXPERIMENTAL
Accepted values: true, 1, yes (case-insensitive)

HAPI_CLAUDE_PATH

Path to a specific Claude CLI executable.
# Use custom Claude installation
export HAPI_CLAUDE_PATH="/opt/claude/bin/claude"

# Use specific version
export HAPI_CLAUDE_PATH="/usr/local/bin/claude-v2"
If not set, HAPI searches for claude on your PATH. This is useful when you have multiple Claude installations or when Claude is not in your PATH.

HAPI_HTTP_MCP_URL

Default HTTP MCP (Model Context Protocol) target URL for hapi mcp command.
# Set default MCP server
export HAPI_HTTP_MCP_URL="http://localhost:8080"

# Use with hapi mcp (uses default URL)
hapi mcp

# Override with command line
hapi mcp --url http://localhost:9000

Runner Configuration

HAPI_RUNNER_HEARTBEAT_INTERVAL

Interval for runner health checks in milliseconds.
# Default: 60000 (60 seconds)
export HAPI_RUNNER_HEARTBEAT_INTERVAL=60000

# More frequent (30 seconds)
export HAPI_RUNNER_HEARTBEAT_INTERVAL=30000

# Less frequent (2 minutes)
export HAPI_RUNNER_HEARTBEAT_INTERVAL=120000
Heartbeat operations:
  • Prune dead sessions
  • Check for CLI version updates
  • Verify PID ownership
  • Update heartbeat timestamp
Setting this too low (< 10 seconds) may cause performance issues. Setting it too high (> 5 minutes) delays version detection and session cleanup.

HAPI_RUNNER_HTTP_TIMEOUT

HTTP timeout for runner control requests in milliseconds.
# Default: 10000 (10 seconds)
export HAPI_RUNNER_HTTP_TIMEOUT=10000

# Increase for slow connections
export HAPI_RUNNER_HTTP_TIMEOUT=30000
Used by:
  • hapi runner stop
  • hapi runner list
  • hapi runner stop-session
  • Internal control operations

Worktree Environment Variables

These variables are automatically set by the runner when spawning worktree sessions. Do not set them manually.

HAPI_WORKTREE_BASE_PATH

Base repository path for worktree sessions.
# Set automatically by runner
HAPI_WORKTREE_BASE_PATH="/Users/you/projects/my-repo"

HAPI_WORKTREE_BRANCH

Branch name for the worktree.
# Set automatically by runner
HAPI_WORKTREE_BRANCH="hapi-feature-auth"

HAPI_WORKTREE_NAME

Worktree name (also the directory name).
# Set automatically by runner
HAPI_WORKTREE_NAME="feature-auth"

HAPI_WORKTREE_PATH

Full path to the worktree directory.
# Set automatically by runner
HAPI_WORKTREE_PATH="/Users/you/projects/my-repo-worktrees/feature-auth"

HAPI_WORKTREE_CREATED_AT

Worktree creation timestamp in milliseconds.
# Set automatically by runner
HAPI_WORKTREE_CREATED_AT="1703001234567"
For more details on worktrees, see the Worktrees documentation.

Hub Configuration

Configuration options for the HAPI hub server.

Required Variables

CLI_API_TOKEN

Base shared secret for CLI authentication. Clients append :<namespace> for isolation.
# Auto-generated on first run if not set
CLI_API_TOKEN="auto-generated-token-123"

# Manually set
CLI_API_TOKEN="my-secure-token"
Namespace format:
  • Hub: CLI_API_TOKEN="base-token"
  • Client: CLI_API_TOKEN="base-token:alice"
The hub-side CLI_API_TOKEN must NOT include a :<namespace> suffix. If it does, the hub strips the suffix and logs a warning.

Telegram Configuration

TELEGRAM_BOT_TOKEN

Telegram Bot API token from @BotFather.
# Get from https://t.me/BotFather
export TELEGRAM_BOT_TOKEN="123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
To enable Telegram:
  1. Create a bot with @BotFather
  2. Set TELEGRAM_BOT_TOKEN
  3. Set HAPI_PUBLIC_URL (required for Mini App)
  4. Start the hub
  5. Open /app in your bot chat

TELEGRAM_NOTIFICATION

Enable or disable Telegram notifications.
# Default: true (if TELEGRAM_BOT_TOKEN is set)
TELEGRAM_NOTIFICATION="true"

# Disable notifications
TELEGRAM_NOTIFICATION="false"
Notification types:
  • Permission requests
  • Session ready notifications
  • Error notifications

Network Configuration

HAPI_LISTEN_HOST

Host/IP address to bind the HTTP service.
# Default: localhost only
HAPI_LISTEN_HOST="127.0.0.1"

# Listen on all interfaces
HAPI_LISTEN_HOST="0.0.0.0"

# Specific interface
HAPI_LISTEN_HOST="192.168.1.100"
Binding to 0.0.0.0 exposes the hub to all network interfaces. Ensure proper firewall rules and use HTTPS in production.

HAPI_LISTEN_PORT

Port for the HTTP service.
# Default
HAPI_LISTEN_PORT="3006"

# Custom port
HAPI_LISTEN_PORT="8080"

HAPI_PUBLIC_URL

Public HTTPS URL for external access (required for Telegram Mini App).
# Production
export HAPI_PUBLIC_URL="https://hapi.example.com"

# Cloudflare Tunnel
export HAPI_PUBLIC_URL="https://hapi.your-tunnel.trycloudflare.com"

# Tailscale
export HAPI_PUBLIC_URL="https://hapi.your-tailnet.ts.net"
Used for:
  • Telegram Mini App URL
  • Default CORS origins
  • OAuth callbacks (if implemented)

CORS_ORIGINS

Comma-separated list of allowed CORS origins.
# Allow all (not recommended for production)
CORS_ORIGINS="*"

# Specific origins
CORS_ORIGINS="https://app.example.com,https://admin.example.com"

# Derive from HAPI_PUBLIC_URL (automatic if not set)
# No manual configuration needed

Data Storage

HAPI_HOME

Data directory for hub configuration and state.
# Default
HAPI_HOME="~/.hapi"

# Custom location
HAPI_HOME="/var/lib/hapi"

DB_PATH

SQLite database path.
# Default: $HAPI_HOME/hapi.db
DB_PATH="~/.hapi/hapi.db"

# Custom location
DB_PATH="/data/hapi/database.db"
Database contents:
  • Sessions and session metadata
  • Messages (paginated)
  • Machines and runner state
  • Users (Telegram bindings with namespaces)
  • Todo items extracted from messages

Relay Configuration

HAPI_RELAY_API

Relay API domain for tunwg (WebRTC tunneling).
# Default
HAPI_RELAY_API="relay.hapi.run"

# Custom relay
HAPI_RELAY_API="relay.your-domain.com"

HAPI_RELAY_AUTH

Relay authentication key.
# Default
HAPI_RELAY_AUTH="hapi"

# Custom key
HAPI_RELAY_AUTH="your-secret-key"

HAPI_RELAY_FORCE_TCP

Force TCP relay mode when UDP is unavailable.
# Enable
HAPI_RELAY_FORCE_TCP="true"  # or "1"

# Disable (default)
unset HAPI_RELAY_FORCE_TCP

Push Notifications

VAPID_SUBJECT

Contact email or URL for Web Push (VAPID protocol).
# Default
VAPID_SUBJECT="mailto:[email protected]"

# Custom
VAPID_SUBJECT="mailto:[email protected]"
VAPID_SUBJECT="https://your-website.com"
Used for:
  • Web Push notification authentication
  • Contact information in push service subscriptions

Voice Configuration (ElevenLabs)

ELEVENLABS_API_KEY

ElevenLabs API key for voice assistant.
export ELEVENLABS_API_KEY="your-api-key"

ELEVENLABS_AGENT_ID

Custom ElevenLabs agent ID.
# Auto-created if not set
export ELEVENLABS_AGENT_ID="agent-id-123"

Settings File Format

CLI Settings File

Location: ~/.hapi/settings.json (or $HAPI_HOME/settings.json)
{
  "machineId": "machine-uuid-123",
  "cliApiToken": "your-secret-token:namespace",
  "onboardingCompleted": true,
  "lastUsed": 1703001234567
}

Hub Settings File

Location: ~/.hapi/settings.json (or $HAPI_HOME/settings.json)
{
  "telegramBotToken": "123456789:ABC...",
  "telegramNotification": true,
  "listenHost": "127.0.0.1",
  "listenPort": 3006,
  "publicUrl": "https://hapi.example.com",
  "corsOrigins": ["https://app.example.com"],
  "cliApiToken": "auto-generated-token-123"
}
The settings file is automatically created and updated when environment variables are read. You can also manually edit it, but environment variables will override manual changes.

Configuration Examples

Local Development

.env
# CLI
CLI_API_TOKEN="dev-token"
HAPI_API_URL="http://localhost:3006"
HAPI_EXPERIMENTAL="true"

# Hub
CLI_API_TOKEN="dev-token"
HAPI_LISTEN_HOST="127.0.0.1"
HAPI_LISTEN_PORT="3006"

Production Hub

.env
# Hub
CLI_API_TOKEN="${SECRET_TOKEN}"  # From secret manager
HAPI_LISTEN_HOST="0.0.0.0"
HAPI_LISTEN_PORT="3006"
HAPI_PUBLIC_URL="https://hapi.example.com"
CORS_ORIGINS="https://app.example.com"

# Telegram
TELEGRAM_BOT_TOKEN="${TELEGRAM_TOKEN}"
TELEGRAM_NOTIFICATION="true"

# Storage
HAPI_HOME="/var/lib/hapi"
DB_PATH="/var/lib/hapi/production.db"

# Push
VAPID_SUBJECT="mailto:[email protected]"

Remote CLI (Connecting to Production)

.env
# CLI connecting to production hub
CLI_API_TOKEN="your-production-token:alice"
HAPI_API_URL="https://hapi.example.com"
HAPI_HOME="~/.hapi-prod"

Multi-Namespace Setup

alice.env
# Alice's configuration
CLI_API_TOKEN="shared-token:alice"
HAPI_API_URL="https://shared-hub.example.com"
HAPI_HOME="~/.hapi-alice"
bob.env
# Bob's configuration
CLI_API_TOKEN="shared-token:bob"
HAPI_API_URL="https://shared-hub.example.com"
HAPI_HOME="~/.hapi-bob"

CI/CD Environment

.env.ci
# Automated testing
CLI_API_TOKEN="ci-token"
HAPI_API_URL="http://localhost:3006"
HAPI_HOME="/tmp/hapi-ci"
HAPI_EXPERIMENTAL="false"
HAPI_RUNNER_HEARTBEAT_INTERVAL="30000"

Environment Variable Reference Table

CLI Variables

VariableRequiredDefaultDescription
CLI_API_TOKENYes-Authentication token (with optional :namespace)
HAPI_API_URLNohttp://localhost:3006Hub base URL
HAPI_HOMENo~/.hapiConfiguration directory
HAPI_EXPERIMENTALNofalseEnable experimental features
HAPI_CLAUDE_PATHNo(auto-detect)Path to Claude CLI
HAPI_HTTP_MCP_URLNo-Default MCP server URL
HAPI_RUNNER_HEARTBEAT_INTERVALNo60000Runner heartbeat interval (ms)
HAPI_RUNNER_HTTP_TIMEOUTNo10000Runner HTTP timeout (ms)
HAPI_WORKTREE_BASE_PATHAuto-Worktree base repo path
HAPI_WORKTREE_BRANCHAuto-Worktree branch name
HAPI_WORKTREE_NAMEAuto-Worktree name
HAPI_WORKTREE_PATHAuto-Worktree directory path
HAPI_WORKTREE_CREATED_ATAuto-Worktree creation timestamp

Hub Variables

VariableRequiredDefaultDescription
CLI_API_TOKENNo(auto-generated)Base authentication token
TELEGRAM_BOT_TOKENNo-Telegram Bot API token
TELEGRAM_NOTIFICATIONNotrueEnable Telegram notifications
HAPI_LISTEN_HOSTNo127.0.0.1HTTP bind address
HAPI_LISTEN_PORTNo3006HTTP port
HAPI_PUBLIC_URLNo-Public HTTPS URL
CORS_ORIGINSNo(auto-derived)Allowed CORS origins
HAPI_HOMENo~/.hapiData directory
DB_PATHNo$HAPI_HOME/hapi.dbSQLite database path
HAPI_RELAY_APINorelay.hapi.runRelay API domain
HAPI_RELAY_AUTHNohapiRelay auth key
HAPI_RELAY_FORCE_TCPNofalseForce TCP relay mode
VAPID_SUBJECTNomailto:[email protected]VAPID subject for Web Push
ELEVENLABS_API_KEYNo-ElevenLabs API key
ELEVENLABS_AGENT_IDNo(auto-created)ElevenLabs agent ID

Troubleshooting

Configuration Not Loading

Check priority: Environment variables override settings file. Ensure you’re setting the variable in the correct shell session:
# Verify variable is set
echo $CLI_API_TOKEN

# Check effective configuration
hapi auth status
Permissions issue: Ensure ~/.hapi/ directory is writable:
ls -la ~/.hapi/
chmod u+w ~/.hapi/settings.json
Must be set before first run: HAPI_HOME must be set before any HAPI command:
export HAPI_HOME="/custom/path"
hapi auth login

Authentication Failures

Token mismatch: Verify CLI and Hub tokens match (base portion for namespaces):
# CLI
echo $CLI_API_TOKEN  # your-token:namespace

# Hub (should be base only)
echo $CLI_API_TOKEN  # your-token
Incorrect token format: Ensure namespace is appended with colon:
# Correct
CLI_API_TOKEN="base:alice"

# Incorrect
CLI_API_TOKEN="base-alice"

Connection Issues

Check URL and network:
# Verify URL is reachable
curl $HAPI_API_URL/api/health

# Check DNS resolution
nslookup hapi.example.com
Check CORS_ORIGINS:
# Add your frontend origin
export CORS_ORIGINS="https://your-app.com,https://admin.your-app.com"

Best Practices

Use .env Files

Store configuration in .env files and load with source .env or dotenv tools

Separate Environments

Use different HAPI_HOME directories for dev, staging, and production

Secure Tokens

Never commit tokens to version control. Use secret managers in production

Document Custom Configs

Document any non-default settings in your team’s runbook

Namespaces

Multi-user isolation for shared hubs

Runner

Background daemon configuration

Worktrees

Git worktree environment variables

Build docs developers (and LLMs) love