Skip to content

Proposal: Standard environment variable for agent runtime detection #136

@ianlet

Description

@ianlet

Problem

Scripts and CLIs can detect CI environments via the CI=true convention, enabling non-interactive behavior and CI-appropriate output. It seems 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 1 Running under an AI coding agent

Precedent

  • CI=true — Set by GitHub Actions, GitLab CI, CircleCI, Travis, Jenkins, etc.
  • NO_COLOR=1 — Disables color output across CLIs
  • TERM=dumb — Signals limited terminal capabilities

The CI convention emerged organically as tools independently adopted it. A coordinated standard would accelerate adoption for agents.

Open questions

  1. Variable nameAGENT, AI_AGENT, AGENTIC, LLM_AGENT?
  2. Scope — Should this cover all automation (like CI) or specifically AI agents?
  3. Relationship to CI — Should agents also set CI=true, or is this orthogonal?

Prior art

  • InfoQ: Patterns for AI Agent Driven CLIs — Recommends --no-interactive flags and structured output, but no env var convention
  • OpenAI Codex uses CODEX_SANDBOX=1 internally for sandbox detection
  • No cross-agent standard exists today

Hopefully this is the right place to propose such standard, let me know if I should post this somewhere else.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions