GitHub
Skip to content

Readers

How readerly decides whether a coding agent, CI, a person at a terminal or a pipe reads a command's output, step by step, and how to override it.

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.

ReaderWho reads the output
agentA coding agent such as Claude Code, Codex or Gemini CLI
ciA CI job, such as GitHub Actions or GitLab CI
terminalA person at a terminal
pipeAnother 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. Detection still runs.

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

  1. 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.

  2. 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 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.

  3. 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.

  4. A CI variable from the table below makes the reader ci, with reason CI:<name>, such as CI:github-actions.

  5. 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.

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

  7. 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.

import { detect } from "readerly/detect";

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

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:

{
  "reader": "agent",
  "reason": "AI_AGENT",
  "agent": {
    "id": "claude-code",
    "raw": "claude-code",
    "strength": "declared"
  },
  "stdout": {
    "isTTY": false
  },
  "stderr": {
    "isTTY": false
  },
  "stdin": {
    "isTTY": false
  }
}
text
Detection fieldWhat it holds
readeragent, ci, terminal or pipe
reasonThe signal that decided reader: override, AI_AGENT, marker:<NAME>, weak:<NAME>, CI:<name>, stdout.isTTY or stdout not a TTY
agentAn 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, --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.

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:

export AI_AGENT=0

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

ciName(env) in src/ci.ts checks these in order. A bare-name variable counts when it is set and not an opt-out value.

ci.nameVariable
github-actionsGITHUB_ACTIONS
gitlabGITLAB_CI
circleciCIRCLECI
travisTRAVIS
buildkiteBUILDKITE
azure-pipelinesTF_BUILD
bitbucketBITBUCKET_BUILD_NUMBER
jenkinsJENKINS_URL
teamcityTEAMCITY_VERSION
droneDRONE
woodpeckerCI=woodpecker
appveyorAPPVEYOR
vercelVERCEL
netlifyNETLIFY
cloudflare-pagesCF_PAGES
genericCI

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 to text.

Next: Coding agents covers what an agent gets once it is detected.