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. Detection still runs.
Detection order
Section titled "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
Section titled "Caller override"detect({ agent: true })makes the readeragent.detect({ agent: false })rules an agent out and picksci,terminalorpipeas steps 4, 6 and 7 do. Either wayreasonisoverride. Withagent: true, the agent details come only from signals the steps below would trust: a declaredAI_AGENT, a strong marker, or a weak marker off a TTY and outside CI.
Section titled "AI_AGENT"AI_AGENTWhen
AI_AGENTis set to any value other than an opt-out, the reader isagentandreasonisAI_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,offand 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
Section titled "Strong markers"A strong marker is a variable a harness sets only while a model runs the command, such as
CLAUDECODE,CODEX_THREAD_IDorGEMINI_CLI. A match makes the readeragentwithreasonmarker:<NAME>, such asmarker: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.A CI variable from the table below makes the reader
ci, withreasonCI:<name>, such asCI:github-actions.Weak markers
Section titled "Weak markers"A weak marker can also sit in a person's shell.
CURSOR_TRACE_IDis 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 readeragentwithreasonweak:<NAME>.A bare
AGENTvariable is a weak marker too. When its value is a known harness id, such asAGENT=goose, it names that harness; otherwise the agent id isunknown.Terminal
Section titled "Terminal"When stdout is a TTY, the reader is
terminalandreasonisstdout.isTTY.Everything else is
pipe, withreasonstdout 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.
Calling detect()
Section titled "Calling detect()"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:
{
"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
Section titled "--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
Section titled "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:
export AI_AGENT=0With AI_AGENT=0 and CLAUDECODE=1 in a TTY, the reader is terminal with reason stdout.isTTY.
CI providers
Section titled "CI providers"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.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 to text.
Next: Coding agents covers what an agent gets once it is detected.