# Readers

readerly sorts every run into one of four readers. This page lists the checks that decide which one, in order, and the fields `detect()` returns.

| `Reader` | Who reads the output |
| --- | --- |
| `agent` | A coding agent such as Claude Code, Codex or Gemini CLI |
| `ci` | A CI job, such as GitHub Actions or GitLab CI |
| `terminal` | A person at a terminal |
| `pipe` | Another program, a file or a pipe |

A program that asks for JSON is a fifth reader in practice, but not a fifth `Reader` value. It passes `--format json` or `--json`, which picks the [format](https://readerly.loadsheet.dev/guide/formats). Detection still runs.

## Detection order

`detect()` checks these in order and stops at the first match. The `reason` column is the string it puts in `Detection.reason`.

### Caller override

`detect({ agent: true })` makes the reader `agent`. `detect({ agent: false })` rules an agent out and picks `ci`, `terminal` or `pipe` as steps 4, 6 and 7 do. Either way `reason` is `override`. With `agent: true`, the agent details come only from signals the steps below would trust: a declared `AI_AGENT`, a strong marker, or a weak marker off a TTY and outside CI.

### `AI_AGENT`

When `AI_AGENT` is set to any value other than an opt-out, the reader is `agent` and `reason` is `AI_AGENT`. The value names the agent: `claude-code`, `codex_0-172-0_agent`, or your own name. [Coding agents](https://readerly.loadsheet.dev/guide/agents#declaring-an-agent) has the parsing rules.

The opt-out values are `0`, `false`, `no`, `off` and the empty string, trimmed and in any case. They skip every marker in steps 3 and 5, so the run goes straight to CI, terminal or pipe.

### Strong markers

A strong marker is a variable a harness sets only while a model runs the command, such as `CLAUDECODE`, `CODEX_THREAD_ID` or `GEMINI_CLI`. A match makes the reader `agent` with `reason` `marker:<NAME>`, such as `marker:CODEX_THREAD_ID`. Strong markers win in CI and in a real TTY: Gemini CLI and Cline run commands in a TTY, and their output still goes to an agent.

### CI

A CI variable from the [table below](https://readerly.loadsheet.dev/guide/readers#ci-providers) makes the reader `ci`, with `reason` `CI:<name>`, such as `CI:github-actions`.

### Weak markers

A weak marker can also sit in a person's shell. `CURSOR_TRACE_ID` is set in a person's Cursor terminal as well as in Cursor's agent. readerly counts a weak marker only when stdout is not a TTY, and step 4 has already ruled out CI. A match makes the reader `agent` with `reason` `weak:<NAME>`.

A bare `AGENT` variable is a weak marker too. When its value is a known harness id, such as `AGENT=goose`, it names that harness; otherwise the agent id is `unknown`.

### Terminal

When stdout is a TTY, the reader is `terminal` and `reason` is `stdout.isTTY`.

### Pipe

Everything else is `pipe`, with `reason` `stdout not a TTY`.

Strong markers are checked for every known harness before any weak marker. That is how Codex running inside a Cursor terminal is reported as Codex and not Cursor. The markers for each harness are in [Coding agents](https://readerly.loadsheet.dev/guide/agents#known-harnesses).

## Calling `detect()`

```ts [who.ts]
import { detect } from "readerly/detect";

const detection = detect();
console.log(detection.reader, detection.reason);
```

`detect()` is synchronous and writes nothing. It reads `process.env` and the TTY state of `process.stdout`, `stderr` and `stdin` on every call, never at import, so a process that changes its env between runs gets a fresh answer. Pass `env`, `stdout`, `stderr` or `stdin` to read those instead of the real process.

Under `AI_AGENT=claude-code`, with stdout piped, `detect()` returns:

```text
{
  "reader": "agent",
  "reason": "AI_AGENT",
  "agent": {
    "id": "claude-code",
    "raw": "claude-code",
    "strength": "declared"
  },
  "stdout": {
    "isTTY": false
  },
  "stderr": {
    "isTTY": false
  },
  "stdin": {
    "isTTY": false
  }
}
```

| `Detection` field | What it holds |
| --- | --- |
| `reader` | `agent`, `ci`, `terminal` or `pipe` |
| `reason` | The signal that decided `reader`: `override`, `AI_AGENT`, `marker:<NAME>`, `weak:<NAME>`, `CI:<name>`, `stdout.isTTY` or `stdout not a TTY` |
| `agent` | An `AgentInfo` when an agent was found: `id`, `strength`, and `raw`, `version`, `mode`, `sessionId`, `effort` and `wrapper` when known |
| `ci` | `{ name }` when a CI variable is set, even when the reader is `agent` |
| `stdout` | `{ isTTY, columns? }` |
| `stderr` | `{ isTTY }` |
| `stdin` | `{ isTTY }` |

`createOut` calls `detect()` with its `io`. Pass `detection` to `createOut` or `resolveProfile` to use your own and skip detection, as tests do.

## `--format` never skips detection

`--format`, `--json` and `<TOOL>_FORMAT` pick the format, but readerly still detects the reader. Under Gemini CLI in a real TTY, `acme check --format text` prints `text`, yet `profile.interactive` is `false` because the reader is `agent`, and `profile.budget` stays at 8,000 characters. An agent's shell never gets a prompt it can't answer.

## Opting out with `AI_AGENT=0`

An agent can leave its variables in a shell a person later uses, such as a tmux session the agent opened. `CLAUDECODE=1` is still set there, and every command would print for an agent. Set `AI_AGENT=0` in that shell:

```sh
export AI_AGENT=0
```

With `AI_AGENT=0` and `CLAUDECODE=1` in a TTY, the reader is `terminal` with `reason` `stdout.isTTY`.

## CI providers

`ciName(env)` in [`src/ci.ts`](https://github.com/loadsheet/readerly/blob/main/src/ci.ts) checks these in order. A bare-name variable counts when it is set and not an opt-out value.

| `ci.name` | Variable |
| --- | --- |
| `github-actions` | `GITHUB_ACTIONS` |
| `gitlab` | `GITLAB_CI` |
| `circleci` | `CIRCLECI` |
| `travis` | `TRAVIS` |
| `buildkite` | `BUILDKITE` |
| `azure-pipelines` | `TF_BUILD` |
| `bitbucket` | `BITBUCKET_BUILD_NUMBER` |
| `jenkins` | `JENKINS_URL` |
| `teamcity` | `TEAMCITY_VERSION` |
| `drone` | `DRONE` |
| `woodpecker` | `CI=woodpecker` |
| `appveyor` | `APPVEYOR` |
| `vercel` | `VERCEL` |
| `netlify` | `NETLIFY` |
| `cloudflare-pages` | `CF_PAGES` |
| `generic` | `CI` |

`CI=0`, `false`, `no` or `off` turns CI detection off, even with `GITHUB_ACTIONS` set. `CODEX_CI` is a Codex marker, not CI. Only `github-actions` changes the output: it adds [annotations](https://readerly.loadsheet.dev/integrations/github-actions) to `text`.

Next: [Coding agents](https://readerly.loadsheet.dev/guide/agents) covers what an agent gets once it is detected.

<!-- 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) (this page)
- [Coding agents](https://readerly.loadsheet.dev/raw/guide/agents.md)
- [Formats](https://readerly.loadsheet.dev/raw/guide/formats.md)
- [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: [Coding agents](https://readerly.loadsheet.dev/raw/guide/agents.md)

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