Files
ai-agent/worker/README.md
gabrielvidalandClaude Opus 5.5 4d79a4a44f feat(sidecar): hold a logind sleep lock on a Linux worker while a run is live
The EVOX2 auto-suspends on input idle and a busy GPU doesn't count, so a
long run there died with the box. sidecar/inhibit.py holds a
`systemd-inhibit --what=sleep --mode=block` lock while pids.list_live() is
non-empty: poked on /spawn, /resume and /fork, re-checked by a small loop
(5 s held, 15 s idle) so it drops right after the last run ends, released
at lifespan teardown. The lock child is `cat` on a pipe we hold, so it also
dies if the sidecar is killed (KillMode=process would otherwise leak it).

On by default on a Linux worker (SIDECAR_INHIBIT_SLEEP=0|1), a no-op on
macOS, without the binary, or when logind/polkit refuses (reported, retried
every minute). /health reports sleepInhibitor {enabled, available, engaged}.
worker/README documents the polkit rule a service-started worker needs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 22:06:45 +01:00

485 lines
28 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ai-agent worker (macOS + Linux)
Run a machine as a **worker** for the ai-agent hub: the hub spawns, resumes,
forks and interrupts `claude -p` sessions *on this machine*, and shows its
terminal sessions live. A session here is exactly a terminal session — this
machine's Claude login and whatever its shell has (mise, gcloud, `op`, `gh`,
OrbStack…). Any Mac works — a personal laptop paired on `personal`, a work
seat on `work` — and so does a Linux box (a systemd user unit instead of a
launchd agent).
The worker is the same `sidecar/sidecar.py` the homelab runs on its own host,
as a user service. **The hub always calls in; the worker never contacts the
hub** — it binds the machine's Tailscale address only and holds one bearer
token minted at pairing. The only thing it fetches on its own is this repo,
from Gitea, when the hub says which commit to update to.
## A guest's computer (the worker link)
A guest of the hub can pair a computer of their own — no Tailscale, no
Claude login. In their portal, **Settings → My computers → Add a computer**
gives one line (the owner switches it on per guest first):
```bash
curl -fsSL https://git.gabvdl.xyz/gabrielvidal/ai-agent/raw/branch/main/worker/install.sh \
| WORKER_HUB=https://ai-agent.gabvdl.xyz WORKER_ENROLL=<one-time code> bash
```
Run it from the folder runs should start in. That worker listens on
`127.0.0.1` only and **dials out**: `sidecar/link.py` long-polls the hub's
guest host over HTTPS, makes each request it gets against the local sidecar
and posts the answer back — the hub pairs with it through that link
(`backend/workers/link.py`). Its Claude Code bills the hub owner's account
through the hub's proxy, within the guest's limits; nothing is written into
the machine's own `~/.claude/settings.json`, and only the conversations the
hub started there are mirrored back — plus the terminal sessions the guest
shares (below). A run there edits only inside its start folder and `/tmp`.
`ai-agent-worker status` shows the link (`/health` → `link`); removing the
computer from the portal makes the hub drop it (`link.json` and the bearer
go). Tokens rotate weekly on their own (`POST /link/token`).
### `claude` in a terminal there: which Claude?
On a guest's computer the installer wraps the shell's `claude` (one marked
line in `~/.bashrc` / `~/.zshrc` / `~/.bash_profile` sourcing
`~/.config/ai-agent-worker/claude-shell.sh`, fish: `conf.d/ai-agent-claude.fish`
→ `~/.local/bin/ai-agent-claude` → `worker/claude_launcher.py`). Typed in a
terminal it asks, in an arrow-key box:
```
╭─ Which Claude? · fedora ─────────────────────────────────────────────╮
│ ❯ ai-agent Claude Gabriel's Claude · synced to the app · $8.20 left │
│ My own Claude your login · stays on this computer │
│ │
│ [ ] Remember for ~/code/app and its subfolders │
╰─ ↑↓ choose · space remember · enter start · esc quit ────────────────╯
```
- **ai-agent Claude** — the hub's proxy pair (`claude-proxy.json`), the owner's
plan within the guest's limits; the hub mirrors the session because it sees
its id on the proxy (`X-Claude-Code-Session-Id`, `backend/workers/terminal.py`).
A new session gets `--session-id` up front, so the line printed before
Claude starts already links it in the app.
- **My own Claude** — the machine's login, untouched, not mirrored — until
the guest syncs it: `/ai-agent sync` inside the session (the mod, below),
`ai-agent-worker sync [<id>|--last]` (a list without), or *Sync* under the
computer in the portal. `ai-agent-worker unsync <id>` / *Stop syncing*
stops taking more of it; the app keeps what it has.
- It starts on the last pick in this folder, else the last anywhere, else
ai-agent Claude; *Remember* skips the question in the folder and its
subfolders. No question for `-p` / a pipe / `--resume <id>` of a known
session (remembered → that session's → local), for subcommands and
`--help`/`--version`, nor with `--ai-agent` / `--local` (`--choose` asks
anyway). `ai-agent-worker claude [list|reset [dir]|off|on]` manages it;
the portal's *Ask at start* switch is `off`/`on`; `command claude` skips it.
- **The mod** (`worker/claude-mod`, loaded with `--plugin-dir` on Claude Code
≥ 2.1.312): a status line entry (`● synced to ai-agent · Gabriel's Claude ·
$8.20 left` / `○ your own Claude · /ai-agent sync to see it in the app`), a
toast with the conversation's link, `/ai-agent [sync|unsync]`, and — on the
guest's own Claude, when its plan runs out — a band offering *Continue on
ai-agent Claude*: it writes `relaunch.json` and exits, and the launcher
(still the parent) resumes the same session on ai-agent Claude.
- State (`~/.config/ai-agent-worker`): `claude-choice.json`,
`terminal-sessions.json` (which Claude each session ran on),
`terminal-synced.json` (listed in `/feed` as `synced`), `terminal-status.json`
(budget left, paused, the hub's address — pushed by the hub when `/health`'s
`terminal.statusHash` differs), `claude-launcher.off`.
## A machine off your tailnet (it dials out)
A machine of yours that the hub can't call — on another company's tailnet
(an Orus **devbox**), or on none (a cloud VM) — uses the same worker link as
a guest's computer, as one of **your** workers. **Add machine → It dials
out** asks where runs start, its name, which of the hub's accounts its Claude
login is, the profile it joins (and whether as its default worker), then
gives one line with a one-time code (an hour):
```bash
curl -fsSL https://git.gabvdl.xyz/gabrielvidal/ai-agent/raw/branch/main/worker/install.sh \
| WORKER_HUB=https://ai-agent.gabvdl.xyz WORKER_ENROLL=<code> WORKER_ACCOUNT=work \
WORKER_CWD='~/src/orus-monorepo' WORKER_OPENCODE=0 bash
```
The hub's answer to the code says it is yours (`/worker-link/enroll/check` →
`owner: true`; `link.json` keeps it), so the installer sets the machine up as
one of your workers, not a guest's: `notify` shims in a terminal, no *Which
Claude?* launcher. It listens on `127.0.0.1` only and long-polls the hub's
public host over HTTPS; the hub pairs with it through the link and puts it in
the picked profile (`backend/workers/link.py` → `on_paired`). The dialog waits
and turns to *Connected ✓* once it is online. Its link token rotates weekly,
like a guest's.
**It runs on its own Claude login.** The Claude proxy is on the tailnet host,
and the public host takes no owner token, so *Through the Homelab* is off for
it (the worker page refuses the switch: `kind: "worker_link"`). Its login is
watched like a Mac's in `own` mode (Settings → Logins health, sign in
again from its page).
### An Orus devbox, step by step
A devbox (`orus-monorepo/infra/devbox`) is an OVH server running a Fedora
bootc image: you work as `agent`, with no root, reachable only over the
**Orus** tailnet (its firewall lets nothing else in). The hub sits on the
personal tailnet, so it can't call the devbox: the devbox dials out. Its
image already has everything the installer needs (`python3` with `venv`,
`git`, `curl`, systemd with lingering on for `agent`, Claude Code in
`/usr/bin`).
1. Set the devbox up as its `use.md` says, at least: `tailscale ssh
agent@devbox-<name>`, then `claude auth login` with the Orus seat, `gh auth
login`, and the clone in `~/src` (`gh repo clone orus-tech/orus-monorepo
~/src/orus-monorepo`).
2. In the hub: **Settings → Machines → Add machine → It dials out**. Runs
start in `~/src/orus-monorepo`, Claude login **Work**, profile **Work**.
Leave *default worker* off to keep the Orus Mac as Work's default: the
devbox then only gets what the composer's *Runs on* chip pins to it. A
devbox never sleeps, so making it the default is the alternative.
3. Run the line in the devbox's shell, from `~/src/orus-monorepo`. It installs
into `~/.local/share/ai-agent-worker` and a systemd user unit, then
connects. Nothing else on the devbox changes.
What to expect:
- **The 6 AM reboot.** The devbox upgrades its image every day at 6 AM Paris
time and reboots. The worker comes back on its own, since lingering starts
`agent`'s user units at boot. Runs in progress at that time are lost, as
Orca's are.
- **Orca's sessions show up too.** The worker mirrors every Claude Code
transcript under `agent`'s `~/.claude/projects` (`sidecar/feed.py`), and
Orca's agents run as `agent` with that home. So their Claude Code sessions
appear in the hub as that worker's terminal sessions.
- **The logins are the runs' logins.** As on the Orus Mac, a run there uses
whatever the devbox is signed in to (`gh`, `gcloud`…). See the devbox's
`use.md`: "Logins are the agents' logins too".
- **Updates** come from Gitea over HTTPS, like any worker's. The devbox
reaches `git.gabvdl.xyz` and `ai-agent.gabvdl.xyz` from the internet; it
never needs the personal tailnet.
- `ai-agent-worker` lands in `~/.local/bin`. If that directory isn't on your
PATH, run it as `~/.local/bin/ai-agent-worker status`.
## Install
Prerequisites: Claude Code installed — **no login needed**: by default the
worker bills the Homelab's Claude accounts through the hub's Claude proxy (see
"The Claude proxy" below) — Tailscale up, `git`, and `uv` (or `python3` with
venv).
The easy way: hub → **Settings → Machines → Add machine** (top right, a
profile's *Add machine*, or ⌘K). A three-step wizard: *Where is it?* (on your
tailnet), then *Run this on it* — one line with the installer's questions
answered (its *Options*: where new runs start, opencode or not) — then *Paste
what it printed*:
```bash
curl -fsSL https://git.gabvdl.xyz/gabrielvidal/ai-agent/raw/branch/main/worker/install.sh \
| WORKER_ACCOUNT=work WORKER_CWD='~/WORK/orus' WORKER_OPENCODE=1 bash
```
Without the variables it asks on the terminal instead: the default working dir
(the directory you run it from, `y` to confirm — without a terminal it is taken
as is), the account (guessed from the login: gmail → `personal`, else `work`)
and opencode.
It clones this repo into `~/.local/share/ai-agent-worker/src`, builds a venv,
writes the service — `~/Library/LaunchAgents/xyz.gabvdl.ai-agent-worker.plist`
on macOS, `~/.config/systemd/user/ai-agent-worker.service` (+ its
`~/.config/ai-agent-worker/worker.env`) on Linux, bound to `tailscale ip -4`
on port 8790 — puts `ai-agent-worker` in `~/.local/bin`, waits for `/health`,
and prints the pairing string:
```
100.80.162.92:8790/K7QMX4PJ2R/you@company.com
```
Paste it in step 2 of the same dialog. The login at the end picks the hub
account automatically; the code works once.
Overrides (each skips its prompt or default): `WORKER_CWD` (where new runs
start; a leading `~` is expanded), `WORKER_PORT`, `WORKER_ACCOUNT` (the hub's
name for this login), `WORKER_OPENCODE` (`1`/`0`), `WORKER_BIND` (e.g.
`127.0.0.1` behind `tailscale serve`), `WORKER_REF` (the branch the clone
follows, `main`), `WORKER_ASKFORM` (`0` = don't install / set up ask-form).
`update` keeps the address, cwd, account, opencode and ask-form answers the
installed service already has.
On Linux the unit needs a user manager that outlives your login: the installer
runs `loginctl enable-linger` and says so when it can't (then
`sudo loginctl enable-linger $USER`).
`install-macos.sh` is the old name, kept so the old URL and the Macs'
`install-macos.sh --update` still work — it hands over to `install.sh`.
## Auto-update
A worker follows **the commit the hub is deployed from**. The homelab's
`services/ai-agent/deploy.sh` writes that commit to the hub's
`/data/deployed-commit`; the hub's 15 s liveness probe compares it with the
worker's `/health` `commit` and, when the worker is behind, calls its
`POST /update {commit}`. The worker then runs `install.sh auto-update <commit>`
detached:
1. fetch that exact commit from Gitea and check it out (detached HEAD);
2. if nothing under `sidecar/`, `cli/`, `worker/` or the notify skill changed,
stop there — no restart for a frontend-only deploy;
3. otherwise run the new installer's `update` (deps, service file, restart) and
wait for `/health` to report the new commit;
4. if it doesn't, check the previous commit out again and restart that — a
**rollback** (`state: rolledback`).
The outcome is in `~/.config/ai-agent-worker/update.json` (served in `/health`
as `update`) and the log in `update.log` next to `worker.log`. In-flight runs
survive the restart (they are detached). The hub's worker page shows the
version, where it stands (up to date / behind / updating / failed / ahead), the
last update, an **Update now** button and the auto-update switch.
- A worker **ahead** of the hub (`ai-agent-worker update` follows main) is left
alone until the hub catches up.
- A target that failed is retried after 6 h; any other attempt after 30 min
(a machine that slept mid-update, a commit not pushed to Gitea yet).
- Only the installer's own clone updates itself. A worker run from a dev
checkout reports `updatable: false` and never has its HEAD moved.
- An install from before auto-update has no `/update`: run
`install-macos.sh --update` on it once, by hand.
## OpenCode (GPT models on a ChatGPT seat)
The installer also offers the **opencode harness** (`WORKER_OPENCODE=1|0`
skips the question; `--update` keeps the first answer): it installs opencode
when missing (`brew install anomalyco/tap/opencode-v2`, else the official
script) and declares this Mac's opencode account under the hub's id for it
(`WORKER_OPENCODE_ACCOUNT`, default `chatgpt-work`) — `OPENCODE_BIN` and
`SIDECAR_OPENCODE_ACCOUNTS` in the plist. An opencode older than the one the
harness was last checked against (`OPENCODE_TESTED` in the installer) is
upgraded to it; a newer one is left alone. opencode's own data dir is used, so
a terminal `opencode` here shares the login (one made there before needs no
second sign-in), and its sessions show up in the hub too.
Log in from the hub — **Settings → Logins → OpenAI · Work → Log in with
ChatGPT**: a device code to enter at `auth.openai.com/codex/device`, from any
device; the card turns green once opencode has stored the login. From then on
the hub sends opencode runs on that account here (the worker's `/health` says
it hosts it), mirrors the sessions over the feed (`@opencode/<account>/…`) and
reads the seat's weekly usage % from this sidecar (`/opencode/usage`).
## Installing tools from the hub (the Setup checklist)
A worker's page in the hub (Settings → Machines → the worker → **Tools**)
lists claude, gh, opencode, agy, pi and ask-form — installed? signed in? —
and installs what's missing: **Install**, **Install all missing**, **Update**
(gh and pi: the others keep themselves current) and **Sign in** (gh's device
code inline; claude / opencode / agy → their account's sign-in). A guest's
own computer gets the same in *My computers*, for claude, gh and pi only.
The hub sends a tool **name**; the recipes are this checkout's
`worker/tools.sh` (`tools.sh install|update <tool>...`, runnable by hand too),
started detached by the sidecar (`sidecar/tools_install.py`,
`POST /tools/install`). User space only, never sudo:
| tool | how |
|---|---|
| claude | `claude.ai/install.sh` (update: `claude update`) |
| gh | the release build into `~/.local/bin`, checksum-checked (`brew` on a Mac that has it); *Update* only moves a gh the worker or brew installed |
| pi | the pi CLI (`npm i -g @earendil-works/pi-coding-agent` into `~/.local/share/ai-agent-worker/pi`, a `~/.local/bin/pi` wrapper) — on the machine's Node ≥ 22.19, else a private Node LTS under `~/.local/share/ai-agent-worker/node` (never on PATH). For a terminal: pi *runs* stay on the Homelab |
| opencode, agy, ask-form | `ai-agent-worker update` with `WORKER_OPENCODE` / `WORKER_AGY` / `WORKER_ASKFORM=1` — installs, declares the harness in the service and **restarts the worker once** (runs keep going); a batch does them together, last |
Progress: `~/.config/ai-agent-worker/tools/<tool>.json` + `<tool>.log`
(`/health`'s `toolJobs`, a log tail while it runs); one batch at a time
(`tools/lock`), never while an auto-update runs. The checklist re-checks as
soon as a job ends.
## Day to day
```bash
ai-agent-worker status # service state, /health, version, last auto-update
ai-agent-worker logs # follow worker.log + update.log
ai-agent-worker pair # a fresh pairing string (re-pair, or a new hub) — rotates the token on use
ai-agent-worker update # fetch the latest main + deps + restart (keeps the pairing)
ai-agent-worker uninstall # stop + remove the service (state in ~/.config/ai-agent-worker kept)
```
(`ai-agent-worker` is `~/.local/share/ai-agent-worker/src/worker/install.sh`;
the `--status`-style flags still work.)
Logs: `~/Library/Logs/ai-agent-worker/` on macOS,
`~/.local/state/ai-agent-worker/` on Linux — `worker.log` (the worker),
`update.log` (auto-updates) and `runs/<session>.log` (each `claude -p`).
State: `~/.config/ai-agent-worker/` (`token`, `worker.json`, a pending
`pairing-code`, `update.json`) — delete it to forget the hub.
## A Linux worker that sleeps on idle (the EVOX2)
While a run is live the sidecar holds a logind `sleep` **block** lock
(`sidecar/inhibit.py`), so a box that auto-suspends on input idle never
sleeps mid-run; it drops the lock once the last run ends. `/health` →
`sleepInhibitor` says whether it is on, available and held;
`SIDECAR_INHIBIT_SLEEP=0` turns it off.
polkit only grants that lock to an *active* (local, logged-in) session by
default, so a worker started as a service or over SSH reads `available: false`
with `reason: "Failed to inhibit: Access denied …"`. Allow the worker's user
once (root, on the machine):
```bash
sudo tee /etc/polkit-1/rules.d/50-ai-agent-worker-inhibit.rules <<'RULES'
polkit.addRule(function (action, subject) {
if (action.id == "org.freedesktop.login1.inhibit-block-sleep" &&
subject.user == "gabrielvidal") {
return polkit.Result.YES;
}
});
RULES
```
The sidecar retries every minute, so no restart is needed.
## Notes
- **Keychain (macOS).** A launchd agent runs in your GUI session and can read the login
keychain; the first run may pop a Keychain access prompt for `claude` — pick
*Always Allow*. If it can't, `claude setup-token` and add
`CLAUDE_CODE_OAUTH_TOKEN` to the plist's `EnvironmentVariables`.
- **Asleep = offline.** A closed lid drops the Mac off the tailnet; the hub
marks the worker offline and a new run sent to it is refused (*Send later* is
the way out). It catches up on updates as soon as it is back. In-flight runs survive a worker
restart (they're detached; launchd's `AbandonProcessGroup`), not a sleep.
- **Binding.** The listener is on the Tailscale IP only — nothing on the office
LAN. If the App-Store Tailscale client ever refuses the bind, set
`WORKER_BIND=127.0.0.1`, re-run the installer, and expose it with
`tailscale serve --bg --tcp 8790 tcp://127.0.0.1:8790`.
- **Remote Control** is on for a personal account and off for `work`
(`SIDECAR_REMOTE_CONTROL`): org-disabled on a work seat, and a work run must
not list itself there anyway. `WORKER_REMOTE_CONTROL=0|1` forces it.
- **Notifications and asks** work: the `notify` CLI (`cli/notify.py`,
on every run's PATH; `notify-done` / `notify-ask` are its aliases) queues
them in this worker's **outbox** (`/outbox`, in
`~/.config/ai-agent-worker/outbox.json`) and the hub collects them on its
2 s poll, records and forwards them, and pushes the tapped answer back —
the worker still never calls the hub. The installer links the skill's
`SKILL.md` into `~/.claude/skills/notify`. A `notify send --final` marks
the session finished in the hub; the exit watcher still covers runs that
end without one.
- **Driving the hub from here** (list, read, search conversations, start or
continue runs on this machine, schedule them): the hub's **MCP server**, not
the `ai-agent` CLI — `claude mcp add --transport http --scope user ai-agent
https://ai-agent.gabvdl.xyz/mcp`, `/mcp` → *Authenticate*, then on the hub
Settings → AI apps → that connection → *Acts as* → this worker: it sees this
machine's profile only and starts runs here only (the hub's `docs/mcp.md` →
"On a worker"). The `ai-agent` CLI in a run here keeps only `past`, through
the outbox.
- **A `claude` in a terminal** here gets `notify`, `notify-done` and
`notify-ask` too: the installer writes them into `~/.local/bin` as small
shims that point the CLI at this sidecar's outbox (its run token is read
from `~/.config/ai-agent-worker/outbox-token` at each call). A file of the
same name that isn't the installer's is left alone; `uninstall` removes
them; an old `ai-agent` shim of the installer's (2026-11-16 → 11-18) is
removed. A guest's computer gets none.
- **Forms** are the standalone [ask-form](https://github.com/GabrielVidal1/ask-form)
tool's. The installer sets it up (since 2026-11-23; `WORKER_ASKFORM=0` opts
out, and the answer is kept for `update`): when `ask-form` isn't on PATH it
runs `https://ask-form.xyz/install.sh` (which checks the release's checksums)
into `~/.local/bin`, then `ask-form setup --events-url
http://<the sidecar's bind address>:<port>/ask-form/events` (`127.0.0.1` on
a machine that dials out) — binary, `ask-form serve` as a launchd agent /
systemd user unit, the `ask-form` skill — and puts `~/.local/bin` on the
service's PATH. An `update` re-runs setup only when serve's events URL
(`~/.config/ask-form/serve.env`) isn't that one. A guest's computer gets
none (its sidecar wires an ask-form its owner installed).
Every form event (`created` with its link, `submitted`, …) lands on the
sidecar's `/ask-form/events` (this machine only), goes into the outbox as an
`askform` item the hub applies, and the hub also reads this machine's forms
through the sidecar's `/ask-form/forms` proxy to the tool's loopback admin
API — so a form asked here shows in the viewer, pushes its link to the
phone and lists in *Waiting for feedback* exactly like one asked on the
lab. Without the tool, a run's `ask-form` call prints the install hint
(`cli/ask-form`).
- **The lab's portable skills and agents** arrive by themselves: every homelab
skill/agent flagged `portable: true` (plus whatever Shortcuts & setup →
*Skills & agents* ticks for this worker — its Tools tab links there) is pushed by the hub to `/sync`,
kept under `~/.local/share/ai-agent-worker/lab-sync`, and symlinked into
`~/.claude/skills` / `~/.claude/agents` (and each declared account's dir) —
terminal sessions get them too. A skill of this machine's own under the same
name is left alone; `.env` files never travel, so a synced skill that needs a
secret needs it set here. Every run also gets the hub's `clarifier` subagent
(forms through the ask-form tool, answered on the phone).
- **Repo plugins** (since 2026-11-23): when the worker's default folder is a
repo with its own Claude Code plugin marketplace
(`.claude-plugin/marketplace.json` — orus-monorepo's `orus`, plugin
`work-context`), `/health` reports it and which of its plugins are on for
the default account (read off `~/.claude/settings.json` and
`~/.claude/plugins/*.json`, never the CLI). What the hub wants on — the
account's picks in Settings → Shortcuts & setup → Skills & agents →
*Repo plugins*, or this worker's own tick there — it applies through
`POST /repo-plugins`: `claude plugin marketplace add <cwd>/` once, then
`claude plugin install <plugin>@<marketplace> --scope user` (unticking is
`claude plugin disable`, never an uninstall). A plugin nobody ticked is
left as you set it by hand. The same by hand, from the checkout:
`claude plugin marketplace add ./` (`.` alone is refused) and
`claude plugin install work-context@orus --scope user`.
- **MCP servers** (since 2026-11-23; the hub's `mcp-servers` plugin since
2026-11-26): set up and signed in from the app, no terminal — the plugin's
page and the machine's page list every server each login sees, per harness
(`GET /mcp-servers`, `sidecar/mcp_base.py` + each harness plugin's
`sidecar/mcp.py`; listed every 30 min in the background and when the page
opens, URLs without their query strings). Claude: `claude mcp list` — the
ones the hub adds, the repo's `.mcp.json`, the machine's own, plugins', and
the login's claude.ai connectors; opencode and agy: their config files, the
hub's servers health-checked with an MCP `initialize`.
- **Sign in** (Claude) runs `claude mcp login <name> --no-browser` here on a pty and
hands the app the provider's link; after approving, the browser lands on a
dead `http://localhost:<port>/callback?code=…` page — paste its address in
the app and the sidecar replays it to that port here. The tokens stay in
this machine's Claude config, as with a terminal sign-in. A claude.ai
connector is a claude.ai link: approve there, nothing to paste. Or sign
in once on the hub, and every machine goes through its gateway.
- **Approve** a repo server pending approval: its name goes into
`enabledMcpjsonServers` of `~/.claude/settings.json` (every project).
- **Servers the hub adds** arrive through `POST /mcp-servers {harness,
account, add, remove}`: Claude `claude mcp add-json <name> - --scope user`
(the JSON on stdin — an API key never reaches `ps`), opencode a 0600 file
merged into each run's `OPENCODE_CONFIG_CONTENT`, agy a merge into
`~/.gemini/config/mcp_config.json` (0600). Only the ones the hub added are
replaced or removed (`~/.config/ai-agent-worker/mcp-managed.json`). Run
the sidecar outside a Claude Code session: `add-json -` refuses inside one.
- A guest's computer is never read nor touched.
- **Not yet:** the other lab skills that call the hub back (conv-meta,
complete).
## The Claude proxy: no login on the worker
A worker's Claude Code runs either **through the hub** (the default for a new
pairing) or on **its own login** (a machine already signed in — the Orus
MacBook keeps its work login). The switch, and which of the hub's accounts a
proxied worker may bill, are on the worker's page (Settings → Machines → the
worker); the logins themselves are on Settings → Logins, signed in once on
the Homelab.
Through the hub, the hub POSTs the worker its config (`/claude-proxy`: the
proxy URL, a bearer of its own, the accounts, the default one) and every run
on one of those accounts launches with
```
ANTHROPIC_BASE_URL=https://ai-agent.lab.gabvdl.xyz/proxy/claude/<account>
CLAUDE_CODE_OAUTH_TOKEN=<the worker's proxy token>
```
— the hub checks the worker may use the account, swaps in the Homelab's real
OAuth token and streams the reply back. The default (★) account's pair also
goes into `~/.claude/settings.json`'s `env`, so a `claude` typed in a terminal
there needs no login either; switching back to its own login (or unpairing)
takes those two keys out again. Settings `env` outranks the process
environment, so a hub run on another account carries its pair in its
`--settings` flag as well. The machine reaches the hub over the tailnet (the
lab's DNS resolves `*.lab.gabvdl.xyz`); the token can do nothing but model
calls on its own accounts.
### opencode through the hub
Its twin for ChatGPT seats: tick, on the worker's page, an opencode account
the **Homelab** holds a login for, and that worker's opencode runs on it bill
the Homelab's login through `/proxy/opencode/<account>`. The worker gives the
account a database of its own under `~/.local/share/ai-agent-worker/opencode/`
(a placeholder login: its proxy token) and points the run's ChatGPT provider
at the hub (`baseURL`, `transport: "http"`). A terminal `opencode` keeps the
machine's own login. Needs opencode installed (`WORKER_OPENCODE=1`).