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

v1.0.1 2026-02-12 10:04 UTC

This package is auto-updated.

Last update: 2026-02-12 10:06:55 UTC


README

Agent Detector

GitHub Workflow Status (master) Total Downloads Latest Version License

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.