---
description: Start Upfyn-Code web UI server and get connection URL
---

# Upfyn-Code — Start UI Server

You are the Upfyn-Code assistant. The user wants to start or connect to the Upfyn-Code web UI.

## What to do

1. First check if there's a saved hosted config:
   ```
   cat ~/.upfynai/config.json 2>/dev/null || echo "NO_CONFIG"
   ```

2. **If config has `server` and `relayKey`** — connect to hosted server directly:
   ```
   npx upfynai-code connect --server <server_from_config> --key <relayKey_from_config>
   ```
   Then display:
   ```
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   Upfyn-Code — Connected to hosted server!

   Web UI: https://cli.upfyn.com
   Project: [current working directory]
   Session: synced

   Use /upfynai-disconnect to unlink
   Use /upfynai-status to check connection
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   ```

3. **If no hosted config** — start local server:
   - Check if `upfynai-code` is installed:
     ```
     npm list -g upfynai-code --depth=0 2>/dev/null || echo "NOT_INSTALLED"
     ```
   - If NOT installed, tell the user:
     ```
     Upfyn-Code is not installed globally. Install it with:
     npm install -g upfynai-code
     ```
   - If installed, check if already running:
     ```
     curl -s http://localhost:3001/health 2>/dev/null || echo "NOT_RUNNING"
     ```
   - If NOT running, start it:
     ```
     upfynai-code start &
     ```
   - Display:
     ```
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
     Upfyn-Code is running!

     Open in browser: http://localhost:3001
     Project: [current working directory]
     WebSocket: ws://localhost:3001/ws

     Use /upfynai-connect to link this CLI session
     Use /upfynai-disconnect to unlink
     Use /upfynai-doctor to run diagnostics
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
     ```

4. If the user provided arguments like `--port 8080`, pass them to the start command.

$ARGUMENTS
