detect-coding-agent
A Rust utility crate that detects whether your application is being invoked by an AI coding agent such as Claude Code, GitHub Copilot Cloud Agent, OpenAI Codex, Cursor, Aider, Gemini CLI, and many more.
Why?
When your application knows it is running inside an automated coding agent it can:
- Suggest machine-friendly interfaces (e.g. MCP) instead of interactive UIs.
- Emit structured output that the agent can parse more reliably.
- Skip interactive prompts and use sensible defaults instead.
- Provide agent-specific hints or documentation snippets.
Quick start
Add to your Cargo.toml:
[]
= "0.1"
Then in your code:
use ;
Supported agents
| Agent | Kind | Detection signal |
|---|---|---|
| OpenCode | Agent | OPENCODE, OPENCODE_BIN_PATH, OPENCODE_SERVER, OPENCODE_APP_INFO, OPENCODE_MODES |
| Jules (Google) | Agent | HOME=/home/jules + USER=swebot |
| Claude Code (Anthropic) | Agent | CLAUDECODE |
| Gemini CLI | Agent | GEMINI_CLI=1 |
| OpenAI Codex | Agent | CODEX_THREAD_ID |
| Aider | Agent | AIDER_API_KEY |
| Windsurf (Codeium) | Agent | CODEIUM_EDITOR_APP_ROOT |
| Antigravity | Agent | ANTIGRAVITY_AGENT, ANTIGRAVITY_PROJECT_ID |
| Crush (Charm) | Agent | CRUSH=1, AGENT=crush, AI_AGENT=crush |
| Amp (Sourcegraph) | Agent | AMP_CURRENT_THREAD_ID, AGENT=amp |
| Auggie (Augment Code) | Agent | AUGMENT_AGENT=1 |
| Qwen Code (Alibaba) | Agent | QWEN_CODE=1 |
| GitHub Copilot Cloud Agent | Agent | COPILOT_AGENT_SESSION_ID + GITHUB_ACTIONS=true |
| Cursor Agent | Agent | CURSOR_TRACE_ID + PAGER=head -n 10000 | cat |
| Cursor | Interactive | CURSOR_TRACE_ID |
| Replit Assistant | Agent | REPL_ID + REPLIT_MODE=assistant |
| Replit | Interactive | REPL_ID |
| Bolt.new Agent | Agent | SHELL=/bin/jsh + npm_config_yes |
| Bolt.new | Interactive | SHELL=/bin/jsh |
| Zed Agent | Agent | TERM_PROGRAM=zed + PAGER=cat |
| Zed | Interactive | TERM_PROGRAM=zed |
| GitHub Copilot in VS Code | Agent | TERM_PROGRAM=vscode + GIT_PAGER=cat |
| Warp Terminal | Hybrid | TERM_PROGRAM=WarpTerminal |
API
// Detect the first matching agent in the current environment
DetectedAgent
AgentKind
Detection strategy
Detection is based exclusively on environment variables — no subprocesses are spawned and no filesystem access is performed. The first provider whose signals match the current environment is returned.
The ordering of checks matters for providers that share environment signals
(e.g. agent mode vs. interactive mode of the same tool). More specific checks
(e.g. Cursor agent, identified by both CURSOR_TRACE_ID and a specific
PAGER value) are evaluated before the less specific interactive variant
(identified by CURSOR_TRACE_ID alone).
Example binary
The crate ships with an example binary that prints detection results:
Sample output when run inside a GitHub Copilot Cloud Agent session:
✅ Coding agent detected!
Name : GitHub Copilot Cloud Agent
ID : copilot-cloud-agent
Kind : agent
💡 Tip: This is an autonomous agent session — consider offering a
machine-friendly interface (e.g. via MCP) for better results.
License
Licensed under either of European Union Public License, Version 1.2, Apache License, Version 2.0 or MIT license at your option.