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

# Use the CLI in automation

> Use the Algolia CLI in scripts, CI, and agent workflows. Use structured output and DEBUG for troubleshooting, and preview changes before applying them.

This page explains how to use the Algolia CLI in automation,
including non-interactive behavior, structured output, run summaries, and dry runs.

To learn more about interactive use, see [Get started](/doc/tools/cli/get-started).

## Credentials in automation

For environment variables, profiles, command-line flags, precedence, and Crawler keys,
see [Authenticate CLI commands](/doc/tools/cli/authentication).

Automation-focused choices:

* **CI and other servers:**
  Use `ALGOLIA_APPLICATION_ID` and `ALGOLIA_API_KEY` from your platform's secret store so keys don't end up in version control or config files.

* \*\*Local machines, including frequent CLI use by agents:
  Use [profiles](/doc/tools/cli/authentication#profiles) to avoid entering credentials for every command and to keep them out of shell history.

* **One-off commands or temporary overrides:**
  `--application-id` and `--api-key` can target a different Algolia application or API key for one command.
  On native Windows, these flags aren't supported. Use environment variables or profiles instead.
  See [Command-line options](/doc/tools/cli/authentication#command-line-options).

## Non-interactive runs

In non-interactive environments, such as CI/CD, pipes,
and agent workflows, the CLI doesn't prompt for confirmation.
Commands that delete or replace existing data require confirmation.
To run these commands in a non-interactive environment, pass `--confirm`.
Otherwise, the command exits with an error.

## Structured output and command metadata

* **JSON output.** To keep standard output machine-readable,
  use `-o json`, `-o jsonl`, or `-o ndjson` where supported.

* **Command schema.**
  To help agents understand a command without parsing `--help`,
  run `algolia describe <command>`.
  This prints JSON metadata for the command,
  including flags and response fields.

## Exit codes

The Algolia CLI uses the following conventions for exit code.
Use them in scripts and CI to handle command outcomes programmatically.

| Code | Meaning        |
| ---- | -------------- |
| `0`  | Success        |
| `1`  | Error          |
| `2`  | User cancelled |
| `4`  | Auth error     |

## Pipe data into the CLI

To import data from another command or script,
use `-F -` to read from standard input.
Supported commands accept NDJSON or line-delimited JSON,
depending on the command.

```sh Command line icon=square-terminal theme={"system"}
cat records.ndjson | algolia objects import INDEX_NAME -F -
```

## Observability

### Telemetry

By default the CLI sends usage analytics.
Opt out with `ALGOLIA_CLI_TELEMETRY=0`.
For details, see [Telemetry](/doc/tools/cli/telemetry).

### Debug logging

Set `DEBUG=1` (or any non-empty value) to print additional error details to `stderr` for telemetry and update notifier issues.
For more information, see [Telemetry](/doc/tools/cli/telemetry).

## Dry runs

To validate changes without applying them, use `--dry-run`.
To get a structured preview, combine it with `-o json`.

Supported for these commands:

| Command area | Examples                                                               |
| ------------ | ---------------------------------------------------------------------- |
| Application  | `algolia application create`                                           |
| Crawler      | `algolia crawler create`, `pause`, `reindex`, `run`, `test`, `unblock` |
| Dictionary   | `algolia dictionary entries import`                                    |
| Indices      | `algolia indices delete`                                               |
| Objects      | `algolia objects update`, `operations`, `delete`                       |
| Rules        | `algolia rules import`                                                 |
| Synonyms     | `algolia synonyms import`                                              |

```sh Command line icon=square-terminal theme={"system"}
algolia objects update INDEX_NAME -F records.ndjson --dry-run --output json
```

The output typically includes `"dryRun": true` and preview fields.
The exact output depends on the command.

## Use `llms.txt` for agent navigation

Algolia provides `llms.txt` files that help agents discover resources.

* Use [`algolia.com/llms.txt`](https://www.algolia.com/llms.txt) for a high-level map of Algolia, including product areas and key links.
* Use [`algolia.com/doc/llms.txt`](https://www.algolia.com/doc/llms.txt) for documentation-focused navigation, such as API references and developer guides.

## Environment variables (quick reference)

| Variable                     | Effect                                                          |
| ---------------------------- | --------------------------------------------------------------- |
| `ALGOLIA_CLI_TELEMETRY=0`    | Opt out of telemetry                                            |
| `ALGOLIA_NO_UPDATE_NOTIFIER` | Skip update checks when set to any value                        |
| `DEBUG=1`                    | Enable debug output on `stderr` when set to any non-empty value |
