# CI and scripts (/docs/developer-resources/cli/ci-and-scripts)

Browser login is for people. On build servers and in scripts, give the CLI an access token through the environment, turn off prompts, and read structured output.

## Authenticate with an access token

1. **Create an access token**

   In the dashboard, open **Developer → Access Tokens** and create a token with only the permissions your pipeline needs. See [Personal Access Tokens](/docs/dashboard-guide/personal-access-tokens).

2. **Store it as a secret**

   Save the token in your CI provider's secret store, and expose it to the job as `MONIME_ACCESS_TOKEN`.

3. **Name the Space**

   Pass `--space`, or set `MONIME_CORE_SPACE`, so the job does not depend on a saved configuration.

```bash
export MONIME_ACCESS_TOKEN=…   # from your CI provider's secret store
monime space list --space spc-k6Em1Aap25VZ8oWg7ajhxHX3JqF -o json
```

`MONIME_ACCESS_TOKEN` takes the place of stored logins: when it is set, the CLI uses it instead of the Monimeer you logged in as.

> **Warning:** Never commit an access token or print it in build logs. Scope it down to the permissions the job needs, and rotate it if it is exposed.

### Example: GitHub Actions

```yaml title=".github/workflows/monime.yml"
jobs:
  check:
    runs-on: ubuntu-latest
    env:
      MONIME_ACCESS_TOKEN: ${{ secrets.MONIME_ACCESS_TOKEN }}
      MONIME_CORE_SPACE: ${{ vars.MONIME_SPACE_ID }}
      MONIME_NO_UPDATE_NOTIFIER: "1"
    steps:
      - name: Install the Monime CLI
        run: |
          curl -fsSL https://cli.monime.io/install.sh \
            | MONIME_NO_MODIFY_PATH=1 sh
          echo "$HOME/.local/bin" >> "$GITHUB_PATH"
      - name: Check access
        run: monime status -o json
```

## Prompts

The CLI never prompts when it is not attached to a terminal. In a terminal, add `--quiet` (or set `MONIME_CORE_DISABLE_PROMPTS=true`) to use default answers instead; a command that needs an answer and has no default fails rather than waiting.

## Machine-readable output

Commands that print data accept `-o` (`--output`):

| Format  | Use it for                            |
| ------- | ------------------------------------- |
| `table` | Reading in a terminal (the default)   |
| `wide`  | A table with extra columns            |
| `json`  | Scripts and tools such as `jq`        |
| `yaml`  | Config files and human-readable diffs |

```bash
# The IDs of every Space you belong to
monime space list -o json | jq -r '.[].id'

# The ID of the active Space
monime space list -o json | jq -r '.[] | select(.active) | .id'
```

Add `--no-headers` to table output when you pipe it into tools such as `awk` or `cut`.

## Exit codes

| Code  | Meaning                                                                                              |
| ----- | ---------------------------------------------------------------------------------------------------- |
| `0`   | Success                                                                                              |
| `1`   | The command failed                                                                                   |
| `2`   | Usage error, such as an unknown flag or a missing argument                                           |
| `4`   | Authentication is needed: you are not logged in, the login expired, or the access token was rejected |
| `130` | Cancelled, for example with Ctrl+C                                                                   |

```bash
if ! monime status > /dev/null 2>&1; then
  echo "Log in with: monime login" >&2
  exit 1
fi
```

## Useful environment variables

| Variable                      | What it does                                                       |
| ----------------------------- | ------------------------------------------------------------------ |
| `MONIME_ACCESS_TOKEN`         | Authenticate with this access token instead of a stored login      |
| `MONIME_CORE_SPACE`           | The Space to operate in                                            |
| `MONIME_ACTIVE_CONFIG`        | The named configuration to use                                     |
| `MONIME_CORE_DISABLE_PROMPTS` | Set to `true` to turn off prompts                                  |
| `MONIME_CORE_VERBOSITY`       | Log level on stderr: `debug`, `info`, `warning`, `error` or `none` |
| `MONIME_CONFIG_DIR`           | The folder the CLI keeps its configurations in                     |
| `MONIME_NO_UPDATE_NOTIFIER`   | Set to `1` to turn off the new-release notice                      |

Every property also has its own variable; see [Configuration](/docs/developer-resources/cli/configuration#properties).
