Problem
Scripts and CLIs can detect CI environments via the CI=true convention, enabling non-interactive behavior and CI-appropriate output. There's no equivalent for AI coding agents.
When agents execute commands, scripts have no way to know they're running in an agent context. This matters because:
- Error output — Agents benefit from structured errors (JSON with actionable suggestions) rather than human-friendly prose
- Verbosity — Agents can process more context; humans need scannable output
- Interactivity — Like CI, agents can't respond to prompts, but the existing
CI=true doesn't capture the full picture
Use cases
# Script adapts output format
if [[ -n "${AGENT:-}" ]]; then
echo '{"error": "config_missing", "suggestion": "run ./setup.sh", "docs": "https://..."}'
exit 1
else
echo "Error: Config file not found. Run ./setup.sh to initialize."
exit 1
fi
# Test runner provides richer failure context for agents
if [[ -n "${AGENT:-}" ]]; then
pytest --tb=long --verbose "$@"
else
pytest "$@"
fi
Proposal
Agents set an environment variable when executing commands:
| Variable |
Value |
Meaning |
AGENT |
[agent-name], 1, or true |
Running under an AI coding agent |
Adoption
AGENT variable (this proposal)
Tool-specific variables (status quo)
Consumer-side detection
Tools already adapting behavior based on agent detection:
| Project |
How |
Ref |
| Bun |
isAIAgent() checks AGENT=1, CLAUDECODE, REPL_ID. Suppresses passing tests, shows only failures. |
PR #21135 |
| Vercel |
@vercel/detect-agent checks AI_AGENT, then falls back to 9+ tool-specific vars. Sets deployment actor. |
PR #13736 |
Both had to build detection matrices because no single standard exists.
Precedent
CI=true — Set by GitHub Actions, GitLab CI, CircleCI, Travis, Jenkins, etc.
NO_COLOR=1 — Disables color output across CLIs (no-color.org)
TERM=dumb — Signals limited terminal capabilities
- InfoQ: Patterns for AI Agent Driven CLIs — Recommends
--no-interactive flags and structured output, but no env var convention
The CI convention emerged organically as tools independently adopted it. A coordinated standard would accelerate adoption for agents.
Open questions
- Variable name —
AGENT (Goose, Amp, Bun), AI_AGENT (Vercel's detect-agent), or something else? AGENT is concise and mirrors CI, but could collide with non-AI agent systems. AI_AGENT is more specific but verbose.
- Scope — Should this cover all automation (like
CI) or specifically AI agents?
- Relationship to
CI — Should agents also set CI=true, or is this orthogonal?
- Coexistence — Should tools set both the standard variable AND their tool-specific one? (Goose already does:
AGENT=goose + GOOSE_TERMINAL=1)
Known opposition
| Project |
Position |
Ref |
| VS Code / Copilot |
Agents should work in identical environments to users. Shipped terminal profile settings instead of env vars. |
#258911, #253945 |
Prior art
- OpenAI Codex uses
CODEX_SANDBOX=1 internally for sandbox detection
- Claude Code uses
CLAUDECODE=1 paired with CLAUDE_CODE_ENTRYPOINT=cli
Comments welcome to update the adoption tables.
Problem
Scripts and CLIs can detect CI environments via the
CI=trueconvention, enabling non-interactive behavior and CI-appropriate output. There's no equivalent for AI coding agents.When agents execute commands, scripts have no way to know they're running in an agent context. This matters because:
CI=truedoesn't capture the full pictureUse cases
Proposal
Agents set an environment variable when executing commands:
AGENT[agent-name],1, ortrueAdoption
AGENTvariable (this proposal)gooseampTool-specific variables (status quo)
CLAUDECODE1CURSOR_AGENT1GEMINI_CLI1CODEX_SANDBOXseatbeltAUGMENT_AGENT1CLINE_ACTIVEtrueOPENCODE_CLIENT1TRAE_AI_SHELL_ID/opt/.devinConsumer-side detection
Tools already adapting behavior based on agent detection:
isAIAgent()checksAGENT=1,CLAUDECODE,REPL_ID. Suppresses passing tests, shows only failures.@vercel/detect-agentchecksAI_AGENT, then falls back to 9+ tool-specific vars. Sets deployment actor.Both had to build detection matrices because no single standard exists.
Precedent
CI=true— Set by GitHub Actions, GitLab CI, CircleCI, Travis, Jenkins, etc.NO_COLOR=1— Disables color output across CLIs (no-color.org)TERM=dumb— Signals limited terminal capabilities--no-interactiveflags and structured output, but no env var conventionThe
CIconvention emerged organically as tools independently adopted it. A coordinated standard would accelerate adoption for agents.Open questions
AGENT(Goose, Amp, Bun),AI_AGENT(Vercel's detect-agent), or something else?AGENTis concise and mirrorsCI, but could collide with non-AI agent systems.AI_AGENTis more specific but verbose.CI) or specifically AI agents?CI— Should agents also setCI=true, or is this orthogonal?AGENT=goose+GOOSE_TERMINAL=1)Known opposition
Prior art
CODEX_SANDBOX=1internally for sandbox detectionCLAUDECODE=1paired withCLAUDE_CODE_ENTRYPOINT=cliComments welcome to update the adoption tables.