CLI Reference
CLI Reference
Section titled “CLI Reference”Complete reference for all LeanJ CLI commands.
Overview
Section titled “Overview”The CLI (leanj) is the heart of the system. All operations go through the CLI.
Commands
Section titled “Commands”Controller Management
Section titled “Controller Management”Start Controller
Section titled “Start Controller”Start the controller daemon:
leanj controller startOptions:
--port <port>- HTTP API port (default: 9877)- TCP port is HTTP port - 1 (default: 9876)
Environment Variables:
LEANJ_CONTROLLER_PORT- HTTP port (default: 9877)
Example:
leanj controller start --port 8888Stop Controller
Section titled “Stop Controller”Stop the running controller:
# Auto-detect PIDleanj controller stop
# Manual PIDleanj controller stop <pid>JVM Discovery
Section titled “JVM Discovery”List JVMs
Section titled “List JVMs”List all discovered JVMs:
leanj jvmsOptions:
--json- Output in JSON format
Output:
Found 2 JVM(s):
1. com.example.SampleLoop ID: abc123 PID: 12345 Environment: local
2. order-service ID: def456 Environment: docker App: order-serviceJSON Output:
leanj jvms --json[ { "jvmId": "abc123", "pid": "12345", "appName": "com.example.SampleLoop", "environment": "local" }, { "jvmId": "def456", "appName": "order-service", "environment": "docker" }]Attach/Detach
Section titled “Attach/Detach”Attach Agent
Section titled “Attach Agent”Attach the profiler agent to a JVM:
# Using PIDleanj attach --pid <pid>
# Using JVM IDleanj attach --jvm-id <id>Example:
leanj attach --pid 12345leanj attach --jvm-id abc123Detach Agent
Section titled “Detach Agent”Detach the profiler agent from a JVM:
leanj detach --jvm-id <id>Example:
leanj detach --jvm-id abc123Status & Health
Section titled “Status & Health”Status
Section titled “Status”Check controller and agent status:
leanj statusOutput:
Controller: Running (PID: 12345)HTTP Port: 9877TCP Port: 9876
Attached JVMs: 2- abc123 (PID: 67890)- def456 (Docker: order-service)Doctor
Section titled “Doctor”Run system health check:
leanj doctorChecks:
- Java installation
- Go installation
- Controller JAR exists
- Agent JAR exists
- Tools.jar availability
- Controller running status
- Port availability
Output:
✓ Java: Found (11.0.19)✓ Go: Found (1.21.0)✓ Controller JAR: Found✓ Agent JAR: Found✓ Tools.jar: Found✓ Controller: Running✓ Ports: Available (9876, 9877)License Management
Section titled “License Management”Purchase License
Section titled “Purchase License”Open license purchase page:
leanj license purchaseOpens Lemon Squeezy checkout in your browser.
Activate Pro license with key:
leanj license login <key>Example:
leanj license login abc123-def456-ghi789Status
Section titled “Status”Check license status:
# Human-readableleanj license status
# JSON formatleanj license status --jsonOutput:
License: ProStatus: ActiveExpires: 2025-12-31Features: All Pro features enabledValidate
Section titled “Validate”Validate license with backend:
leanj license validateNote: License validation is cached for 24 hours to reduce API calls.
Get detailed license information:
leanj license infoShows:
- License tier (Free/Pro)
- Status
- Expiration date
- Features enabled
- Machine ID
Logout
Section titled “Logout”Log out and return to Free tier:
leanj license logoutEnvironment Variables
Section titled “Environment Variables”Controller Configuration
Section titled “Controller Configuration”LEANJ_CONTROLLER_PORT- HTTP API port (default: 9877)
CLI Configuration
Section titled “CLI Configuration”LEANJ_CLI_PATH- CLI binary path (for IDE)
License Configuration
Section titled “License Configuration”LEANJ_LICENSE_API_URL- License API URL (default: Cloudflare Worker)LEANJ_MACHINE_ID- Machine ID (auto-generated if not set)LEMON_SQUEEZY_CHECKOUT_URL- Checkout URL for purchasesLEANJ_DEV_MODE- Development mode (test licenses)
Exit Codes
Section titled “Exit Codes”0- Success1- General error2- Controller not running3- JVM not found4- Attach failed5- License error
Examples
Section titled “Examples”Complete Workflow
Section titled “Complete Workflow”# 1. Start controllerleanj controller start
# 2. Discover JVMsleanj jvms
# 3. Attach to JVMleanj attach --pid 12345
# 4. Check statusleanj status
# 5. Detach when doneleanj detach --jvm-id abc123
# 6. Stop controllerleanj controller stopDocker Workflow
Section titled “Docker Workflow”# 1. Start controllerleanj controller start
# 2. List Docker JVMs (auto-registered)leanj jvms
# 3. Attach to Docker JVMleanj attach --jvm-id def456
# 4. View metrics in IntelliJLicense Workflow
Section titled “License Workflow”# 1. Purchase licenseleanj license purchase
# 2. Login with keyleanj license login <key>
# 3. Verify statusleanj license status
# 4. Validate (if needed)leanj license validateTroubleshooting
Section titled “Troubleshooting”Command Not Found
Section titled “Command Not Found”Error: leanj: command not found
Solution:
- Verify CLI is built:
ls dist/cli/leanj* - Add to PATH (see Installation Guide)
- Or use full path:
/path/to/leanj <command>
Controller Not Running
Section titled “Controller Not Running”Error: Controller not running
Solution:
leanj controller startJVM Not Found
Section titled “JVM Not Found”Error: JVM not found
Solution:
- List JVMs:
leanj jvms - Verify PID is correct:
jps -l - Check JVM is running
Attach Failed
Section titled “Attach Failed”Error: Attach failed
Solution:
- Run
leanj doctorto check system - Verify tools.jar is available
- Check JVM supports attach API
- Ensure correct PID
Next Steps
Section titled “Next Steps”- Learn about Configuration
- Read How It Works
- See Troubleshooting Guide