Skip to content

Instantly share code, notes, and snippets.

@mrexodia
Last active April 14, 2026 08:37
Show Gist options
  • Select an option

  • Save mrexodia/37cb4bcf5a9c77c5d6555577ec8353b4 to your computer and use it in GitHub Desktop.

Select an option

Save mrexodia/37cb4bcf5a9c77c5d6555577ec8353b4 to your computer and use it in GitHub Desktop.
Claude Deep Research about standardized `AGENT` environment variable

The race to standardize how coding agents announce themselves

There is no established standard yet, but a clear frontrunner has emerged. The most significant proposal is Issue #136 on the agentsmd/agents.md repository (18k+ stars), filed January 8, 2026, which proposes a universal AGENT=<name> environment variable — directly modeled on the CI=true convention that unified CI/CD detection years ago. Three coding agents already ship with this convention (Goose, Amp, Bun), two detection libraries exist to paper over the fragmentation (@vercel/detect-agent and unjs/std-env), and a parallel naming camp champions AI_AGENT=<name> instead. The ecosystem is in the "organic adoption" phase, with real-world friction driving urgency.

The central proposal mirrors how CI=true became universal

The AGENTS.md repository — already the de facto standard for giving coding agents project-specific instructions — hosts the most authoritative proposal for environment variable standardization. Issue #136, authored by @ianlet, argues that scripts and CLIs today have no reliable way to detect they're running under an AI coding agent. The proposal draws a direct parallel to CI=true, which every CI provider now sets, and which thousands of tools check.

The motivations are concrete. Error output should be structured JSON for agents but human-friendly prose for developers. Verbosity can be higher for agents that process full context. Interactivity must be suppressed — agents can't answer y/n prompts, just like CI runners. The proposed convention is simple:

if [[ -n "${AGENT:-}" ]]; then
  echo '{"error": "config_missing", "suggestion": "run ./setup.sh"}'
else
  echo "Error: Config file not found. Run ./setup.sh to initialize."
fi

The proposal cites three precedents: CI=true (GitHub Actions, GitLab CI, CircleCI, etc.), NO_COLOR=1 (the no-color.org convention), and TERM=dumb (limited terminal capabilities). Four open questions remain unresolved: whether to name it AGENT, AI_AGENT, or something else; whether it should cover all automation or only AI agents; whether agents should also set CI=true; and whether tools should set both a standard variable and a tool-specific one.

What agents actually set today: a fragmented landscape

The current state is messy. Every major coding agent either sets its own proprietary environment variables or sets nothing at all. Here is the confirmed state as of April 2026:

Agent Env Var(s) Set in Subprocesses Convention
Goose (Block) AGENT=goose + GOOSE_TERMINAL=1 Both generic + specific
Amp (Sourcegraph) AGENT=amp Generic only
Bun AGENT=bun Generic only
Claude Code (Anthropic) CLAUDECODE=1, CLAUDE_CODE_ENTRYPOINT, CLAUDE_CODE_SESSION_ID Tool-specific only
OpenAI Codex CLI CODEX_CI=1, NO_COLOR=1, TERM=dumb, GIT_PAGER=cat, GH_PAGER=cat Tool-specific only
Cursor CURSOR_CLI (working), CURSOR_AGENT=1 (intended but buggy) Tool-specific only
Aider None No detection env var
GitHub Copilot None documented No detection env var
Cline None (proposed: CLINE_ACTIVE=true) Feature requested
Windsurf None documented No detection env var

Goose is the model citizen here, setting both the emerging generic AGENT=goose and its own GOOSE_TERMINAL=1. Claude Code sets CLAUDECODE=1 in all spawned subprocesses — confirmed in anthropics/claude-code#37817 — primarily to prevent nested Claude Code sessions from launching. Codex sets CODEX_CI=1 internally, with an open issue (#13416) requesting it also set AGENT=codex. Cursor's CURSOR_AGENT=1 was intended but reportedly broken, and its recent decision to set CI=1 in agent terminals caused real bugs — packages that change behavior under CI (disabling watch mode, changing output formats) broke unexpectedly.

Two detection libraries already exist to handle the chaos

Because no single standard exists, two JavaScript libraries have built detection matrices that check multiple environment variables with fallback chains.

@vercel/detect-agent is Vercel's npm package that promotes AI_AGENT as the universal standard. It checks AI_AGENT first, then falls back to 9+ tool-specific environment variables: CLAUDECODE for Claude Code, CURSOR_CLI for Cursor, COPILOT_MODEL for GitHub Copilot, and custom detection for Devin, Gemini CLI, Codex, Antigravity, and Replit. The recommended convention is AI_AGENT="your-tool-name" using lowercase with hyphens (e.g., claude-code, cursor-cli, devin@1).

