Detect if code is running in an AI agent or automated development environment
Maintained. Last release 4 months ago, commits in 3 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install detect-agentdetect_agent
This is a Python port of Vercel's
detect-agentpackage.
A lightweight utility for detecting if code is being executed by an AI agent or automated development environment.
Installation
uv add detect_agent
Usage
from detect_agent import determine_agent
result = determine_agent()
if result["is_agent"]:
agent = result["agent"]
print(f"Running in {agent['name']} environment")
# Adapt behavior for AI agent context
Agent Definitions
Detection rules are vendored from upstream agents.json (validated against agents.schema.json) and evaluated in array order; the first match wins.
Supported Agents
This package can detect the following AI agents and development environments:
- Cursor (Anysphere)
- Claude Code (Anthropic)
- Claude Cowork (Anthropic)
- Kimi Code (Moonshot AI)
- Grok Build (xAI)
- Devin (Cognition Labs)
- Gemini CLI (Google)
- Codex (OpenAI)
- Antigravity (Google DeepMind)
- Augment
- Cline
- OpenCode
- OpenClaw
- Goose (Block)
- Junie (JetBrains)
- Kiro (AWS)
- Pi
- GitHub Copilot
- Replit
- Custom agents (via the
AI_AGENTenvironment variable)
See agents.json for the exact environment variables and conditions used to detect each one.