Skip to content

CLI Reference

Complete reference for all LeanJ CLI commands.

The CLI (leanj) is the heart of the system. All operations go through the CLI.

Start the controller daemon:

Terminal window
leanj controller start

Options:

  • --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:

Terminal window
leanj controller start --port 8888

Stop the running controller:

Terminal window
# Auto-detect PID
leanj controller stop
# Manual PID
leanj controller stop <pid>

List all discovered JVMs:

Terminal window
leanj jvms

Options:

  • --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-service

JSON Output:

Terminal window
leanj jvms --json
[
{
"jvmId": "abc123",
"pid": "12345",
"appName": "com.example.SampleLoop",
"environment": "local"
},
{
"jvmId": "def456",
"appName": "order-service",
"environment": "docker"
}
]

Attach the profiler agent to a JVM:

Terminal window
# Using PID
leanj attach --pid <pid>
# Using JVM ID
leanj attach --jvm-id <id>

Example:

Terminal window
leanj attach --pid 12345
leanj attach --jvm-id abc123

Detach the profiler agent from a JVM:

Terminal window
leanj detach --jvm-id <id>

Example:

Terminal window
leanj detach --jvm-id abc123

Check controller and agent status:

Terminal window
leanj status

Output:

Controller: Running (PID: 12345)
HTTP Port: 9877
TCP Port: 9876
Attached JVMs: 2
- abc123 (PID: 67890)
- def456 (Docker: order-service)

Run system health check:

Terminal window
leanj doctor

Checks:

  • 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)

Open license purchase page:

Terminal window
leanj license purchase

Opens Lemon Squeezy checkout in your browser.

Activate Pro license with key:

Terminal window
leanj license login <key>

Example:

Terminal window
leanj license login abc123-def456-ghi789

Check license status:

Terminal window
# Human-readable
leanj license status
# JSON format
leanj license status --json

Output:

License: Pro
Status: Active
Expires: 2025-12-31
Features: All Pro features enabled

Validate license with backend:

Terminal window
leanj license validate

Note: License validation is cached for 24 hours to reduce API calls.

Get detailed license information:

Terminal window
leanj license info

Shows:

  • License tier (Free/Pro)
  • Status
  • Expiration date
  • Features enabled
  • Machine ID

Log out and return to Free tier:

Terminal window
leanj license logout
  • LEANJ_CONTROLLER_PORT - HTTP API port (default: 9877)
  • LEANJ_CLI_PATH - CLI binary path (for IDE)
  • 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 purchases
  • LEANJ_DEV_MODE - Development mode (test licenses)
  • 0 - Success
  • 1 - General error
  • 2 - Controller not running
  • 3 - JVM not found
  • 4 - Attach failed
  • 5 - License error
Terminal window
# 1. Start controller
leanj controller start
# 2. Discover JVMs
leanj jvms
# 3. Attach to JVM
leanj attach --pid 12345
# 4. Check status
leanj status
# 5. Detach when done
leanj detach --jvm-id abc123
# 6. Stop controller
leanj controller stop
Terminal window
# 1. Start controller
leanj controller start
# 2. List Docker JVMs (auto-registered)
leanj jvms
# 3. Attach to Docker JVM
leanj attach --jvm-id def456
# 4. View metrics in IntelliJ
Terminal window
# 1. Purchase license
leanj license purchase
# 2. Login with key
leanj license login <key>
# 3. Verify status
leanj license status
# 4. Validate (if needed)
leanj license validate

Error: leanj: command not found

Solution:

  1. Verify CLI is built: ls dist/cli/leanj*
  2. Add to PATH (see Installation Guide)
  3. Or use full path: /path/to/leanj <command>

Error: Controller not running

Solution:

Terminal window
leanj controller start

Error: JVM not found

Solution:

  1. List JVMs: leanj jvms
  2. Verify PID is correct: jps -l
  3. Check JVM is running

Error: Attach failed

Solution:

  1. Run leanj doctor to check system
  2. Verify tools.jar is available
  3. Check JVM supports attach API
  4. Ensure correct PID