Skip to main content

Crate is_ai_agent

Crate is_ai_agent 

Source
Expand description

Detect whether the current process is being invoked by an AI coding agent, and identify which one.

Detection order:

  1. The generic AGENT (agentsmd/agents.md#136) and AI_AGENT (@vercel/detect-agent) env vars, when their value names a known agent.
  2. Tool-specific env vars (CLAUDECODE, CURSOR_AGENT, …).
  3. Filesystem signals (e.g. /opt/.devin).
  4. A bare truthy AGENT/AI_AGENT (e.g. AGENT=1) as a last resort, resolving to AgentId::Unknown. Tool-specific vars outrank it so agents that set both (e.g. OpenCode sets AGENT=1 and OPENCODE=1) are still identified.
if is_ai_agent::is_ai_agent() {
    // emit structured output
}

if let Some(agent) = is_ai_agent::detect() {
    eprintln!("running under {}", agent.name);
}

Structs§

Agent
A detected AI agent and the signal that revealed it.

Enums§

AgentId
Canonical identifier for a known agent, or Unknown when an agent is present but its specific identity can’t be determined (e.g. AGENT=1).
Signal
What signal triggered the detection.

Functions§

detect
Detect the AI agent, if any.
detect_with
Detection with injectable lookups, useful for tests and for callers that want to consult a captured environment instead of the live process.
is_ai_agent
Returns true if any AI agent signal is present.