shipfastlabs/agent-detector
Lightweight PHP 8.2+ utility to detect if your app is running inside an AI agent or automated dev environment. Supports Claude, Cursor, Gemini, Codex, Replit, Devin, and more via env vars or file checks, with a simple API and helper function.
A lightweight PHP utility to detect if your code is running inside an AI agent or automated development environment.
Requires PHP 8.2+
composer require shipfastlabs/agent-detector
use AgentDetector\AgentDetector;
$result = AgentDetector::detect();
if ($result->isAgent) {
echo "Running inside: {$result->name}";
}
// Check for a specific known agent
if ($result->knownAgent() === \AgentDetector\KnownAgent::Claude) {
echo "Hello from Claude!";
}
Or use the standalone function:
use function AgentDetector\detectAgent;
$result = detectAgent();
| Agent | Detection Method |
|---|---|
| Custom | AI_AGENT env var |
| Cursor | CURSOR_AGENT env var |
| Gemini | GEMINI_CLI env var |
| Codex | CODEX_SANDBOX or CODEX_THREAD_ID env var |
| Augment CLI | AUGMENT_AGENT env var |
| AMP | AMP_CURRENT_THREAD_ID env var |
| Opencode | OPENCODE_CLIENT or OPENCODE env var |
| Claude | CLAUDECODE or CLAUDE_CODE env var |
| Replit | REPL_ID env var |
| Devin | /opt/.devin file exists |
Set the AI_AGENT environment variable to any value to identify your custom agent:
AI_AGENT=my-custom-agent php your-script.php
Please see CONTRIBUTING for details on how to contribute, including adding support for new agents.
composer test
Agent Detector was created by Pushpak Chhajed under the MIT license.
How can I help you explore Laravel packages today?