# Formats

A format is how a command's output is written. readerly has four built in, and a tool can add its own. This page shows the `acme check` example from [`test/golden`](https://github.com/loadsheet/readerly/blob/main/test/golden) in each.

| Format | Picked for | Color | Writes |
| --- | --- | --- | --- |
| `text` | A person at a terminal, CI, a pipe | When the [color rule](https://readerly.loadsheet.dev/guide/color) allows | Findings on stdout; prompts, progress and failures on stderr |
| `agent` | A coding agent | Never | The report and failures on stdout, 8,000 characters by default |
| `json` | `--format json` or `--json` | Never | One document on stdout, also on failure |
| `jsonl` | `--format jsonl` | Never | One JSON record per line on stdout, as entries happen |

## `text`

A verdict line, the diagnostics with a `├▶ ╰▶` tree for `why` and `fix`, then the `next:` lines. Errors print before warnings and infos. At a terminal it shows 50 rows by default and hides the rest behind a `… N more` line; CI, pipes and `--full` get every row. [Diagnostics](https://readerly.loadsheet.dev/guide/diagnostics) covers the layout.

A person at a terminal gets this on stdout, with the prompt `? Apply 2 safe fixes? (y/N) ` on stderr between the warning and the blank line:

```text
✖ 2 errors, 1 warning in 212 files (0.8s)

error ACME001  src/app.ts:14:3  Route handler reads process.env at module scope
├▶ why: The value is fixed at build time
╰▶ fix: Read it inside the handler
error ACME004  src/db.ts:3:1  Top-level await in a server entry
╰▶ fix: Move the call into the plugin setup
warn  ACME010  vite.config.ts:8:5  Alias shadows a workspace package

next: acme explain <code>   (explains one code)
```

## `agent`

The verdict on line 1, one line per diagnostic, no color, no glyphs and no prompts, under a [budget](https://readerly.loadsheet.dev/guide/budget). A coding agent gets:

```text
acme check: failed. 2 errors, 1 warning in 212 files (0.8s).
error ACME001 src/app.ts:14:3 Route handler reads process.env at module scope. fix: Read it inside the handler
error ACME004 src/db.ts:3:1 Top-level await in a server entry. fix: Move the call into the plugin setup
warn ACME010 vite.config.ts:8:5 Alias shadows a workspace package
next: acme check --fix   (applies 2 safe fixes)
next: acme explain <code>   (explains one code)
```

The prompt it couldn't ask became `next: acme check --fix`. [Coding agents](https://readerly.loadsheet.dev/guide/agents) explains each part.

## `json`

One document with `schema`, `status`, `summary`, `diagnostics`, `result` and `next`. `out.log()` lines are left out. `acme check --format json` prints:

```text
{
  "schema": "acme.check/v1",
  "status": "failed",
  "summary": {
    "error": 2,
    "warn": 1,
    "info": 0
  },
  "diagnostics": [
    {
      "severity": "error",
      "code": "ACME001",
      "message": "Route handler reads process.env at module scope",
      "why": "The value is fixed at build time",
      "fix": "Read it inside the handler",
      "file": "src/app.ts",
      "line": 14,
      "column": 3
    },
    {
      "severity": "error",
      "code": "ACME004",
      "message": "Top-level await in a server entry",
      "fix": "Move the call into the plugin setup",
      "file": "src/db.ts",
      "line": 3,
      "column": 1
    },
    {
      "severity": "warn",
      "code": "ACME010",
      "message": "Alias shadows a workspace package",
      "file": "vite.config.ts",
      "line": 8,
      "column": 5
    }
  ],
  "result": {
    "files": 212,
    "durationMs": 840
  },
  "next": [
    {
      "command": "acme check --fix",
      "reason": "applies 2 safe fixes"
    },
    {
      "command": "acme explain <code>",
      "reason": "explains one code"
    }
  ]
}
```

## `jsonl`

A `version` record first, one record per diagnostic, log or next step as the command reports it, and a `result` record last. Every record has a `type`. `acme check --format jsonl` prints:

```text
{"type":"version","schema":"acme.check/v1","tool":"acme@1.2.0"}
{"type":"diagnostic","severity":"error","code":"ACME001","message":"Route handler reads process.env at module scope","why":"The value is fixed at build time","fix":"Read it inside the handler","file":"src/app.ts","line":14,"column":3}
{"type":"diagnostic","severity":"error","code":"ACME004","message":"Top-level await in a server entry","fix":"Move the call into the plugin setup","file":"src/db.ts","line":3,"column":1}
{"type":"diagnostic","severity":"warn","code":"ACME010","message":"Alias shadows a workspace package","file":"vite.config.ts","line":8,"column":5}
{"type":"next","message":"acme check --fix","reason":"applies 2 safe fixes"}
{"type":"next","message":"acme explain <code>","reason":"explains one code"}
{"type":"result","status":"failed","message":"2 errors, 1 warning in 212 files (0.8s)","data":{"files":212,"durationMs":840}}
```

[JSON and JSONL](https://readerly.loadsheet.dev/guide/json) documents every field.

## How readerly picks the format

`resolveProfile()` in [`src/profile.ts`](https://github.com/loadsheet/readerly/blob/main/src/profile.ts) takes the first of these that is set:

1. `--format <name>`.
2. `--json`, the same as `--format json`. When both are given, `--format` wins.
3. The `<TOOL>_FORMAT` environment variable. `formatEnvName(tool)` gives its name: the tool name in upper case, with every character other than a letter or digit turned into `_`. `acme` reads `ACME_FORMAT`, and `vite-doctor` reads `VITE_DOCTOR_FORMAT`.
4. Detection: `agent` when the reader is an agent, `text` for every other reader.

A `<TOOL>_FORMAT` value that is not a format is ignored, and `--verbose` says so:

```text
format: text (ACME_FORMAT=yaml ignored, not one of text, agent, json, jsonl; detected pipe (stdout not a TTY))
```

The format never changes who the reader is. `--format text` under an agent still prints no prompt. See [Readers](https://readerly.loadsheet.dev/guide/readers).

## A bad `--format`

An unknown `--format` value is a usage failure with exit code 2. readerly sets the bad flag aside, picks the format from the other flags and detection, and prints the failure in that format. In `text` it goes to stderr:

```text
✖ --format yaml is not a format. Use one of: text, agent, json, jsonl.
╰▶ fix: Pass --format with one of: text, agent, json, jsonl.
```

`--format` with no value prints the same failure, starting with `--format needs a value.`. Under an agent, the failure is the `agent` report on stdout, and with `--json` it is a JSON document with `"status": "failed"`.

## Your own formats

A tool adds a format with `formats`, and renders it with `renderers`:

```ts [check.ts]
const out = createOut({
  tool: "acme",
  command: "check",
  argv,
  formats: ["count"],
  renderers: {
    count: { render: (run) => ({ stdout: `${run.counts.error}\n` }) },
  },
});
```

`acme check --format count` and `ACME_FORMAT=count acme check` both print the error count. The new name joins the list in the `--format` error, as in `Use one of: text, agent, json, jsonl, count.`. A format in `formats` without a renderer makes `createOut` throw `No renderer for format count.` when that format is picked. [Custom renderers](https://readerly.loadsheet.dev/guide/renderers) covers `renderers` and `render`.

## GitHub annotations are not a format

On GitHub Actions, the `text` format also writes `::error` and `::warning` workflow commands to stderr, and the runner shows them on the diff. They sit next to `text`, not in place of it, and no flag selects them. See [GitHub Actions](https://readerly.loadsheet.dev/integrations/github-actions).

<!-- vitehub-docs:section-links -->
## In this section

- [Introduction](https://readerly.loadsheet.dev/raw/guide.md)
- [Installation](https://readerly.loadsheet.dev/raw/guide/installation.md)
- [Readers](https://readerly.loadsheet.dev/raw/guide/readers.md)
- [Coding agents](https://readerly.loadsheet.dev/raw/guide/agents.md)
- [Formats](https://readerly.loadsheet.dev/raw/guide/formats.md) (this page)
- [Shared flags](https://readerly.loadsheet.dev/raw/guide/flags.md)
- [Color and glyphs](https://readerly.loadsheet.dev/raw/guide/color.md)
- [Diagnostics](https://readerly.loadsheet.dev/raw/guide/diagnostics.md)
- [Budget](https://readerly.loadsheet.dev/raw/guide/budget.md)
- [Prompts and input](https://readerly.loadsheet.dev/raw/guide/prompts.md)
- [Failures and exit codes](https://readerly.loadsheet.dev/raw/guide/failures.md)
- [JSON and JSONL](https://readerly.loadsheet.dev/raw/guide/json.md)
- [Custom renderers](https://readerly.loadsheet.dev/raw/guide/renderers.md)
- [API](https://readerly.loadsheet.dev/raw/guide/api.md)

Next: [Shared flags](https://readerly.loadsheet.dev/raw/guide/flags.md)

All pages: [llms.txt](https://readerly.loadsheet.dev/llms.txt)
