is-ai-agent 0.1.0

Detect whether a CLI is being invoked by an AI coding agent, and identify which one.
Documentation
  • Coverage
  • 28.57%
    8 out of 28 items documented1 out of 7 items with examples
  • Size
  • Source code size: 25.93 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 467.87 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 25s Average build duration of successful builds.
  • all releases: 24s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • sdairs/is-ai-agent
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sdairs

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

[dependencies]
is-ai-agent = "0.1"

Usage

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);
}

For tests or callers that want to consult a captured environment instead of the live process, use detect_with:

use is_ai_agent::detect_with;

let agent = detect_with(
    |name| if name == "AGENT" { Some("goose".into()) } else { None },
    |_| false,
);

Detection order

  1. The proposed standard AGENT env var. Its value is mapped to a known agent (goose, amp, claude-code, cursor, gemini-cli, codex, augment, cline, opencode, trae, devin); generic values like 1 / true resolve to AgentId::Unknown.

  2. Tool-specific env vars:

    Variable Agent
    CLAUDECODE Claude Code
    CURSOR_AGENT Cursor
    GEMINI_CLI Gemini CLI
    CODEX_SANDBOX OpenAI Codex
    AUGMENT_AGENT Augment
    CLINE_ACTIVE Cline
    OPENCODE_CLIENT OpenCode
    TRAE_AI_SHELL_ID TRAE AI
    GOOSE_TERMINAL Goose
  3. Filesystem signals:

    Path Agent
    /opt/.devin Devin

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.