Detect AI coding agents from their execution environment
Project description
Agent Detector
agent-detector is a small, dependency-free Python package for detecting which
AI coding agent is driving the current process.
It returns evidence rather than only a boolean, so callers can distinguish an explicit identity from a broad environmental hint.
Installation
pip install agent-detector
Usage
from agent_detector import detect_agent
detection = detect_agent()
if detection:
print(detection.agent) # "codex"
print(detection.confidence) # "high"
print(detection.signal) # "CODEX_THREAD_ID"
The returned DetectionResult contains:
agent: anAgentNameliteral containing a supported agent nameconfidence:high,medium, orlowsource:environmentorpathsignal: the name of the matched signal, never its value
Pass a mapping to make detection deterministic in tests:
assert detect_agent({"OPENCODE": "1"}).agent == "opencode"
Require a minimum confidence when broad environmental hints are not useful:
detection = detect_agent(minimum_confidence="high")
minimum_confidence is typed as Literal["high", "medium", "low"] and
defaults to "low".
Supported agents
| Agent | Signals | Confidence |
|---|---|---|
| Explicit override | AI_AGENT containing a supported agent name |
high |
| Amp | AGENT=amp, AMP_CURRENT_THREAD_ID |
high / medium |
| Codex | CODEX_THREAD_ID, CODEX_CI, CODEX_SANDBOX |
high |
| Gemini CLI | GEMINI_CLI |
high |
| Copilot CLI | COPILOT_CLI |
medium |
| OpenCode | OPENCODE |
high |
| Antigravity | ANTIGRAVITY_AGENT |
medium |
| Augment CLI | AUGMENT_AGENT |
medium |
| Cowork | CLAUDE_CODE_IS_COWORK |
high |
| Claude Code | CLAUDE_CODE_CHILD_SESSION, CLAUDECODE, CLAUDE_CODE |
high / medium |
| Cursor | CURSOR_TRACE_ID |
medium |
| Cursor CLI | CURSOR_AGENT, CURSOR_EXTENSION_HOST_ROLE=agent-exec |
high / medium |
| Kiro | TERM_PROGRAM=kiro |
low |
| Pi | .pi/agent entry in PATH |
medium |
| Replit | REPL_ID |
low |
| Goose | GOOSE_PROVIDER |
low |
AI_AGENT takes precedence over inferred signals when its value is one of the
supported agent names. Unknown values are ignored.
The detector is deliberately ordered. For example, Amp is checked before
Claude Code because Amp also sets CLAUDECODE.
Important limitations
Detection is best-effort. None means unattributed, not "human". Some
signals can also be present in an integrated terminal where a person typed the
command manually.
This package detects the execution harness. It cannot determine whether a particular skill, plugin, prompt, or model caused the command. Use a separate explicit marker when that attribution matters.
Privacy
Environment values such as thread IDs are never returned. A result contains only a normalized agent name and the name and category of the matched signal.
Development
uv sync --all-groups
uv run ruff check .
uv run ruff format --check .
uv run mypy
uv run pytest
uv build
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agent_detector-1.0.0.tar.gz.
File metadata
- Download URL: agent_detector-1.0.0.tar.gz
- Upload date:
- Size: 51.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
014ea0403dc50bf3748db72197b94a3cb6e7df4b0050973867fec63551829363
|
|
| MD5 |
363eee25cd4bab65d44bda898c8ffdc6
|
|
| BLAKE2b-256 |
d6500e4f389bd39b3426e629b23856f8d4467e3e04cfbc64f9266b905b42a769
|
File details
Details for the file agent_detector-1.0.0-py3-none-any.whl.
File metadata
- Download URL: agent_detector-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fde1814282ee66db764855b0fa8535f739883338ecf6148019be370ba3b11f4
|
|
| MD5 |
78467f40a339d56a08c72e7ad5d4ddd5
|
|
| BLAKE2b-256 |
3cc417a5659bfdb9cb65f9350d83dc9b9184b4618c726797f713a154cbd3ad47
|