unjs/std-env (v4.0.0, March 2026) is the popular runtime-agnostic JavaScript utility that recently added agent detection alongside its established CI and runtime detection. It exposes isAgent, agent, and agentInfo properties and supports 11 agents: Cursor, Claude, Devin, Replit, Gemini, Codex, Auggie, OpenCode, Kiro, Goose, and Pi. Its detection logic checks AI_AGENT first, then tool-specific variables, with IDEs checked last so agents running inside them are detected preferentially.

Both libraries exist because the fragmentation forced them to — as the Issue #136 discussion notes, "Both had to build detection matrices because no single standard exists."

GitHub issues and forum threads show broad community demand

The demand for standardization spans every major agent and editor ecosystem:

  • openai/codex#13416 (March 2026, 64.7k-star repo): Requests adding AGENT=codex to Codex's UNIFIED_EXEC_ENV array, with a working implementation branch already created
  • microsoft/vscode#265446 (September 2025): Proposed VSCODE_COPILOT_TERMINAL=1 to distinguish AI-initiated terminal sessions, motivated by tmux auto-start configs breaking AI output
  • block/goose#3827: Requested GOOSE_TERMINAL=1 for shell customization in Goose-spawned terminals
  • cline/cline discussions#5366: Proposes CLINE_ACTIVE=true for all Cline-managed terminals
  • Cursor forum (January 2025): The earliest community request, proposing AGENT=1 or CURSOR_AGENT=1 for Composer runs, with a practical workaround discovering that Cursor sets PAGER=head -n 10000 | cat in agent terminals
  • Zed discussions#47038: Requests separate environment variable configuration for Zed Agent terminals vs. interactive terminals

Technical articles have also covered the pattern. An InfoQ article on AI Agent CLI patterns recommends environment variables as one of three "escape routes" for CLI tools (alongside explicit flags and semantic exit codes) but notably does not propose a specific convention — a gap that Issue #136 aims to fill.

AGENTS.md and the broader interoperability stack

The environment variable proposal sits within a rapidly maturing interoperability ecosystem. AGENTS.md itself — originally proposed by OpenAI for Codex in August 2025 — is now a widely adopted open standard for providing AI coding agents with project-specific instructions (build commands, code style, conventions). It has been adopted by 60,000+ open-source projects and is supported by OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Amp, Devin, and many others. In December 2025, it was donated to the Agentic AI Foundation (AAIF) under the Linux Foundation, alongside Anthropic's MCP and Block's Goose.

The broader landscape has several complementary layers, each addressing a different interoperability concern:

  • AGENTS.md — Static project guidance for agents (what to do in this codebase)
  • Model Context Protocol (MCP) — Runtime tool connectivity (how agents access external tools and data; 97 million+ monthly SDK downloads)
  • Agent2Agent Protocol (A2A) — Google's cross-agent communication standard (50+ technology partners)
  • Agent Client Protocol (ACP) — Standardizes editor-to-agent communication (used by Zed, Goose)
  • NIST AI Agent Standards Initiative — Government-led security and interoperability standards (announced February 2026)
  • AGENT/AI_AGENT env var — Runtime detection of agent context (no standard yet; active proposal)

The environment variable standardization remains the most significant open gap in this stack. Every other layer has an established or emerging standard; runtime agent detection does not.

The naming debate and what comes next

The community faces a consequential naming decision between two camps. The AGENT=<name> convention is concise, mirrors CI=true, and already has adoption from Goose, Amp, and Bun — but risks collision with non-AI agent systems (monitoring agents, user-agent strings, etc.). The AI_AGENT=<name> convention, championed by Vercel's detection library, is unambiguous but more verbose. A third possibility, tool-specific variables only (CODEX_CI, CLAUDECODE, CURSOR_AGENT), perpetuates the fragmentation that detection libraries are already struggling with.

The most likely resolution path runs through the AGENTS.md repository and AAIF governance. The standard already has momentum: three agents ship AGENT=<name>, detection libraries check for it, and the 18k-star repo provides institutional weight. The CI=true precedent is instructive — it succeeded not through a formal specification but through organic adoption reaching a tipping point where non-compliance became more costly than compliance.

The practical upshot for tool developers today: check for AI_AGENT first (Vercel's convention), then AGENT (the emerging community convention), then fall back to tool-specific variables. For agent developers: set AGENT=<your-tool-name> alongside your tool-specific variables, following Goose's dual-variable pattern. This hedges against whichever naming convention ultimately wins while ensuring downstream tools can detect your agent context now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment