shipfastlabs / agent-detector
Detect if code is running in an AI agent or automated development environment
Fund package maintenance!
pushpak1300
Installs: 12
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/shipfastlabs/agent-detector
Requires
- php: ^8.2.0
Requires (Dev)
- laravel/pint: ^1.24.0
- peckphp/peck: ^0.1.3
- pestphp/pest: ^3.8.5|^4.1.0
- pestphp/pest-plugin-type-coverage: ^3.0|^4.0.2
- phpstan/phpstan: ^2.1.26
- rector/rector: ^2.1.7
- symfony/var-dumper: ^7.3.3
README
A lightweight PHP utility to detect if your code is running inside an AI agent or automated development environment.
Requires PHP 8.2+
Installation
composer require shipfastlabs/agent-detector
Usage
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();
Supported Agents
| Agent | Detection Method |
|---|---|
| Custom | AI_AGENT env var |
| Cursor | CURSOR_TRACE_ID env var |
| Cursor CLI | CURSOR_AGENT env var |
| Gemini | GEMINI_CLI env var |
| Codex | CODEX_SANDBOX env var |
| Augment CLI | AUGMENT_AGENT 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 |
Custom Agent
Set the AI_AGENT environment variable to any value to identify your custom agent:
AI_AGENT=my-custom-agent php your-script.php
Contributing
Please see CONTRIBUTING for details on how to contribute, including adding support for new agents.
Testing
composer test
Agent Detector was created by Pushpak Chhajed under the MIT license.
