Laravel Agent Detector

April 27, 2026 ยท View on GitHub

GitHub Workflow Status (main) Total Downloads Latest Version License

Introduction

Agent Detector is a lightweight PHP utility to detect if your code is running inside an AI agent or automated development environment.

Requires PHP 8.2+

Installation

To get started, install Agent Detector via the Composer package manager:

composer require laravel/agent-detector

Usage

use Laravel\AgentDetector\AgentDetector;
use Laravel\AgentDetector\KnownAgent;

$result = AgentDetector::detect();

if ($result->isAgent) {
    echo "Running inside: {$result->name}";
}

// Check for a specific known agent
if ($result->knownAgent() === KnownAgent::Claude) {
    echo "Hello from Claude!";
}

Or use the standalone function:

use function Laravel\AgentDetector\detectAgent;

$result = detectAgent();

Supported Agents

AgentDetection Method
CustomAI_AGENT env var
CursorCURSOR_AGENT env var
GeminiGEMINI_CLI env var
CodexCODEX_SANDBOX, CODEX_CI, or CODEX_THREAD_ID env var
Augment CLIAUGMENT_AGENT env var
AMPAMP_CURRENT_THREAD_ID env var
OpencodeOPENCODE_CLIENT or OPENCODE env var
ClaudeCLAUDECODE or CLAUDE_CODE env var
CoworkCLAUDE_CODE_IS_COWORK with CLAUDECODE or CLAUDE_CODE env var
CopilotAI_AGENT=github-copilot, AI_AGENT=github-copilot-cli, COPILOT_MODEL, COPILOT_ALLOW_ALL, COPILOT_GITHUB_TOKEN, or COPILOT_CLI env var
ReplitREPL_ID env var
Devin/opt/.devin file exists
AntigravityANTIGRAVITY_AGENT env var
PiPI_CODING_AGENT env var
Kiro CLIKIRO_AGENT_PATH env var
v0AI_AGENT=v0 env var

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

Testing

composer test

Contributing

Thank you for considering contributing to Agent Detector! You can read the contribution guide here.

Code of Conduct

In order to ensure that the Agent Detector community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

Agent Detector is open-sourced software licensed under the MIT license.