Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Agent Detector Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Lightweight & Non-Intrusive: The package remains a standalone utility with minimal dependencies (PHP 8.2+ only), making it ideal for integration into existing Laravel or PHP applications without architectural overhead. v2.0.5 introduces no new runtime dependencies.
  • Environment-Based Detection: Relies on environment variables and filesystem checks, which are non-blocking and do not require runtime modifications to the application flow.
  • Rapidly Expanding Agent Coverage: v2.0.5 adds detection for ZCode, Qwen Code, Crush, Windsurf, Zed Agent, Kiro IDE, Copilot cloud agent, and Jules — eight new agents on top of the six added in v2.0.4 (Kimi, Grok, Cline, Goose, Junie, OpenClaw). Across two patch releases the supported set has more than doubled, materially reducing the "coverage gap" risk called out in the prior assessment.
  • Cloud/CI Agent Awareness: The addition of Copilot cloud agent and Jules means detection is no longer purely a local-developer-workstation concern; it now covers agents that execute in ephemeral CI/cloud runners. This expands the package's relevance to build-pipeline and hosted-agent governance use cases.
  • Extensible Design: Supports custom agent detection via AI_AGENT env var, allowing future-proofing for emerging AI tools not yet on the supported list.
  • Laravel-Native: Aligns with Laravel's ecosystem (e.g., enum-based KnownAgent for type safety) but remains framework-agnostic.
  • Governance Simplification: The package-specific security policy file was removed in favour of Laravel's org-wide default. No runtime or architectural impact, but it does change the vulnerability disclosure channel (see Operational Impact).

Integration Feasibility

  • Zero Configuration: Installation via Composer (composer require laravel/agent-detector) and usage via a single function call (detectAgent()) or class (AgentDetector::detect()).
  • Minimal Boilerplate: No database migrations, service providers, or middleware required. Can be invoked anywhere in the codebase (e.g., middleware, controllers, CLI commands).
  • Standalone or Framework-Agnostic: Works in pure PHP apps, Laravel, or other frameworks. Laravel-specific features (e.g., KnownAgent enum) are optional.
  • Drop-in Upgrade from v2.0.x: v2.0.5 is a purely additive release (agent detections, a CI dependency bump, and a documentation/governance change). No config, namespace, or API changes — upgrade is a simple 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.

Technical Risk

  • False Positives/Negatives: Detection relies on env vars or filesystem checks, which may not cover all edge cases (e.g., custom agents with non-standard configurations). Risk mitigated by:
    • Community-driven agent additions (v2.0.4 and v2.0.5 are concrete examples — fourteen agents added across two patches, the latter from two separate contributors).
    • Custom detection logic via AI_AGENT env var.
    • New consideration: cloud/CI agents (Copilot cloud agent, Jules) may present different or fewer env markers than local CLI agents, so their detection reliability should be validated in your own pipeline rather than assumed.
  • PHP Version Lock: Requires PHP 8.2+. Risk for legacy systems, but most modern Laravel apps (v9+) already meet this requirement.
  • Performance Impact: Negligible—env var checks are O(1) and executed once per request/CLI invocation. Each patch adds a small number of additional env-var/file checks; the constant-time nature is unchanged and the added constant factor remains trivial relative to request handling.
  • Breaking Changes: None in v2.0.5. The last breaking change was v2.0.0 (namespace). Risk remains low for the current 2.x line.
  • Security Disclosure Path Change: Removing the package-level security policy in favour of the org-wide Laravel default is a process change, not a code change. Confirm your internal security triage still routes agent-detector findings to a monitored channel.

