detect_agent
Detect if code is running in an AI agent or automated development environment
What it is and what it does
detect_agent is a lightweight utility that identifies whether code is executing inside an AI agent or automated development environment. It works by checking environment variables and conditions against a vendored list of detection rules sourced from Vercel's upstream detect-agent package, returning both a boolean flag and metadata about the detected agent if one is found.
The package supports detection of many AI coding assistants and development environments—including Cursor, Claude Code, GitHub Copilot, Devin, Gemini CLI, and others—plus a standard AI_AGENT environment variable that any tool can set to identify itself. It's designed for scenarios where application behavior needs to adapt based on whether a human or an AI agent is running the code, such as adjusting logging verbosity, enabling experimental features, or tracking telemetry differently.
Use it for:
- Adapt application logging, error handling, or output formatting when running under an AI agent versus human execution.
- Track telemetry and analytics separately for AI agent runs versus human-driven sessions.
- Enable or disable experimental features conditionally based on whether an AI development tool is detected.
- Implement custom behavior in libraries or frameworks when they detect they're running in an AI-assisted coding environment.
- Support the AI_AGENT standard by setting it in your own tool to allow downstream code to detect your presence.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Detects whether code is running in an AI agent or automated development environment by checking environment variables and conditions against a curated list of known agents.
Yes, with a license caveat. The package is actively maintained, has zero dependencies, and solves a real problem for code that needs to behave differently in AI agent contexts. However, verify the actual license terms before use—the metadata does not declare one, which is a gap you should resolve before committing to a dependency.
Install
detect-agent on PyPI
pip
pip install detect-agentuv
uv add detect-agentpoetry
poetry add detect-agentInstalling detect_agent
Before you install
Low friction installation with no runtime dependencies. Active maintenance as of 2026-08-12 with recent releases.
License in practice
License status is unclear—no SPDX identifier or raw license text is available in the package metadata. Verify the actual license terms before using in proprietary or restricted contexts.
Quickstart
from detect_agent import determine_agent
result = determine_agent()
if result["is_agent"]:
print(f"Running in {result['agent']['name']} environment")
Requires Python 3.9 or later.
Verify before relying
- Exact license under which detect_agent is distributed (SPDX identifier not provided).
- How frequently the vendored agents.json is synced with upstream Vercel repository.
- Whether detection rules cover all current AI coding assistants or if gaps exist.
Package facts
| License | not declared (unclear) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 2 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 652,133/month — #5,545 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: detect_agent-0.6.0-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
deepagents-codeA terminal-based AI coding agent that works…
permissive · top 15,000 on PyPI
verminVermin analyzes Python source code to detect…
permissive · top 15,000 on PyPI
google-agents-cliA CLI toolchain that equips coding agents…
permissive · top 15,000 on PyPI
lib-detect-testenvDetects whether code is running in a test…
permissive · top 5,000 on PyPI
claude-tapclaude-tap is a local proxy and trace viewer…
permissive · top 15,000 on PyPI
serena-agentSerena is an MCP server that provides semantic…
permissive · top 15,000 on PyPI
plugin-scannerLints, verifies, and gates plugins, skills, MCP…
permissive · top 15,000 on PyPI
ci-infoDetects which continuous integration platform…
permissive · top 15,000 on PyPI
shellinghamShellingham detects which shell the current…
permissive · top 1,000 on PyPI
opencode-agent-hubCoordinates communication between multiple AI…
agpl · top 15,000 on PyPI