# Using Arena from a coding agent

Set up Claude Code, Cursor, Codex or another coding agent so it can upload data, write a manifest and submit experiments with the `arena` CLI.

## Prerequisites

- An Arena account and a CLI API key. See [Install and sign in](install.md#sign-in-with-an-api-key).

## Give the coding agent the CLI and a key

The coding agent runs commands in a terminal with no browser, so it can’t use `arena login`. Install the CLI with `uv tool install agilerl` and give the coding agent your key through `ARENA_API_KEY`. `uv tool` gives the CLI its own environment, so it doesn’t replace the `agilerl` 2.x RL framework if the project uses it.

```bash
uv tool install agilerl
export ARENA_API_KEY='arena_pat_...'
```

Put the export in the shell profile or `.env` file your coding agent’s terminal loads, not in a file you commit. The key acts as you, so anything the coding agent submits is billed to your organization.

`arena experiments submit` and `arena experiments resume` print the price and ask you to confirm before billing starts. With no terminal attached, they refuse to go on unless you pass `--yes`. Leave `--yes` out of your instructions if you want to approve each run yourself, and have the coding agent run `--dry-run` first to show you the price.

## Get JSON output

Put `--json` before the command name to get one JSON document on stdout with every field. Progress, logs and errors go to stderr, so the coding agent can parse stdout directly:

```bash
arena --json experiments list --project gsm8k
arena --json experiments status gsm8k-cispo
```

`ARENA_JSON=1` turns it on for every command. `arena agent run`, `arena agent generate` and the `arena agent sessions` commands stream text and ignore it. `arena --json experiments logs` prints one object per log line, then one with the final status and failure reason.

A few commands also take `--json` after the command name:

- `arena manifest validate run.yaml --json` prints the verdict and exits 0 whether the manifest is valid or not. A non-zero exit means the check itself failed.
- `arena memory estimate run.yaml --gpu h100-80 --json` and `arena memory solve max_model_len run.yaml --gpu h100-80 --json` print the full GPU memory result. Without `--num-gpus`, Arena sizes the run at the GPU count a submit on that GPU type would pick; pass `--num-gpus` to check another count.

## Point the coding agent at these docs

Every page on this site has a Markdown copy at the same address plus `.md`, for example `https://docs.arena.agilerl.com/cli/install.md`. Two files at the site root collect them:

- [`llms.txt`](https://docs.arena.agilerl.com/llms.txt) lists every page with a one-line description. Give the coding agent this first so it can fetch only the pages it needs.
- [`llms-full.txt`](https://docs.arena.agilerl.com/llms-full.txt) is the whole site in one file, for coding agents that can hold it.

The CLI also documents itself. `arena <command> --help` prints every flag, and `arena manifest schema` prints the manifest’s JSON Schema.

## Add Arena to your project instructions

Paste this into the project’s `AGENTS.md`, `CLAUDE.md` or Cursor rules file and edit the project name:

```markdown
## Arena

We train models on Arena with the `arena` CLI from the `agilerl` package.

- Install: `uv tool install agilerl`, which keeps the CLI out of the project's
  environment. Upgrade with `uv tool upgrade agilerl`. Auth comes from the
  `ARENA_API_KEY` environment variable, which is already set. Never print, echo,
  log or commit its value, and never pass it on the command line. Do not run
  `arena login`.
- Docs: fetch https://docs.arena.agilerl.com/llms.txt, then the `.md` page you need.
  Use `arena <command> --help` for flags.
- Put `--json` before the command name when you need to read the output
  (`arena --json experiments list`).
- Our project is `my-project`. Pass `--project my-project` to commands that take it.
- To start a run, begin from Arena's default manifest instead of writing one:
  `arena manifest template <ALGORITHM> --model <MODEL> --dataset <DATASET> > run.yaml`
- Validate before every submit and fix every error it reports:
  `arena manifest validate run.yaml`
- Show me the price with `arena experiments submit run.yaml --dry-run` and wait
  for my OK before submitting for real.
- Follow a run with `arena experiments status <NAME>` and `arena experiments logs <NAME>`.
```

## Related

- [Command reference](command-reference.md)
- [Run spec and manifest schema](manifest-schema.md)
- [Train a model](../guides/train-a-model.md)
