# ConfigHub: Agent Setup & Ongoing Session Guide

> Free, open-source (MIT) Zero-Hub plugin and local operations factory for Claude Code, Codex CLI, and agent swarms: tracked config receipts across chats, pre-write undo protection, isolated previews, and human-approved production rollouts.

## HARD RULES FOR AGENTS (READ FIRST: STOP BEFORE RUNNING ANYTHING)
1. **Person runs install:** Never run `claude plugin marketplace add` or `claude plugin install` unattended. Hand the command to the human, or open a 1-file `.claude/settings.json` PR with the Consent Card below.
2. **Marketplace collision check first:** Run `claude plugin marketplace list`. If `confighub` already points to `confighub/confighub-skills` (or if permissions block you from running the check), STOP, inform the human, and do NOT proceed to install.
3. **Hooks load in a new chat:** Tell the user that after installing (or after `/confighub:staging`), they need to open a fresh chat for hooks and scoped keys to activate, and give them a 1-line carry-over prompt (`Check ConfigHub for our recent settings and continue.`).
4. **Hard-gate boundary:** Server-side production approval enforces a hard gate only when raw host production credentials (such as a logged-in `vercel` or `fly` CLI) stay out of the agent's shell. When the agent holds provider creds, recommend `CUB_MINI_MODE=team` and running host deploys in the owner's terminal.

