is-ai-agent
Detect whether a CLI is being invoked by an AI coding agent, and identify which one.
Inspired by the AGENT environment variable proposal. Lets your CLI adapt its output — structured errors, more verbose tracebacks, no interactive prompts — when it's running under an agent rather than a human.
Install
[]
= "0.2"
Usage
use ;
if is_ai_agent
if let Some = detect
For tests or callers that want to consult a captured environment instead of the live process, use detect_with:
use detect_with;
let agent = detect_with;
Detection order
-
The proposed standard
AGENTenv var. Its value is mapped to a known agent (goose,amp,claude-code,cursor,cursor-cli,gemini-cli,codex,augment,cline,opencode,trae,devin,replit,antigravity,github-copilot); generic values like1/trueresolve toAgentId::Unknown. -
Tool-specific env vars:
Variable Agent CLAUDECODE,CLAUDE_CODEClaude Code CURSOR_TRACE_IDCursor (editor) CURSOR_AGENT,CURSOR_EXTENSION_HOST_ROLE=agent-execCursor CLI GEMINI_CLIGemini CLI CODEX_SANDBOX,CODEX_CI,CODEX_THREAD_IDOpenAI Codex ANTIGRAVITY_AGENTAntigravity AUGMENT_AGENTAugment CLINE_ACTIVECline OPENCODE_CLIENTOpenCode TRAE_AI_SHELL_IDTRAE AI GOOSE_TERMINALGoose REPL_IDReplit COPILOT_MODEL,COPILOT_ALLOW_ALL,COPILOT_GITHUB_TOKENGitHub Copilot -
Filesystem signals:
Path Agent /opt/.devinDevin
The detected Agent carries the Signal that matched, so callers can see exactly how detection fired.
License
Dual-licensed under MIT or Apache-2.0, at your option.