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.1"
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,gemini-cli,codex,augment,cline,opencode,trae,devin); generic values like1/trueresolve toAgentId::Unknown. -
Tool-specific env vars:
Variable Agent CLAUDECODEClaude Code CURSOR_AGENTCursor GEMINI_CLIGemini CLI CODEX_SANDBOXOpenAI Codex AUGMENT_AGENTAugment CLINE_ACTIVECline OPENCODE_CLIENTOpenCode TRAE_AI_SHELL_IDTRAE AI GOOSE_TERMINALGoose -
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.