Expand description
Detect whether the current process is being invoked by an AI coding agent, and identify which one.
Detection order:
- The generic
AGENT(agentsmd/agents.md#136) andAI_AGENT(@vercel/detect-agent) env vars, when their value names a known agent. - Tool-specific env vars (
CLAUDECODE,CURSOR_AGENT, …). - Filesystem signals (e.g.
/opt/.devin). - A bare truthy
AGENT/AI_AGENT(e.g.AGENT=1) as a last resort, resolving toAgentId::Unknown. Tool-specific vars outrank it so agents that set both (e.g. OpenCode setsAGENT=1andOPENCODE=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
Unknownwhen 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
trueif any AI agent signal is present.