Key Questions

  1. Use Case Clarity:
    • Is detection needed for security (e.g., blocking AI-generated requests), analytics (tracking AI tool usage), or feature gating (e.g., disabling certain endpoints)?
    • Example: "Should we block Claude-generated requests from sensitive APIs?"
  2. Integration Scope:
    • Where will detection be used? (e.g., middleware for all requests, specific controllers, CLI commands).
    • Example: "Do we need to wrap this in a middleware for global detection?"
  3. Custom Agent Support:
    • Will the team need to extend detection for internal tools? If so, how will custom agents be registered/managed?
  4. Agent Coverage Priority:
    • With v2.0.5, does the newly supported set (ZCode, Qwen Code, Crush, Windsurf, Zed Agent, Kiro IDE, Copilot cloud agent, Jules) cover your actual tooling? If key agents remain unsupported, plan for AI_AGENT fallback or upstream PRs — the contribution cadence suggests small PRs land quickly.
  5. CI/Cloud Agent Detection:
    • Do you need to detect agents running in CI or hosted environments (Jules, Copilot cloud agent)? If so, validate detection behaviour in ephemeral runners where env vars are set by the platform rather than a developer's shell.
  6. False Positive Tolerance:
    • What's the acceptable rate of false positives/negatives? (e.g., "We can tolerate 5% false negatives for Copilot.")
  7. Monitoring:
    • Should detection results be logged or exposed via metrics (e.g., Prometheus) for observability?
  8. Dependency Conflicts:
    • Could this conflict with existing packages (e.g., other env var-based tools)? Unlikely, but worth auditing.

Integration Approach

Stack Fit

  • Laravel Applications: Ideal for Laravel apps due to native enum support (KnownAgent) and Laravel's env var ecosystem. Works seamlessly with:
    • Middleware (e.g., AgentDetectorMiddleware to block AI requests).
    • Service containers (bind AgentDetector as a singleton).
    • Artisan commands (detect AI usage in CLI tools).
  • Non-Laravel PHP: Fully functional with the standalone detectAgent() function. No framework-specific dependencies beyond PHP 8.2+.
  • Microservices/CLI Tools: Perfect for detecting AI usage in background workers (e.g., queues) or CLI scripts. v2.0.4's CLI-first additions (Goose, Cline, OpenClaw) and v2.0.5's editor/IDE agents (Windsurf, Zed Agent, Kiro IDE) now span both terminal and IDE-driven workflows.
  • CI/CD Pipelines: v2.0.5's cloud-agent coverage makes the package viable for pipeline-level telemetry — e.g., tagging builds or PRs that were produced with Copilot cloud agent or Jules.

Migration Path

  1. Evaluation Phase:
    • Install the package in a staging environment: composer require laravel/agent-detector --dev.
    • Test detection in various contexts (e.g., local dev, CI/CD, production-like env vars).
    • Example: Simulate AI agents using env vars (e.g., AI_AGENT=github-copilot).
  2. Pilot Integration:
    • Start with a single use case (e.g., logging AI detections in a controller).
    • Example:
      use Laravel\AgentDetector\detectAgent;
      
      $result = detectAgent();
      logger()->info("AI Agent Detected", ["agent" => $result->name]);
      
  3. Scaled Rollout:
    • Option A (Middleware): Create a global middleware to attach AI detection to all requests.
      // app/Http/Middleware/DetectAgent.php
      public function handle(Request $request, Closure $next) {
          $result = detectAgent();
          $request->merge(['is_ai_agent' => $result->isAgent]);
          return $next($request);
      }
      
    • Option B (Service Provider): Bind AgentDetector to the container for dependency injection.
      // app/Providers/AppServiceProvider.php
      public function register() {
          $this->app->singleton(AgentDetector::class);
      }
      
    • Option C (Event Listeners): Trigger events when AI agents are detected (e.g., AiAgentDetected).

