shipfastlabs/agent-detector
Lightweight PHP utility that detects whether your code is running inside an AI agent or automated dev environment. Identify Claude, Cursor, Gemini, Codex and more via env vars or a standalone detectAgent() helper.
AI_AGENT env var, allowing future-proofing for emerging AI tools not yet on the supported list.KnownAgent for type safety) but remains framework-agnostic.composer require laravel/agent-detector) and usage via a single function call (detectAgent()) or class (AgentDetector::detect()).KnownAgent enum) are optional.composer update laravel/agent-detector. Teams that deliberately pinned 2.0.4 should re-pin to ^2.0 to absorb both waves of agent additions.AI_AGENT env var.AI_AGENT fallback or upstream PRs — the contribution cadence suggests small PRs land quickly.KnownAgent) and Laravel's env var ecosystem. Works seamlessly with:
AgentDetectorMiddleware to block AI requests).AgentDetector as a singleton).detectAgent() function. No framework-specific dependencies beyond PHP 8.2+.composer require laravel/agent-detector --dev.AI_AGENT=github-copilot).use Laravel\AgentDetector\detectAgent;
$result = detectAgent();
logger()->info("AI Agent Detected", ["agent" => $result->name]);
// app/Http/Middleware/DetectAgent.php
public function handle(Request $request, Closure $next) {
$result = detectAgent();
$request->merge(['is_ai_agent' => $result->isAgent]);
return $next($request);
}
AgentDetector to the container for dependency injection.
// app/Providers/AppServiceProvider.php
public function register() {
$this->app->singleton(AgentDetector::class);
}
AiAgentDetected).COPILOT_MODEL). Ensure these are set correctly in deployment pipelines (e.g., GitHub Actions, Docker).AgentDetector or using the AGENT_ENV_VARS constant to add custom env vars.composer update laravel/agent-detector. If you maintain a hardcoded allowlist of KnownAgent cases, extend it to cover the eight new agents or handle unknown enum members defensively.KnownAgent enum cases appear in patch releases.AgentDetector::AGENT_ENV_VARS to inspect detected env vars.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| False positive detection | Legitimate requests blocked | Whitelist known good env vars; test thoroughly. |
| False negative detection | AI requests slip through | Monitor logs/metrics; extend detection rules; adopt v2.0.5+ for newer agents. |
| Cloud/CI agent not detected | Pipeline usage untracked | Validate in ephemeral runners; fall back to explicit AI_AGENT in CI config. |
| Env var injection attack | Malicious env vars trigger detection | Validate env vars against a allowlist (e.g., KnownAgent enum). |
Stale KnownAgent allowlist |
New agents silently unclassified | Review allowlist each upgrade; handle unknown enum values defensively. |
| Package update breaks compatibility | New major version introduces issues | Pin to a stable minor version (e.g., ^2.0). |
| Custom agent misconfiguration | Undetected or misclassified agents | Document custom agent setup; use AI_AGENT for clarity. |
| Unknown new agent (not yet supported) | Coverage gap for emerging tools | Use AI_AGENT override; watch for upstream additions (14 added in two patches). |
| Misdirected security disclosure | Delayed vulnerability triage | Update runbooks to Laravel's org-wide security policy. |
detectAgent() vs. AgentDetector::detect()).KnownAgent::Claude), including the v2.0.5 additions.jobs:
test:
env:
AI_AGENT:
How can I help you explore Laravel packages today?