# atrix-agent: guide for coding agents

Audience: a coding agent (Claude Code, Cursor, Codex, or similar) asked to convert a lab's annotation files for iEEG/EEG recordings into a standard format. This page is the machine-readable version of https://www.atrix.bio/agent. Source of truth: the `atrix-agent` npm package (`agent/` in the Atrix repository).

`atrix-agent` is a command-line tool. It scans one folder, pairs each annotation file with its recording, and writes NWB, BIDS, EDF+, CSV or JSON copies of the labels into an output folder. Conversion runs on the computer where it is invoked. Source files are never modified.

## Install

- Requires Node 20 or newer.
- No install: `npx atrix-agent convert <folder>`
- Global install: `npm install -g atrix-agent`, then the command is `atrix`.

The examples below use `atrix`; with `npx`, replace `atrix` by `npx atrix-agent`.

## Command

```
atrix convert <folder> [--to nwb|bids|edf|csv|json] [--dry-run] [--no-ai] [--out <dir>] [--model <id>] [--tz <zone>]
atrix --help
```

`convert` is the only command. `<folder>` is scanned recursively, so pass the study folder, not a home directory.

| Flag | Meaning | Default |
|---|---|---|
| `--to` | Output format: `nwb`, `bids`, `edf`, `csv`, `json` | `nwb` |
| `--dry-run` | Plan and print the summary table, write nothing. Also prints the file-name alias table (see Privacy). | off |
| `--no-ai` | Deterministic heuristics only: BIDS names and standard column names. No network. | off |
| `--out <dir>` | Output folder | `<folder>/atrix-out` |
| `--model <id>` | Model: `anthropic/<id>`, `openai/<id>`, or a bare id for whichever provider's key is set. Also `ATRIX_MODEL`. | per provider, below |
| `--tz <zone>` | IANA zone the recorder's clock was in, e.g. `America/New_York`. Also `ATRIX_TZ`. | this machine's zone |
| `--help`, `-h` | Print usage, exit 0 | |

Unknown flags are an error (exit 1).

## Environment variables

| Variable | Effect |
|---|---|
| `ANTHROPIC_API_KEY` | AI planning through the Anthropic API. Default model `claude-opus-5-5`. |
| `OPENAI_API_KEY` | AI planning through the OpenAI API. Default model `gpt-5-mini`. |
| `AI_GATEWAY_API_KEY` | AI planning through Vercel AI Gateway, any `provider/model` id. Default model `openai/gpt-5-mini`. |
| `ATRIX_MODEL` | Same as `--model`. The flag wins. |
| `ATRIX_TZ` | Same as `--tz`. The flag wins. |

Provider precedence when more than one key is set: Anthropic, then OpenAI, then AI Gateway. `--model anthropic/...` or `--model openai/...` picks a provider explicitly; if that provider's key is missing but `AI_GATEWAY_API_KEY` is set, the request goes through the gateway with the same id; otherwise it is an error (exit 1).

With no key set and without `--no-ai`, the tool prints `No AI key set: using offline heuristics (same as --no-ai). Set one of ANTHROPIC_API_KEY, OPENAI_API_KEY or AI_GATEWAY_API_KEY (Vercel AI Gateway).` and continues offline. This is not a failure.

## Recommended sequence

1. Offline dry run. No network, nothing written. Shows what was found, how it would be paired, and what would be skipped.

   ```sh
   atrix convert ./study-data --dry-run --no-ai
   ```

2. If rows are `skipped` for non-standard columns or pairing, and a key is available, dry run with AI. Still writes nothing. Prints the alias table so the person can check what the model would see.

   ```sh
   export ANTHROPIC_API_KEY=...   # or OPENAI_API_KEY
   atrix convert ./study-data --dry-run
   ```

3. Convert.

   ```sh
   atrix convert ./study-data --to bids
   ```

4. Read the summary table (below). Report `failed` and `skipped` rows to the person with their reasons.

## What the scan finds

Walks `<folder>` recursively. Skips names starting with `.`, `node_modules`, and `atrix-out` at the top of `<folder>`. Unreadable files are skipped, not fatal.

Recordings (header only; no signal data is read):

- EDF, EDF+, BDF, BDF+ (any extension; detected by header)
- BrainVision `.vhdr`, with the `.vmrk` next to it for start time
- NWB (HDF5). `session_start_time` is read only when the file is 200 MB or smaller.

Annotation files:

- `*_events.tsv` (BIDS)
- other `.tsv` only when it has an `onset` column (case-insensitive); `channels.tsv`, `participants.tsv`, `scans.tsv` are therefore not treated as annotations
- `.csv` (any)
- `.json`: an array, or an object with an `events` array, whose first row has an `onset` key; an optional top-level `recording_started_at` is used as the file's own clock
- EDF+ annotations: a file with only an annotations signal, and annotations embedded in an EDF+ recording (recording 200 MB or smaller)

Tables over 50 MB are ignored.