## Trust, License & Footprint
- **License & org:** Free and open source (MIT) Zero-Hub client plugin (`v0.99.44`, ~5 MB gzipped, client binary only, zero server) published under [`confighubai`](https://github.com/confighubai/confighub-mini-plugin) (ConfigHub's official AI org). Optional Local Hub server binaries come from the official [`confighub/cub-server`](https://github.com/confighub/cub-server) plugin (`cub plugin install confighub/cub-server && cub server local up`) under ConfigHub's Evaluation License; hosted Remote Hubs are on `confighub.com`.
- **Zero Hub -> Local Hub -> Remote Hub (same 7 `cub <noun> <verb>` groups):** Start with Zero Hub (plugin alone), add a Local Hub on `127.0.0.1` via `cub server local up`, `cub local start`, or `/confighub:staging`, or graduate to a Remote Hub (`confighub.com` or self-hosted Helm) via `/confighub:to-hub` or `cub local to-hub`. Legacy `cub mini ...` commands remain supported as a silent compatibility alias.
- **Footprint & overhead:** Zero Hub runs only on this laptop with zero background servers, zero account, and zero outbound ConfigHub network calls (`~20 ms` median pre-tool hook, `~100-175 ms` once a Local Hub is attached, fail-closed `SHA256SUMS` check). Optional Local Hub runs the official ConfigHub server, PostgreSQL, and Web UI on `127.0.0.1` (no Docker), and `/confighub:staging` restricts Claude's sandbox network to localhost (run `npm install` or host CLIs in your own terminal).
- **Storage & help:** Local history lives in `~/.confighub/agent-changes` on this machine. Run `/confighub:help` anytime inside Claude Code for a 1-screen repo capabilities menu.

---

## Step 1: Inspect the Environment First (Idempotent)

Before proposing any install, check what is already present and detect the repo stack:

1. Check existing tools and setup:
   - `command -v confighub || command -v cub`
   - `claude plugin marketplace list` (if Claude Code is installed)
   - `ls -la ~/.confighub .claude/settings.json AGENTS.md 2>/dev/null`
2. Detect repo config and deploy surfaces (Spring-Boot auto-detection style):
   - `.env*`, `app-config.json`, `config/*.yaml`, `/etc/<app>/<app>.yaml`
   - `vercel.json`, `fly.toml`, `Procfile`
   - `k8s/`, `Chart.yaml`, `argocd/`, `flux/`
   - `Dockerfile`, `docker-compose.yml`, `.devcontainer/`
3. **Fit rubric (recommend the smallest stage that fits):**
   - Plain `.env`/JSON/YAML repo or PaaS host (Vercel, Fly, Heroku): start with **Zero Hub (plugin alone)** (zero repo layout changes, zero server). Add a Local Hub only when isolated previews, staging/prod separation, or server-side approvals are needed.
   - Helm charts + Argo CD, Flux, or Sveltos: start with read-only **Inventory** (`https://confighub-ai-agents.pages.dev/docs/inventory.html`, no 12-chart cap) plus the **GitHub PR review Action** (`https://confighub-ai-agents.pages.dev/docs/review-readme.html`).
4. If ConfigHub is already installed and configured for this repo, skip to Step 6 (Verification).

---

## Step 2: Show the 4-Line Consent Card and Ask

Present this summary to the human and wait for `y/n` approval (or offer a PR):

```text
ConfigHub setup summary:
- Installs: confighub@confighub (MIT open-source Zero-Hub plugin v0.99.44, SHA256SUMS fail-closed, ~20 ms/hook)
- Local state: ~/.confighub/agent-changes (0 servers, 0 account, 0 outbound ConfigHub network calls)
- Repo changes: optional .claude/settings.json + 5-line AGENTS.md rule (zero app code changes)
- Uninstall: remove .claude/settings.json entry (or run `claude plugin uninstall confighub@confighub`) and `rm -rf ~/.confighub/agent-changes`
Proceed? [y/n]
```

---

## Step 3: Install via the Matching Harness Path (After Consent)

### Claude Code (solo developer)
First run `claude plugin marketplace list` to confirm `confighub` does not already point to `confighub/confighub-skills` (if it does, or if permissions block the check, stop and ask the user). Then ask the user to run:

```sh
claude plugin marketplace add confighubai/confighub-mini-plugin && claude plugin install confighub@confighub
```

Add `--scope project` to limit installation to this repository. Set `CUB_MINI_EARLIER_SESSIONS=lazy` for on-demand transcript lookup (or `=0` to disable backfill).

### Claude Code (team or PR-based handoff)
Open a branch/PR adding `.claude/settings.json` (omit `"env"` for solo defaults):

```json
{
  "extraKnownMarketplaces": {
    "confighub": {
      "source": { "source": "github", "repo": "confighubai/confighub-mini-plugin" }
    }
  },
  "enabledPlugins": {
    "confighub@confighub": true
  },
  "env": {
    "CUB_MINI_MODE": "team"
  }
}
```

Paste the 4-line Consent Card into the PR description. Merging the PR is the owner's approval.

### Codex CLI
Review the manual clone and checksum steps at `https://confighub-ai-agents.pages.dev/docs/codex.html#set-it-up` (pinned `v0` clone with fail-closed `SHA256SUMS`, no `curl | bash`), then run with user consent:

```sh
[ -d "$HOME/confighub-mini-plugin" ] || git clone --depth 1 --branch v0 https://github.com/confighubai/confighub-mini-plugin "$HOME/confighub-mini-plugin"
"$HOME/confighub-mini-plugin/plugins/confighub/bin/confighub" agent setup
```

### Cursor, Antigravity, Windsurf, Pi & Swarm Workers
Install the portable skill below to `.agents/skills/confighub-mini/SKILL.md` and append the 5-line `AGENTS.md` rule in Step 4 so every future session and subagent uses ConfigHub automatically.

---

## Step 4: Ongoing Session & Swarm Persistence (`AGENTS.md`)

Ask the user whether to append this 5-line rule to `AGENTS.md` (or `CLAUDE.md`) so fresh chats and parallel swarm workers inherit it on boot:

```markdown
## Config changes (ConfigHub)
Before editing `.env*`, `k8s/`, `helm/`, `vercel.json`, `fly.toml`, or service config files:
1. Check prior intent (`cub agent why <file>` or `/confighub:why`) before modifying or reverting any setting.
2. Record a plain-English reason for every config edit so later chats and parallel swarm workers see why it changed.
3. Never write directly to production; propose a change order for human `cub inbox approve BASE/ORDER`.
```

---

## Step 5: Portable Pain-Triggered `SKILL.md` Template

Save to `.agents/skills/confighub-mini/SKILL.md` for harnesses without native hooks:

```markdown
---
name: confighub-mini
description: Use BEFORE editing .env*, k8s/*.yaml, Helm values, fly.toml, vercel.json, or app config files; when checking why a setting changed, running isolated local previews, reverting config without git reset, building OCI config bundles, or coordinating config across parallel agents/swarms. Skip for pure application source edits.
---

1. Before modifying or reverting a config value, run `cub agent why <file>` (or inspect `~/.confighub/agent-changes`) so you do not silently undo an earlier session's uncommitted override.
2. Include a concise plain-English reason with every config change. Protect sensitive keys with `cub agent lock` and roll back config alone with `cub agent undo`.
3. Never apply changes directly to production. Update preview/staging and print the exact `cub inbox list --card` and `cub inbox approve BASE/ORDER` commands for the human owner.
4. Before opening a PR with config changes, attach a secret-redacted Config Receipt via `cub agent changes --export-md`.
```

---

## Step 6: 10-Second Verification & Next Steps

1. Open a fresh chat so hooks activate, then confirm recording works: make one small uncommitted edit to a sample local config file with a reason, and verify `cub agent why <file>` (or `/confighub:why`) recalls the old value and reason.
2. Need a custom stack wiring? Read `https://confighub-ai-agents.pages.dev/recipes/template.md` and generate a Connection Recipe for this repository.
3. Need to sync across multiple machines or remote sandboxes without signing up first? Read `https://confighub-ai-agents.pages.dev/auth.md` (pull-only, when explicitly requested) for anonymous Ed25519/X25519 keypair provisioning and cross-environment share.
4. Growing across One ConfigHub (same 7 `cub <noun> <verb>` command groups; `cub mini` stays as a silent compatibility alias):
   - **Stage 1: Zero Hub (Plugin alone):** Free, MIT open source (`v0.99.44`), offline, 0 servers, 0 account.
   - **Stage 2: Local Hub (`127.0.0.1`):** Official `confighub/cub-server` plugin (plugin MIT; server under ConfigHub Evaluation License) with localhost PostgreSQL and Web UI, no Docker, no cloud account (`cub plugin install confighub/cub-server && cub server local up`).
   - **Stage 3: Remote Hub (Cloud or VPC):** Hosted on `confighub.com` or self-hosted Helm + OIDC/SSO for teammates, PR-triggered isolated envs, named human approvers, and fleet governance. Export plain YAML back to Git anytime (`cub repo back-to-git`).
