# Use the CLI

Use a product that has rungent from a terminal or a script. Install its CLI, sign in once, find and run commands, confirm changes, and script it with JSON output and exit codes.

```bash
acme login https://console.example.com
acme vm stop gpu-train-01
```

```text
Stop server gpu-train-01? [y/N] y
{ "id": "vm-42", "name": "gpu-train-01", "status": "stopped" }
```

Every product with rungent has a command line. Its commands come from the product itself: what you
may do in the product, and nothing more. A new feature is a new command the next time you run it,
with nothing to update. The examples use the cloud console at `console.example.com` and its
branded CLI, `acme`.

## Install it

A product may publish its own CLI under its name; its docs or its `/skill.md` say how to install it.

```bash
npm install -g @acme/cli          # the console's own CLI: the command is acme
npm install -g @rungent/cli       # the same for any product: the command is rungent-cli
npx @rungent/cli --help           # or run it without installing
```

Both need Node.js 22 or later. A branded CLI is `rungent-cli` under another name, with the
product's address built in; everything on this page works the same with either. `--version`
prints the version.

## Sign in

You sign in with a token the product gives you, usually from a page where you create access
tokens; the product's docs say where. Give the CLI its own token, so you can revoke it alone.

```bash
acme login https://console.example.com      # asks for the token, without echoing it
acme login https://console.example.com --token-stdin < token.txt
acme status
```

`login` checks the token, saves it for that address, and makes the address your default, so later
commands need neither. A branded CLI with its address built in takes `acme login` alone. `status`
shows the address, which credential it used, and how many commands you have. `logout` forgets the
token.

## Find commands

```bash
acme tools                 # every command you may run, with its usage
acme tools server          # only those that mention "server"
acme vm stop --help        # one command's arguments and flags
acme search "gpu"          # search everything you can see, docs included
```

The list is yours: someone with other rights in the product sees other commands. It is cached for
five minutes.

## Run a command

```bash
acme vm list
acme vm stop gpu-train-01 --forced
acme vm create --name train-02 --zone-id z1 --tag ml --tag gpu
acme vm create --input-json spec.json --name train-03
```

| Input | How to write it |
|---|---|
| Positional arguments | In the order `--help` shows. A name often works where an id is asked: `gpu-train-01` for `vm-42`. |
| Other inputs | `--page-size 20` or `--page-size=20`; `_` in a name becomes `-`. |
| Booleans | `--forced`, `--no-forced`, `--forced=true`. |
| Arrays | Repeat the flag: `--tag a --tag b`. |
| Objects | A JSON object: `--labels '{"team":"ml"}'`. |
| The whole input | `--input-json <file\|->`: a JSON object from a file or stdin. Flags override its keys. |
| End of flags | `--`: everything after it is positional. |

A missing required input fails before anything is sent. When a product command has the same name
as a built-in one (`login`, `logout`, `status`, `tools`, `search`), the product's wins;
`acme rungent:login` always runs the built-in.

## Confirm changes

A command that changes something asks first, with the same title and target the product's
assistant would show: `Stop server gpu-train-01? [y/N]`. Type `y` to run it; anything else runs
nothing. `--yes` (`-y`), before or after the command, confirms without asking:

```bash
acme --yes vm stop gpu-train-01
```

Without a terminal, in a script or a CI job, a change is declined unless you pass `--yes`.

## Script it

Output is JSON on stdout, indented on a terminal and one line otherwise; messages and prompts go
to stderr. So a script reads it with any JSON tool:

```bash
acme vm list | jq -r '.[] | select(.status == "running") | .name'
```

In CI, skip `login` and set two variables: the address and the token. Nothing is written to disk,
and the token goes only to that address.

| Variable | `rungent-cli` | `acme` |
|---|---|---|
| The address | `RUNGENT_CLI_HOST` | `ACME_HOST` |
| The token | `RUNGENT_CLI_TOKEN` | `ACME_TOKEN` |

The address is `--host <url>`, else the variable, else the one `login` saved last, else the one
built in. The token is the variable, else the one `login` saved for that address. A branded CLI's
variables are its name in capitals with `_HOST` and `_TOKEN`, unless the product chose others.

| Exit code | Meaning |
|---|---|
| `0` | OK. |
| `1` | The command failed; the reason is on stderr as `error: …`. |
| `2` | Usage: an unknown command or flag, a missing or invalid value. |
| `3` | Sign-in: no address, not logged in, or the token was refused. |
| `4` | Network: the product cannot be reached, or answered another HTTP error. |

## Files it keeps

| Path | Content |
|---|---|
| `~/.config/rungent/hosts.json` | The tokens `login` saved, by address, and each CLI's default address. Readable only by you. |
| `~/.cache/rungent/tools/<hash>.json` | The command list, cached for five minutes. |

`XDG_CONFIG_HOME` and `XDG_CACHE_HOME` move them. Every branded CLI shares these files, each with
its own default address. No command prints a token.

## Where to go next

[Use with coding agents](use-with-agents.md) hands the CLI to an agent; [Use MCP](use-mcp.md)
connects one directly.