Header fields read: format, start time, duration, sample rate, channel names, BIDS entities from the path. Not read at all: EDF/BDF patient and recording identification fields, BrainVision comment and author lines, NWB subject, identifier and notes.

## How files are paired and labelled (offline rules)

For each annotation file, the first rule that gives exactly one recording wins:

1. annotations embedded in a recording: that recording
2. BIDS entities: at least two of `sub`, `ses`, `task`, `run` present on both and all equal
3. same file stem after removing an `_events`, `_annotations`, `_labels`, `_markers`, `_ieeg`, `_eeg` or `_meg` suffix
4. the annotation file's own start time (EDF+ header or JSON `recording_started_at`) within 12 hours of a recording start: the nearest
5. the only recording in the same folder
6. the only recording found anywhere
7. otherwise none; reason `ambiguous: several recordings, no match` or `no recordings found`

Subject, session and task come from BIDS entities in the file name, then `sub-*`/`ses-*` folder names, then the paired recording; defaults `01`, `01`, `task`. Labels are reduced to alphanumerics.

Column mapping: standard fields are `onset`, `duration`, `trial_type`, `value`, `trial_number`, `note`. A column matches a field ignoring case, spacing and a unit in parentheses or brackets (`Onset (s)` is `onset`, `Trial Type` is `trial_type`). A table without an onset column is skipped with `no onset column (columns: ...)`. JSON files are read with their keys as they are.

With AI on, the model receives this plan and may correct pairings, labels and column mappings, including non-standard column names and time columns in other units.

## AI mode

The model gets the scan metadata (file names aliased) and the offline plan, and works through five tools: `list_files`, `read_header`, `preview_table` (at most 10 rows, cells clipped to 80 characters), `convert` (runs locally, returns label count and output paths), and `ask_user`. At most 40 tool steps per run. The conversion itself never runs inside the model.

