# CLI (cchp)

Source: https://cch-plus.com/en/docs/cli

> Install and use cchp, the official command-line tool for managing CCHP servers, automating control-plane workflows safely, and reading or searching the CCHP documentation from your terminal or AI coding agents.

[`cchp`](https://github.com/CCH-HQ/cchp-cli) is the official command-line tool for CCHP (Claude Code Hub Plus). It serves both interactive operators and automated workflows from a single binary:

- **Interactive terminal UI**: Run `cchp` with no arguments in a terminal to open a home screen with a usage dashboard and 365-day activity heatmap, wallet and package status, upstream providers, provider keys, LLM tokens, recent requests, and built-in guides.
- **Automation and AI agents**: Run any CCHP control-plane operation that accepts a management token behind a single, predictable JSON contract (`--json`), with offline command and JSON Schema discovery, strict read-only-by-default safety gates, secret redaction, and an embedded Claude Code skill.
- **Documentation lookup (`cchp docs`)**: Read and search the public CCHP documentation in all six languages directly from the terminal—no sign-in required.

If you have not deployed a CCHP server yet, start with [Installation](https://cch-plus.com/en/docs/installation). You can still use `cchp docs` before setting up a server.

## Install

### Homebrew (macOS / Linux)

Install from CCH-HQ's official tap on macOS or Linux (Apple Silicon/ARM64 and Intel/AMD64). Homebrew installs the release binary and sets up Bash, Zsh, and Fish completions automatically:

```bash
brew install cch-hq/tap/cchp
```

To upgrade later:

```bash
brew update && brew upgrade cchp
```

### Install script (macOS / Linux)

Download the latest release archive for macOS or Linux (`amd64` or `arm64`), verify its SHA-256 digest against `checksums.txt`, and install `cchp` into `~/.local/bin`:

```bash
curl -fsSL https://raw.githubusercontent.com/CCH-HQ/cchp-cli/main/install.sh | sh
```

You can pin a release or change the destination directory with environment variables:

```bash
curl -fsSL https://raw.githubusercontent.com/CCH-HQ/cchp-cli/main/install.sh | \
  CCHP_VERSION=v0.2.0 CCHP_INSTALL_DIR=/usr/local/bin sh
```

Re-run the script to upgrade to the latest release. Make sure `~/.local/bin` (or your `CCHP_INSTALL_DIR`) is on your `PATH`.

### Go & manual download

Every release on [GitHub Releases](https://github.com/CCH-HQ/cchp-cli/releases) includes prebuilt archives for Linux, macOS, and Windows (`amd64` and `arm64`) along with a `checksums.txt` file:

```bash
sha256sum --ignore-missing -c checksums.txt
```

Or build from source with Go 1.27 or newer:

```bash
go install github.com/CCH-HQ/cchp-cli/cmd/cchp@latest
```

### Verify the installation

```bash
cchp --version
cchp version
```

`cchp --version` prints the CLI version. `cchp version` also displays the pinned CCHP control-plane spec version and build metadata (pass `--json` for structured output).

To configure shell completions manually (outside Homebrew), run `cchp completion bash`, `cchp completion zsh`, or `cchp completion fish`.

## Configuration and authentication

`cchp` authenticates with a CCHP **management API token** (`cch_auth_live_...`). Create one in the console under **Account & Security** → **Management API tokens** (see [Create a management token](https://cch-plus.com/en/docs/operations/management-tokens)).

> [!WARNING]
>
> `cchp` does not accept LLM keys (`cch_llm_live_...`). LLM keys are only for calling models through the gateway—see [Create an LLM key](https://cch-plus.com/en/docs/guide/llm-keys). For security, `cchp` never accepts a token as a command-line argument.

### Interactive sign-in

```bash
cchp login
cchp status
cchp whoami
cchp logout
```

- `cchp login` prompts for your server address and management token (hidden as you type), verifies the token with the server, and stores it securely. Plain `http://` is permitted only for loopback addresses (`localhost`, `127.0.0.1`, `::1`); remote servers require `https://`.
- `cchp status` confirms which server you are signed in to and verifies that the token works (`--offline` reads local state only).
- `cchp logout` deletes the saved credential for the current server on your machine. To revoke the token itself, revoke it in the console.

### Scripts, CI, and multiple servers

For non-interactive workflows, provide the token through stdin, a private file (`chmod 600`), or an environment variable:

```bash
# Option 1: save a sign-in non-interactively
printf '%s' "$TOKEN" | cchp login --server https://hub.example.com --token-stdin --json
# or read from a file:
cchp login --server https://hub.example.com --token-file ~/.config/cchp/token --json

# Option 2: supply credentials per run without saving
export CCHP_BASE_URL=https://hub.example.com
export CCHP_TOKEN_FILE=~/.config/cchp/token    # mode 600; refused if group/world-readable
# or: export CCHP_TOKEN=...                    # do not set both CCHP_TOKEN and CCHP_TOKEN_FILE
cchp status --json
```

Each signed-in server is stored as a separate origin entry in `config.json`. To target a different saved server, set `CCHP_BASE_URL` to that server's URL; `cchp` binds every token strictly to its server origin and drops credentials on cross-origin redirects.

Credential resolution order:

1. `CCHP_TOKEN` or `CCHP_TOKEN_FILE` (must be paired with `CCHP_BASE_URL`).
2. Saved credential matching `CCHP_BASE_URL`.
3. Saved credential for the most recently signed-in (`current`) server.

### Configuration files and environment variables

| Variable / Path | Purpose | Default |
| - | - | - |
| `CCHP_BASE_URL` | Target CCHP server origin (selects saved server or pairs with token env vars) | Current signed-in server |
| `CCHP_TOKEN` | Management token passed via environment | — |
| `CCHP_TOKEN_FILE` | Path to a mode-600 file containing the management token | — |
| `CCHP_CREDENTIAL_STORE` | Force credential backend: `keychain` or `file` | System keychain (falls back to mode-600 `credentials.json`) |
| `CCHP_CONFIG_DIR` | Directory for `config.json` and fallback `credentials.json` | `~/.config/cchp` (Linux), `~/Library/Application Support/cchp` (macOS), `%AppData%\cchp` (Windows) |
| `CCHP_CACHE_DIR` | Directory for the embedded engine cache and `docs/` cache | User cache dir (`cchp/`) |
| `CCHP_AGENT` | Set to `1` to force agent mode (JSON output, non-interactive, read-only by default) | Auto-enabled with `--json` or non-TTY stdout |
| `NO_COLOR` | Disable ANSI colors in terminal output | Unset |

## Safety model and automation

Agent mode activates automatically when you pass `--json`, set `CCHP_AGENT=1`, or pipe stdout to another process. In agent mode, `cchp`:

- prints exactly one JSON result object to stdout (`schema_version`, `ok`, `operation`, `status`, `request_id`, `data`, `pagination`, `error`, and related metadata);
- writes diagnostics to stderr and exits nonzero with a stable `error.kind` and exit code on failure;
- never opens interactive prompts, pagers, or colored output.

### Read-only by default and write gates

Every CCHP operation is classified by risk in `cchp`'s embedded policy (unclassified operations default to `write`):

| Risk level | Behavior in agent mode | Required flags |
| - | - | - |
| `read` | Allowed by default | None |
| `write` | Blocked unless explicitly enabled | `--allow-write` |
| `destructive` (delete / replace) | Requires explicit confirmation of the operation ID | `--allow-write --confirm <operationId>` |
| One-time secret response | Prevents secrets from leaking to stdout or logs | `--allow-write --confirm <operationId> --secret-out <new-file>` |

In an interactive terminal, human mode runs writes directly and prompts for confirmation on destructive or secret-producing operations. Without a terminal, `--confirm <operationId>` is always required.

### Dry-run, secret handling, and redaction

- **`--dry-run`**: Builds and validates the request locally and prints the exact HTTP method, URL, headers, and body without sending anything or needing credentials.
- **`--secret-out <new-file>`**: Writes one-time secrets (such as newly created LLM keys or management tokens) to a brand-new mode-600 file (refusing to overwrite existing files) and replaces the secret fields with placeholders in `data`.
- **Automatic redaction**: Across `--dry-run`, `--debug`, error messages, and response traces, `cchp` masks `Authorization` headers, cookies, CSRF tokens, human-check proofs, CCHP tokens (keeping only the public prefix), and credential-like JSON fields (`password`, `api_key`, `clientSecret`, `plaintext`, and similar keys) at any depth.
- **Safe retries and console-only boundaries**: Reads retry automatically on transient network errors, `408`, `429`, and `5xx`. Mutations are never retried automatically; if a change receives no clear answer (`unknown_outcome`, exit code `12`), check server state first and reuse the returned `idempotency_key` via `--idempotency-key` if retrying. Actions requiring a browser session (`browser_session_required`) or human verification (`human_verification_required`, exit code `8`) stop cleanly and tell you to complete them in the console.

### Offline discovery, schema checks, and agent skills

Agents can discover operations and inspect their exact parameters and JSON Schemas offline using the spec built into `cchp`, then call any operation through the stable `cchp api <operationId>` entry point:

```bash
cchp commands --search "provider keys" --json          # find matching operations offline
cchp commands show listProviderKeyPage --json          # flags, risk level, and examples
cchp schema listProviderKeyPage --json                 # parameter and JSON Schema details
cchp api listProviderKeyPage --provider-id <id> --json # stable entry point for scripts
```

- Pass JSON request bodies via `--body-file body.json` (or `--body-file -` for stdin). `cchp` validates the body against the schema locally before sending and preserves `null`, `false`, `0`, and `""` verbatim.
- `orgId` defaults to your management token's organization.
- List commands support `--cursor` / `--page`, or multi-page collection with `--page-limit N --max-items M`. Use `--output <file>` (`-` for stdout) for binary downloads, `--max-events N` for streams (agent mode defaults to 20), and `--timeout` (default `60s`) to bound execution time.
- Install the embedded agent skill for Claude Code or print an `AGENTS.md` snippet:

```bash
cchp skill install --project      # installs to .claude/skills/cchp
cchp skill install --user         # installs to ~/.claude/skills/cchp
cchp skill show --agents-md       # prints an AGENTS.md snippet
```

## Common commands

Run `cchp --help` to list every command group, `cchp <group> --help` for commands in a group, or `cchp guide` for built-in short guides. All grouped commands execute the exact same engine and policy layer as `cchp api <operationId>`.

| Group | What it covers | Example commands |
| - | - | - |
| `account` | Identity, permissions, preferences, announcements | `cchp account me`, `cchp account permissions` |
| `org` | Organization info, members, teams, roles, invitations, audit logs | `cchp org show`, `cchp org members`, `cchp org teams`, `cchp org audit` |
| `providers` | Upstream providers, endpoints, groups, network proxies, health checks | `cchp providers list`, `cchp providers counts`, `cchp providers set-network-proxies` |
| `keys` | Upstream provider keys, balances, health checks, model sync | `cchp keys list`, `cchp keys balance`, `cchp keys check` |
| `models` | Model catalog, aliases, pricing, price-table sync | `cchp models catalog`, `cchp models list`, `cchp models pricing` |
| `llm-tokens` | Gateway LLM keys for members and applications | `cchp llm-tokens list`, `cchp llm-tokens create` |
| `tokens` | Management API tokens | `cchp tokens list`, `cchp tokens create`, `cchp tokens revoke` |
| `usage` | Usage summaries, trends, breakdowns by model/provider/team, live metrics | `cchp usage summary`, `cchp usage by-model`, `cchp usage by-provider` |
| `requests` | Request logs, attempt history, archived payloads | `cchp requests list`, `cchp requests get` |
| `billing` | Wallet overview, invoices, plans, quota policies, adjustments | `cchp billing wallet`, `cchp billing quota-policies`, `cchp billing create-quota-policy` |
| `admin` | Platform-wide system info, organizations, users, domains, audit logs | `cchp admin about`, `cchp admin orgs`, `cchp admin users`, `cchp admin audit-logs` |

Additional specialized groups include `safety` (moderation, privacy, client and error rules), `overrides` (request/response rewrite rules), `operations` (announcements, redeem codes, billing adjustments), `config` (configuration drafts and rollout experiments), `plugins`, `tasks`, `import` (including `cchp import run` for CC Hub imports), and `public` (unauthenticated health and status endpoints).

### Everyday examples

```bash
# Inspect usage, providers, keys, and recent requests
cchp usage summary
cchp providers list
cchp keys list --provider-id <provider-id>
cchp requests list --limit 20
cchp requests get <request-id>

# Preview a write safely with --dry-run before applying it in agent mode
cchp billing create-quota-policy --body-file policy.json --dry-run --json
cchp billing create-quota-policy --body-file policy.json --allow-write --json

# Destructive replacement: requires both --allow-write and --confirm <operationId>
cchp providers set-network-proxies <provider-id> \
  --body-file proxies.json --allow-write --confirm saveProviderNetworkProxies --json
```

## Reading and searching docs via CLI (`cchp docs`)

`cchp docs` reads the official CCHP documentation at `https://cch-plus.com` through its [`llms.txt`](https://llmstxt.org) endpoints (`/<lang>/llms.txt`, `/<lang>/llms-full.txt`, and per-page `/<lang>/docs/<slug>.md`) and the site's full-text search API (`/api/docs/search`).

> [!NOTE]
>
> `cchp docs` accesses public documentation only. It requires no sign-in, never reads saved credentials, and its HTTP transport refuses any request carrying `Authorization`, `Proxy-Authorization`, or `Cookie` headers. It is also read-only, so AI agents can call it without `--allow-write`.

### Subcommands

| Command | Endpoint read | Output |
| - | - | - |
| `cchp docs index` | `/<lang>/llms.txt` | Complete table of contents grouped by section (title, slug, URL, description) |
| `cchp docs read <slug\|url>` | `/<lang>/docs/<slug>.md` | One documentation page as Markdown (rendered on a terminal, raw Markdown when piped, or JSON with `--json`) |
| `cchp docs search <words>...` | `/api/docs/search` | Ranked section matches with title, section, slug, URL, snippet, and relevance score |
| `cchp docs full` | `/<lang>/llms-full.txt` | All documentation pages for a language combined into one Markdown document |

### Examples

```bash
# Search and fetch the top matching page's full Markdown in a single call (ideal for AI agents)
cchp docs search "docker compose" --lang en --read-top 1 --json
cchp docs search "network proxy" --limit 5 --read-top 2 --json

# Read a specific page by slug, path, or cch-plus.com URL
cchp docs read installation/docker-compose
cchp docs read providers/network-proxies --lang en --json

# Browse the full index or export every page in one Markdown file
cchp docs index --lang en
cchp docs full --lang en > cchp-docs-en.md
```

- **Search flags**: `--limit N` returns between `1` and `50` matches (default `10`). `--read-top N` embeds the full Markdown of the top `N` unique pages directly on each page's first result so an agent can answer and cite `url` in one round trip. CJK queries do not require spaces between words.
- **Language selection**: Supports `zh-CN`, `zh-TW`, `en`, `ja`, `ko`, and `ru`. `cchp` resolves the language in order: `--lang` → `CCHP_DOCS_LANG` → system locale (`LC_ALL`, `LC_MESSAGES`, `LANG`) → `en`. If a page is missing in the chosen language, `cchp docs read` returns `not_found` and lists the languages that have it.
- **Caching and preview sites**: `llms.txt`, pages, and `llms-full.txt` are cached under `<CCHP_CACHE_DIR>/docs` for up to 5 minutes (within server cache headers), then revalidated via `ETag` and `Last-Modified`—stale cached content is never served if the site fails. Search results are never cached. Pass `--no-cache` to bypass the cache, `--docs-url` (or `CCHP_DOCS_URL`) to read from a local preview such as `http://127.0.0.1:8787` (plain `http://` is loopback-only), and `--dry-run` or `--debug` to inspect requests.
