# Coding agents

When the reader is a coding agent, readerly prints the `agent` format. This page covers what that output holds and how readerly knows which agent is running.

## What an agent gets

The `acme check` example from [`test/golden`](https://github.com/loadsheet/readerly/blob/main/test/golden), as a coding agent gets it:

```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)
```

- **No color and no glyphs.** No escape codes, no `✖`, no tree. Each diagnostic is one line, with its `fix` on the same line. `why` and `docs` appear only with `--full`.
- **The verdict on line 1.** Hosts cut the middle of long output, so the first line says whether the run failed and what it counted.
- **No prompts.** An agent can't answer one. When a prompt has a default, readerly uses it and adds a `next:` line with the flag that changes it, here `acme check --fix`. When it has none, `out.confirm` throws an `action_required` failure that names the flag, and `out.fail()` prints it with exit code 2. See [Prompts and input](https://readerly.loadsheet.dev/guide/prompts).
- **A budget of 8,000 characters.** That is under Claude Code's 30,000-character Bash output limit and Codex's 10,000-token cap. readerly keeps or drops whole lines: `next:` lines first, then errors, warnings, infos and logs. The last line names what it dropped and how to get it back:

```text
hidden: 23 warn. rerun: acme check --full, or acme check --format json
```

`--max-chars <n>` sets another budget and `--full` removes it. [Budget](https://readerly.loadsheet.dev/guide/budget) has the details.

Failures go to stdout in this format too, so an agent sees the error, the fix and the command to rerun in one read.

## Known harnesses

The harness registry in [`src/registry.ts`](https://github.com/loadsheet/readerly/blob/main/src/registry.ts) lists each agent readerly knows. A bare marker name counts when the variable is set and not `0`, `false`, `no`, `off` or empty; `NAME=value` must match exactly.

| `id` | Strong markers | Weak markers | `sessionId` from | Also reads |
| --- | --- | --- | --- | --- |
| `claude-code` | `CLAUDECODE` | | `CLAUDE_CODE_SESSION_ID` | `CLAUDE_EFFORT` as `effort` |
| `codex` | `CODEX_THREAD_ID`, `CODEX_SANDBOX`, `CODEX_CI` | | `CODEX_THREAD_ID` | `CODEX_VERSION` as `version` |
| `gemini`\* | `GEMINI_CLI` | | | |
| `cline`\* | `CLINE_ACTIVE` | | | |
| `opencode` | `OPENCODE` | | `OPENCODE_SESSION_ID` | |
| `cursor` | `CURSOR_AGENT`, `CURSOR_EXTENSION_HOST_ROLE=agent-exec` | `CURSOR_TRACE_ID` | `CURSOR_CONVERSATION_ID` | |
| `augment`\* | `AUGMENT_AGENT` | | | |
| `amp`\* | `AMP_CURRENT_THREAD_ID` | | `AMP_CURRENT_THREAD_ID` | |
| `copilot`\* | | | | |
| `grok`\* | | `GROK_SESSION_ID`, `GROK_AGENT_ID` | `GROK_SESSION_ID` | |
| `kiro`\* | | `TERM_PROGRAM=kiro` | | |
| `goose`\* | | `GOOSE_TERMINAL` | | |
| `replit`\* | | `REPL_ID` | | |
| `windsurf`\* | | `WINDSURF_CASCADE_TERMINAL` | | |
| `pi`\* | | | | |
| `t3-code` | | `T3CODE_THREAD_ID` | `T3CODE_THREAD_ID` | |

\* Markers taken from the harness's source or docs, not from a live run.

`copilot` and `pi` have no marker. readerly finds them only through `AI_AGENT`, such as `AI_AGENT=github_copilot_vscode_agent`. A bare `AGENT` variable is one more weak marker for any harness: `AGENT=goose` reports `goose`, and `AGENT=1` reports `unknown`.

When `T3CODE_THREAD_ID` is set and the agent is not T3 Code itself, `AgentInfo.wrapper` is `{ id: "t3-code", threadId }`: a Claude Code run inside T3 Code reports both.

## Declared, strong and weak

`AgentInfo.strength` says how readerly found the agent.

| `strength` | Source | Trusted |
| --- | --- | --- |
| `declared` | `AI_AGENT` | Always. It is checked before any marker. |
| `strong` | A variable the harness sets only while a model runs the command | Always, also in a TTY and in CI |
| `weak` | A variable that can also sit in a person's shell | Only when stdout is not a TTY and the run is not in CI |

The full order is in [Readers](https://readerly.loadsheet.dev/guide/readers#detection-order).

## Declaring an agent

A harness, or a wrapper script around one, declares itself by setting `AI_AGENT`. readerly reads the value like this:

1. A value that doesn't match `^[A-Za-z0-9_.-]{1,64}$` gives the id `unknown`.
2. readerly lowercases it and splits it on `_`. A last segment of `agent` or `harness` becomes `mode`.
3. A version segment of digits joined by `-` or `.` becomes `version`, with `-` turned into `.`.
4. The id is the longest registry prefix followed by `_`, `-` or the end of the value. Otherwise it is the rest of the value; `1`, `true`, `yes` and `on` give `unknown`.

| `AI_AGENT` | `id` | `version` | `mode` |
| --- | --- | --- | --- |
| `claude-code_2-1-332_agent` | `claude-code` | `2.1.332` | `agent` |
| `codex` | `codex` | | |
| `opencode_1.4.2` | `opencode` | `1.4.2` | |
| `github_copilot_vscode_agent` | `copilot` | | `agent` |
| `new-tool_3-0_agent` | `new-tool` | `3.0` | `agent` |
| `1` | `unknown` | | |

`AgentInfo.raw` keeps the value as given. `AI_AGENT=0` declares that no agent runs; see [Readers](https://readerly.loadsheet.dev/guide/readers).

## Agents in CI

A coding agent can run inside a CI job, such as Claude Code in GitHub Actions. A declared or strong agent wins over CI: the reader is `agent`, and `Detection.ci` still names the provider. A weak marker never wins in CI, so `CURSOR_TRACE_ID` in a GitHub Actions job leaves the reader `ci`.

An agent in CI gets the `agent` format and no GitHub annotations. Annotations go only with the `text` format, for the `ci` reader on GitHub Actions. 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) (this page)
- [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: [Formats](https://readerly.loadsheet.dev/raw/guide/formats.md)

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