`ask_user` prints a question in the terminal and waits for a typed answer only when stdin is a TTY. When stdin is not a TTY (the usual case for a coding agent's shell tool), the model is told `No answer: not an interactive terminal` and decides on its own, noting it in the summary. A run therefore never blocks on input unless a human is at the terminal. If real ambiguity is expected (several candidate recordings, files with no BIDS entities), have the person run the command in their own terminal.

## Output

Default output folder: `<folder>/atrix-out/` (`--out` overrides). The tool refuses to write outside it. Sources are only read.

| `--to` | Files written |
|---|---|
| `nwb` | `sub-<S>_ses-<E>_task-<T>_labels.nwb` per annotation file |
| `edf` | `sub-<S>_ses-<E>_task-<T>_events.edf` per annotation file (EDF+ annotations only, no signal) |
| `csv` | `sub-<S>_ses-<E>_task-<T>_events.csv` per annotation file |
| `json` | `sub-<S>_ses-<E>_task-<T>_events.json` per annotation file |
| `bids` | one dataset under `atrix-out/bids/`: `dataset_description.json`, `participants.tsv`, `participants.json`, `README.md`, `.bidsignore`, and per session `sub-<S>/ses-<E>/ieeg/sub-<S>_ses-<E>_task-<T>_events.tsv` with `_events.json` and `_ieeg.json` sidecars, plus non-BIDS extras listed in `.bidsignore` |

Two outputs with the same name in one run get `_2`, `_3`, ... before the extension. In BIDS, a second session with the same `sub-`/`ses-` becomes `ses-<E>b`, then `c`. The BIDS dataset holds labels only; the README it writes says to add the recordings to each `sub-*/ses-*/ieeg/` folder.

Session start: the paired recording's start (header or `scans.tsv`); otherwise the annotation file's own start; otherwise unknown (`1970-01-01`). When both the recording and the annotation file carry a clock and they are at most 12 hours apart, onsets are shifted by the difference; a larger gap is reported and not shifted. Each converted session's task description is set to `Converted locally by atrix-agent from <source format> (<annotation path>)`.

## Timezone rule

EDF/BDF and BrainVision headers store local wall-clock time with no zone. The zone is taken from, in order:

1. a BIDS `*_scans.tsv` in the recording's session or subject folder with an `acq_time` for that file (ISO 8601; with `Z` or an offset it is exact; without one it is local time read in the zone below)
2. `--tz <IANA zone>` or `ATRIX_TZ`
3. this machine's zone; the output then carries the line `Note: EDF/BrainVision header times were read in this machine's zone (<zone>); pass --tz <IANA zone> or set ATRIX_TZ if the recording was made elsewhere.`

NWB files carry a zoned `session_start_time`; the rule does not apply to them. Zone data comes from the platform's `Intl`; nothing is downloaded. Pass `--tz` whenever the recording was made in a different zone from the machine running the conversion.

## What stdout looks like

In order (illustrative paths; column widths vary):

```
Scanned /abs/path/study-data: 2 recording(s), 2 annotation file(s).
Note: EDF/BrainVision header times were read in this machine's zone (Europe/Berlin); pass --tz ...   (only without --tz/ATRIX_TZ)

File names as the AI model would see them (dry run):                                               (only with --dry-run)
File                                               Alias
-------------------------------------------------  --------------------------------
patients/DOE_JANE_MRN4471902_2026-03-12_rest.csv   n1/n2_n3_n4_2026-03-12_n5.csv
patients/DOE_JANE_MRN4471902_2026-03-12_rest.edf   n1/n2_n3_n4_2026-03-12_n5.edf

Privacy: only header metadata, column names and up to 10 sample rows per table are sent to the AI model; ...   (AI on)
Planning with claude-opus-5-5 (Anthropic API)...                                                     (AI on)
  agent: <annotation> -> <recording>  sub-01 ses-01 task-rest  [Time (ms)->onset]                   (one per convert call, AI on)

Agent: <at most three sentences from the model>                                                     (AI on)

Annotation                 Recording                  Session                      Labels  Output                                      Status
-------------------------  -------------------------  ---------------------------  ------  ------------------------------------------  --------------------
sub-01/ses-01/..._events.tsv  sub-01/ses-01/..._ieeg.edf  sub-01 ses-01 task-rest   142     atrix-out/sub-01_ses-01_task-rest_labels.nwb  ok (recording start)

1/2 converted to NWB in /abs/path/study-data/atrix-out.
```

If no annotation files are found, the output after the `Scanned` line is `No annotation files found.` and the run ends (exit 0).

Summary table columns: `Annotation`, `Recording`, `Session`, `Labels`, `Output` (`Would write` in a dry run), `Status`. Columns are padded and separated by two spaces; the second row is dashes. `-` marks an empty cell. `Status` is one of:

- `ok (<how the session start was set>)`, for example `ok (recording start)`, `ok (recording start, shifted 3s)`, `ok (recording start; clocks 90000s apart, not shifted)`, `ok (annotation file's own start)`, `ok (unknown start (1970-01-01))`
- `failed: <error>`, for example `failed: no labels in the file`
- `skipped: <reason>`, for example `skipped: no onset column (columns: Time, Event)` or `skipped: not converted by the agent`

Last line: `<ok>/<total> converted to <FORMAT> in <output folder>.`, or `<ok>/<total> converted to <FORMAT> (dry run, nothing written).`

## Exit codes

- `0`: the run completed, including runs where some rows are `failed` or `skipped`, runs that found no annotation files, and runs that fell back to offline mode for lack of a key. Read the `Status` column; do not rely on the exit code for per-file success.
- `1`: usage error (no `convert`, no folder, unknown flag; usage is printed), or an error line `atrix: <message>` on stderr. Messages include `Not a folder: <folder>`, `--to must be one of bids, nwb, edf, csv, json`, `--tz must be an IANA zone name such as America/New_York or Europe/Berlin (got "...")`, `--model <id> needs <KEY> (or AI_GATEWAY_API_KEY) in the environment.`, and provider errors (invalid key, network).
- `0` with `--help`.

## Privacy

Enforced in the tool (`src/privacy.ts`, `src/alias.ts`), not by instructions to the model.

Sent to the model when AI is on, under the lab's own API key and provider terms:

- aliased file and folder names
- header metadata: format, start time, duration, sample rate, channel names (first 64), BIDS entities
- column names and row counts
- at most 10 sample rows per table, cells clipped to 80 characters

Never sent: signal data, whole files, real file names, EDF/BDF patient and recording ID fields, BrainVision comment lines, NWB subject or identifier fields. Recordings and EDF+ annotation files cannot be previewed at all. A guard rejects any payload with more than 10 table rows or more than 24,000 characters. With `--no-ai`, or with no key, nothing is sent anywhere.

Alias rule: a path is aliased segment by segment. Kept in the clear: folder depth, delimiters (`_ - .` and spaces), the extension, BIDS entities (`sub-`, `ses-`, `task-`, `run-`, `acq-`), dates (`2026-03-12`, `20260312`, `12-MAR-2026`), and the words `events`, `annotation(s)`, `label(s)`, `marker(s)`, `ieeg`, `eeg`, `meg`, `channels`, `scans`. Every other token becomes `n<K>`, the same alias for the same token everywhere in the run. Example: `patients/DOE_JANE_MRN4471902_2026-03-12_rest.csv` is sent as `n1/n2_n3_n4_2026-03-12_n5.csv`. The map lives in memory for the run only; the person at the terminal sees real names in questions and in the summary table. `--dry-run` prints the full alias table.

Caveat to pass on: sample rows are sent as they are. A free-text column (notes, comments) that contains names in its first 10 rows would reach the model. Options: `--no-ai`, or keep such text out of the first rows.

## Links

- Human page: https://www.atrix.bio/agent
- Package: https://www.npmjs.com/package/atrix-agent
- Site index for agents: https://www.atrix.bio/llms.txt
