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

# Use the CLI with coding agents

> Set up Claude Code or Codex to manage Totebot with the CLI

A coding agent can run `totebot` commands for you: "update the delivery FAQ on every agent", "triage unassigned tickets", "clone the SLO agent for Croatia".

## Set up

**1. Install and sign in**

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

When approving, turn on only the write scopes the agent needs. You can change them later under **Team settings** → **API keys** → **Edit access**.

**2. Teach the agent the CLI**

`totebot ai-guide` prints a guide written for agents: the rules (JSON output, exit codes, dry runs, when to use `--yes`), recipes and the full command map.

* **Claude Code:** copy the skill into your project:
  ```bash theme={null}
  mkdir -p .claude/skills
  cp -r "$(npm root -g)/@totebot/cli/skills/totebot" .claude/skills/
  ```
  Claude Code then picks the skill whenever you ask for a Totebot change.
* **Codex and other agents:** add the guide to your `AGENTS.md`:
  ```bash theme={null}
  totebot ai-guide >> AGENTS.md
  ```

**3. In CI or a sandbox**

Set `TOTEBOT_API_KEY` instead of logging in. Use a key with the smallest scopes that work.

## Recipes

### Update an FAQ on every agent

```bash theme={null}
totebot bulk qa --all-agents \
  --question "How long does delivery take?" \
  --answer "2-3 working days within Slovenia and Croatia." \
  --train --json
```

### Sync a folder of FAQs

```bash theme={null}
totebot bulk qa --agents agt_slo,agt_hr --from-file faq.json --train --json
```

### Keep a document in sync

```bash theme={null}
totebot bulk text --all-agents --title "Shipping policy" --file docs/shipping.md --train --json
```

### Test, preview, then change instructions

```bash theme={null}
# Run the test questions against the proposed prompt; exit code 10 below 90%
totebot tests run agt_slo --prompt-file prompt.md --fail-under 90 --json
# Spot-check one question with the proposed prompt (nothing is saved)
totebot chat agt_slo "Do you deliver on Saturdays?" --prompt-file prompt.md --json
# See each field before and after, then apply
totebot agents update agt_slo --prompt-file prompt.md --dry-run --json
totebot agents update agt_slo --prompt-file prompt.md --yes --json
```

### Roll back a bad change

```bash theme={null}
totebot agents revisions agt_slo --json
totebot agents diff agt_slo <revision>
totebot agents rollback agt_slo <revision> --dry-run --json
totebot agents rollback agt_slo <revision> --yes --json
```

`totebot ai-guide` has the full "Optimize my agents" recipe: analyse, propose, test before applying, apply, verify, roll back. [Optimize your agents with Claude Code](https://docs.totebot.ai/cli/optimize-agents.md) walks through it step by step.

### Gate a deploy on test questions

```bash theme={null}
totebot tests export agt_slo > tests.json   # keep it in git
totebot tests import agt_slo tests.json     # sync edits back
totebot tests run agt_slo --fail-under 90 --format junit > junit.xml
```

### Clone an agent for a new market

```bash theme={null}
totebot agents duplicate agt_slo --name "Example HR" --json
totebot agents update "Example HR" --language hr --yes --json
totebot train start <new-agent-id> --wait --json
```

### Fix failed knowledge

```bash theme={null}
totebot knowledge list agt_slo --status FAILED --json
totebot knowledge retry-failed agt_slo --json
```

### Triage the help desk

```bash theme={null}
totebot tickets list --view UNASSIGNED --json
totebot tickets assign tkt_123 --to ana@example.com --json
totebot tickets note tkt_123 --message "Customer asked twice; prioritise." --json
```

### A session in Claude Code

> **You:** Our delivery time is now 2-3 days. Update every agent.
>
> **Claude Code** runs `totebot whoami --json`, then `totebot bulk qa --all-agents --question "How long does delivery take?" --answer "2-3 working days." --dry-run --json`, shows you the planned change, runs it without `--dry-run` and with `--train`, and reports that both agents now have the new answer.

If a command fails with exit code 3 and `missingScopes`, the agent tells you which scope to turn on. It cannot widen its own access.


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