Compatibility

  • Laravel Versions: Compatible with Laravel 9+ (PHP 8.2+). For older versions, use v1.x of the package.
  • PHP Extensions: No extensions required. Works with any PHP runtime (CLI, Apache, Nginx, CI runner, etc.).
  • Environment Variables: Detection relies on env vars (e.g., COPILOT_MODEL). Ensure these are set correctly in deployment pipelines (e.g., GitHub Actions, Docker).
  • Customization: Override detection logic by extending AgentDetector or using the AGENT_ENV_VARS constant to add custom env vars.
  • Patch-Level Upgrade (v2.0.4 → v2.0.5): Backward-compatible. No action required beyond 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.
  • Governance: Security reporting now follows Laravel's org-wide policy rather than a package-local file; no application-side change required.

Sequencing

  1. Phase 1: Detection Only (1–2 days):
    • Install and test detection in isolation.
    • Verify all supported agents are detected correctly, prioritising the v2.0.4 and v2.0.5 additions that match your tooling (including any cloud/CI agents).
  2. Phase 2: Integration (2–3 days):
    • Choose integration method (middleware/service provider).
    • Implement use case (e.g., logging, blocking, or analytics).
  3. Phase 3: Validation (1 day):
    • Test with real AI agents (e.g., Copilot, Claude, Windsurf, Zed Agent) in staging.
    • Mock edge cases (e.g., missing env vars, custom agents, ephemeral CI runners).
  4. Phase 4: Monitoring (Ongoing):
    • Add observability (e.g., log detections, alert on unexpected agents).
    • Plan for future agent additions (e.g., subscribe to package releases — 14 agents added across v2.0.4 and v2.0.5 within a short window).

Operational Impact

Maintenance

  • Low Effort: Minimal maintenance required. Updates are backward-compatible (except major versions).
  • Dependency Updates: Monitor for new agent additions — the cadence is clearly active (six agents in v2.0.4, eight in v2.0.5). Budget for a monthly Composer update, and review the changelog before pinning, since new KnownAgent enum cases appear in patch releases.
  • Custom Logic: If extending detection, maintain custom env var mappings or logic separately.
  • Allowlist Hygiene: Any internal allowlist/denylist of agent identifiers should be reviewed on each upgrade to avoid silently ignoring newly supported agents.

Support

  • Troubleshooting:
    • Common issues: False negatives due to missing env vars or custom agent misconfiguration; cloud/CI agents not exposing expected markers in ephemeral runners.
    • Debugging: Use AgentDetector::AGENT_ENV_VARS to inspect detected env vars.
  • Community: Active GitHub repo with responsive maintainers (Laravel team). v2.0.5 includes a first-time contributor (@DarkGhostHunter) alongside the existing maintainers, indicating a broadening contributor base rather than single-maintainer dependency.
  • Security Reporting: The package-local security policy was removed in favour of Laravel's org-wide default. Update internal runbooks so vulnerability reports for this dependency are routed through the org-wide channel.
  • Documentation: Comprehensive README and changelog. Add internal docs for custom use cases and the specific agents your team supports.

Scaling

  • Performance: Negligible overhead. Env var checks are O(1) and cached per request. The v2.0.5 additions increase the constant factor slightly but remain trivial.
  • Concurrency: Thread-safe (stateless design). No locks or shared resources.
  • Horizontal Scaling: No impact on distributed systems (e.g., Kubernetes, serverless). The expanded cloud-agent coverage adds value in these topologies rather than cost.

Failure Modes

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.

Ramp-Up

  • Developer Onboarding (1 hour):
    • Explain basic usage (detectAgent() vs. AgentDetector::detect()).
    • Show how to check for specific agents (e.g., KnownAgent::Claude), including the v2.0.5 additions.
  • Team Adoption (1 day):
    • Demo integration in a shared component (e.g., middleware).
    • Provide a template for custom detection logic and for handling unrecognised agents.
  • CI/CD Integration (0.5 day):
    • Add env var checks to deployment pipelines (e.g., GitHub Actions).
    • Example:
      jobs:
        test:
          env:
            AI_AGENT:
      
  • Governance Handover (0.5 hour):
    • Confirm the team knows where to report security issues now that the package-local policy is gone.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel