~/sdairs git:(main) $ cat posts/is-ai-agent-rust-crate.md
is-ai-agent for Rust: detect if your CLI is invoked by an agent
I published a new Rust crate is-ai-agent. It lets you detect when your CLI is being called an AI agent, by detecting standard/common environment variables that various agents set.
It’s a very simple API:
use is_ai_agent::{detect, is_ai_agent};
if is_ai_agent() {
// emit structured/agent-friendly output
}
if let Some(agent) = detect() {
eprintln!("running under {}", agent.name);
}
It’s not perfect, as there’s no standard signal for agents to identify themselves yet. There is an ongoing discussion for creating a standard AGENT variable, but it seems that only a few of the smaller open source agents have adopted it so far.
For now, this is the environment variable and agent coverage:
| Variable | Agent |
|---|---|
CLAUDECODE, CLAUDE_CODE | Claude Code |
CURSOR_TRACE_ID | Cursor (editor) |
CURSOR_AGENT, CURSOR_EXTENSION_HOST_ROLE=agent-exec | Cursor CLI |
GEMINI_CLI | Gemini CLI |
CODEX_SANDBOX, CODEX_CI, CODEX_THREAD_ID | OpenAI Codex |
ANTIGRAVITY_AGENT | Antigravity |
AUGMENT_AGENT | Augment |
CLINE_ACTIVE | Cline |
OPENCODE_CLIENT | OpenCode |
TRAE_AI_SHELL_ID | TRAE AI |
GOOSE_TERMINAL | Goose |
REPL_ID | Replit |
COPILOT_MODEL, COPILOT_ALLOW_ALL, COPILOT_GITHUB_TOKEN | GitHub Copilot |
I needed this for clickhousectl, so I’ll be keeping the rules up to date.
There’s a similar lib for TypeScript with @vercel/detect-agent.
~/sdairs git:(main) $