-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
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=truedoesn'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 "$@"
fiProposal
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)
| Project | Value | Status | Ref |
|---|---|---|---|
| Goose | goose |
implemented | PR #7017 |
| Amp | amp |
implemented | Docs |
| Claude Code | - | issue open | #24838 |
| Cursor | - | requested (no response) | Forum thread |
Tool-specific variables (status quo)
| Project | Variable | Value | Ref |
|---|---|---|---|
| Claude Code | CLAUDECODE |
1 |
Env vars reference |
| Cursor | CURSOR_AGENT |
1 |
Docs |
| Gemini CLI | GEMINI_CLI |
1 |
Source |
| Codex CLI | CODEX_SANDBOX |
seatbelt |
Source |
| Augment | AUGMENT_AGENT |
1 |
Docs |
| Cline | CLINE_ACTIVE |
true |
Discussion #5366 |
| OpenCode | OPENCODE_CLIENT |
1 |
Vercel PR #15121 |
| TRAE AI | TRAE_AI_SHELL_ID |
(session id) | Vercel PR #14257 |
| Devin | /opt/.devin |
(filesystem) | Vercel detect-agent source |
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-interactiveflags 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?AGENTis concise and mirrorsCI, but could collide with non-AI agent systems.AI_AGENTis more specific but verbose. - Scope — Should this cover all automation (like
CI) or specifically AI agents? - Relationship to
CI— Should agents also setCI=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=1internally for sandbox detection - Claude Code uses
CLAUDECODE=1paired withCLAUDE_CODE_ENTRYPOINT=cli
Comments welcome to update the adoption tables.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels