# Worker overview

1. **Terminal UI, Web UI, CLI**
2. **Worker** port 18100: API, WebSocket, Web UI

## Control

Running `openprogram` starts a background worker if none is up. `OPENPROGRAM_NO_AUTO_WORKER=1` makes the terminal UI only connect to an existing one.

| Command | Effect |
| --- | --- |
| `openprogram worker start` | Start in the background and return |
| `openprogram worker run` | Foreground, for debugging; Ctrl-C stops |
| `openprogram worker status`, `openprogram status` | Running or not, PID, port, uptime; the top-level form also shows the log path and whether a service is installed |
| `openprogram worker stop`, `openprogram stop` | Stop. An installed service stays stopped until the next start or login |
| `openprogram worker restart`, `openprogram restart` | Stop and start fresh, after code or config changes |
| `openprogram web` | Start in this terminal and open `http://localhost:18100` |

```
$ openprogram status
openprogram: running (PID 82472, port 18100, up 48m)
  logs: ~/.openprogram/worker.log
```

## Port

| Precedence | Set with |
| --- | --- |
| 1 | `openprogram web --web-port <p>` |
| 2 | `OPENPROGRAM_WEB_PORT` |
| 3 | `openprogram ports --port 8101`, persisted |
| 4 | Chosen at this account's first start: 18100, or the next free port when something else holds it |

## Logs

| Command | Effect |
| --- | --- |
| `openprogram logs list` | Every log, size, last updated |
| `openprogram logs tail [name]` (`-n LINES`, default 50) (`-f` follow) | Last lines |
| `openprogram logs path [name]` | Absolute path |

| Name | File |
| --- | --- |
| `worker` (default) | `~/.openprogram/worker.log` |
| `runtime` | `~/.openprogram/logs/runtime.log` |
| `ink-startup` | `~/.openprogram/logs/ink-startup.log`, terminal UI startup |

Prefixes match: `logs tail ink`. Past 16 MB the worker log rotates at startup to `worker.log.1`, up to `.3`.

## Login service

`openprogram worker install` starts the worker at login and restarts it after a crash; `uninstall` removes it.

| Platform | Service | Note |
| --- | --- | --- |
| macOS | launchd, `~/Library/LaunchAgents/ai.openprogram.worker.plist` | `stop` unloads the job, so a crash restart does not bring it back |
| Linux | systemd `--user` | Each named [profile](https://fzkuji.github.io/OpenProgram/docs/install/profiles.html) gets its own unit |
| Windows source checkout | Least-privilege per-user Task Scheduler entry | `OpenProgram Worker`; each named profile gets its own task. `stop` also ends the task run, so its retry does not bring the worker back |

`start`, `stop` and `restart` go through the service rather than creating a detached replacement. `start` and `restart` regenerate its plist, unit or task launcher from the active CLI runtime, so an upgrade does not keep launching the old one.

[Configuration](https://fzkuji.github.io/OpenProgram/docs/server/configuration.html) · [Backup](https://fzkuji.github.io/OpenProgram/docs/server/backup.html) · [Troubleshooting](https://fzkuji.github.io/OpenProgram/docs/server/troubleshooting.html)
