> ## Documentation Index
> Fetch the complete documentation index at: https://customergpt.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI

> Create, train and test chatbots from your terminal, scripts and CI with @customergpt/cli.

The CLI does everything the [Actions API](https://customergpt.ai/docs/api-reference/actions/overview.md) does, with tables for people and JSON for scripts. It needs Node.js 20 or later. Commands that use your account need a plan with API access (Growth and above).

## Install

```bash theme={null}
npm install -g @customergpt/cli
```

```bash theme={null}
customergpt --version
```

To update, run `npm install -g @customergpt/cli@latest`.

## Sign in

```bash theme={null}
customergpt login
```

Your browser opens CustomerGPT. Sign in and approve the connection, then return to the terminal. The session is saved in `~/.config/customergpt/config.json` and refreshes on its own. Don't commit that file.

* `customergpt login --no-browser` prints the sign-in URL instead of opening it. Open it on the same computer.
* `customergpt login --read-only` asks only for read access, so the session can never change anything.
* `customergpt whoami` checks that you're signed in and shows your usage.
* `customergpt logout` signs out.

## Build a chatbot in five commands

```bash theme={null}
customergpt chatbots create "Acme Support" --url https://acme.com --yes
```

The output includes the new chatbot's `id`. Use it in place of `BOT_ID`:

```bash theme={null}
customergpt knowledge website add https://acme.com --chatbot BOT_ID --max-pages 20 --yes --wait
customergpt messages send "What do you offer?" --chatbot BOT_ID --yes
customergpt installation snippet --chatbot BOT_ID
```

`messages send` is a preview: it uses your message quota but doesn't create a conversation or reach a real visitor. Paste the snippet from `installation snippet` into your site before `</body>`. It contains the public Widget ID, never your API key.

For every command, see [CLI commands](https://customergpt.ai/docs/cli/commands.md).

## Try without an account

```bash theme={null}
customergpt onboarding start https://acme.com --yes --wait
```

This returns a temporary bot, a secret token, and a preview URL. Open the URL to ask questions and claim the bot into your account. Drafts expire after 24 hours and answer up to 20 preview messages. Keep the token private.

## Confirmations and dry runs

* **`--yes`** confirms a change, or a preview that uses your message quota. Without it, changes fail with `CONFIRMATION_REQUIRED`.
* **`--dry-run`** checks a change without making it. Run deletions and bulk changes this way first.
* **`--wait`** waits for training to finish, up to 15 minutes by default, and fails if the training fails. An interrupted wait doesn't stop the training; check it later with `customergpt jobs get JOB_ID`.

## Scripts and CI

In CI, set an [API key](https://customergpt.ai/docs/api-reference/authentication.md) instead of signing in:

```bash theme={null}
export CUSTOMERGPT_API_KEY=cgpt_...
customergpt chatbots list --json
```

To save a key without it ending up in your shell history, pipe it in: `customergpt login --token-stdin`.

Output is JSON when stdout isn't a terminal, when you pass `--json`, or when `CUSTOMERGPT_OUTPUT=json` is set. Results go to stdout; errors and progress go to stderr. Exit code `0` means success. Errors look like this:

```json theme={null}
{"ok":false,"error":{"code":"HTTP_401","message":"Invalid or expired OAuth access token","hint":"Run customergpt login or set CUSTOMERGPT_API_KEY."}}
```

To call any action directly, use `call`:

```bash theme={null}
customergpt call chatbots_list --json '{"limit":10}'
customergpt call sources_add --json-file source.json --yes --wait
```

## Profiles

Keep several accounts or servers without retyping keys:

```bash theme={null}
customergpt login --profile work
customergpt profiles list
customergpt profiles use work
customergpt chatbots list --profile work
```

The profile is chosen by `--profile`, then `CUSTOMERGPT_PROFILE`, then the saved default.

## Use it as an MCP server

The CLI includes an [MCP server](https://customergpt.ai/docs/developers/mcp.md) that uses your saved sign-in. After `customergpt login`, add this to a client that starts local servers:

```json theme={null}
{
  "mcpServers": {
    "customergpt": { "command": "customergpt", "args": ["mcp"] }
  }
}
```

On Windows, some clients need `"command": "cmd"` with `"args": ["/c", "customergpt", "mcp"]`.

## Use it from JavaScript

```js theme={null}
import { createClient } from "@customergpt/cli";

const customer = createClient({ key: process.env.CUSTOMERGPT_API_KEY });
const result = await customer.call("chatbots_list");
console.log(result.data);
```

For a fully typed client, use the [JavaScript SDK](https://customergpt.ai/docs/developers/sdk.md).

## For AI coding agents

`customergpt agent-guide` prints the workflow and command map for AI agents. The agent skill that ships with the CLI teaches Claude Code, Codex, Cursor and others to build a support bot safely. It's also available at `https://api.customergpt.ai/agents/customergpt-cli-skill.md`.

## Shell completion

```bash theme={null}
source <(customergpt completion zsh)   # or: completion bash
```

Add the line to `~/.zshrc` or `~/.bashrc` to keep it.

## Configuration

| Variable | Purpose |
| - | - |
| `CUSTOMERGPT_API_KEY` | API key for scripts and CI. It overrides a saved sign-in. |
| `CUSTOMERGPT_PROFILE` | Selects a saved profile. |
| `CUSTOMERGPT_OUTPUT` | `json` forces JSON output; `human` forces tables even when piped. |
| `CUSTOMERGPT_API_URL` | API origin, without `/api`. Default `https://api.customergpt.ai`. |
| `CUSTOMERGPT_CONFIG_FILE` | Where the config file lives. |
| `CUSTOMERGPT_DASHBOARD_URL` | What `customergpt dashboard` opens. |
| `NO_COLOR`, `FORCE_COLOR` | Turn colored output off or on. |

## Troubleshooting

| Problem | What to do |
| - | - |
| `customergpt` isn't found | Check that npm's global directory is on your PATH, then open a new terminal. |
| 401, or the sign-in expired | Run `customergpt login` again. Check that `CUSTOMERGPT_API_KEY` isn't overriding your sign-in. |
| 400 "API Access Denied" | Your plan doesn't include API access. Upgrade to Growth or above. |
| `CONFIRMATION_REQUIRED` | Review the change, then add `--yes`. Use `--dry-run` to check first. |
| Chatbot not found | Use the chatbot's `id`, not its Widget ID, and check which account you're signed in to. |
| Training times out | Run `customergpt jobs get JOB_ID`. A timeout doesn't stop the training. |
| Something else | Run `customergpt doctor`. It checks Node.js, your config, the server, and your sign-in, and reports what's wrong. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.