Download the PHP package impruthvi/agent-detector-laravel without Composer
On this page you can find all versions of the php package impruthvi/agent-detector-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download impruthvi/agent-detector-laravel
More information about impruthvi/agent-detector-laravel
Files in impruthvi/agent-detector-laravel
Package agent-detector-laravel
Short Description Laravel companion for agent-detector: CSRF bypass, agent log channel, and session headers for AI coding agents.
License MIT
Homepage https://github.com/impruthvi/agent-detector-laravel
Informations about the package agent-detector-laravel
agent-detector-laravel
Laravel companion for shipfastlabs/agent-detector.
Install it, add two lines to bootstrap/app.php, and your Laravel app automatically:
- Bypasses CSRF for AI agent requests (no more 419s)
- Logs every request to a separate
agent.logchannel tagged with agent name + session ID - Adds
X-Agent-Sessionheader to responses (visible in proxy/CDN logs)
Grep by session ID. See exactly what your AI agent did.
Requirements
- PHP 8.2+
- Laravel 11, 12, or 13
- shipfastlabs/agent-detector
^1.1
Installation
Publish the config (optional):
Setup
Add the middleware to bootstrap/app.php:
That's it. CSRF bypass and the agent log channel are active automatically.
What you get
CSRF bypass
Agent requests skip CSRF verification. No more 419s when Claude Code, Codex, or Cursor hits your endpoints.
The package tries two approaches, in order:
Approach 1 (automatic): Decorates VerifyCsrfToken via the service container. Works on most Laravel 11+ installs.
Approach 2 (manual fallback): If Approach 1 doesn't work, you'll see a warning in your logs:
Fix it by replacing the middleware in bootstrap/app.php:
You can subclass AgentAwareCsrfMiddleware to add your own $except array:
Agent log channel
Every log line emitted during an agent session is tagged with the agent name and session ID.
The agent channel is auto-registered. Use it directly:
Logs write to storage/logs/agent.log.
X-Agent-Session response header
Every response to a detected agent request includes:
Useful for debugging via proxy logs, CDN access logs, or browser devtools.
Configuration
config/agent-detector.php (after publishing):
Using AgentContext
Inject AgentContext anywhere in your app:
| Method | Returns | Example |
|---|---|---|
isAgent() |
bool |
true |
name() |
?string |
'claude' |
displayName() |
string |
'Claude Code' |
sessionId() |
?string |
'thread-abc123' or null |
knownAgent() |
?KnownAgent |
KnownAgent::Claude |
Session IDs
Most agents do not expose a session ID. Only Codex (CODEX_THREAD_ID) and Amp (AMP_CURRENT_THREAD_ID) expose session env vars today. Log output shows session:"none" for all others — that's expected.
Known limitations
Octane / long-running processes: AgentContext is resolved once when the application boots. Under Laravel Octane or long-running queue:work, detection reflects the environment at startup. Agents set env vars before the process starts, so this is rarely an issue in practice.
Detected agents
Inherits detection from shipfastlabs/agent-detector:
| Agent | Display name | Session ID |
|---|---|---|
| Claude Code | Claude Code |
— |
| Cursor | Cursor |
— |
| Codex | Codex |
CODEX_THREAD_ID |
| Amp | Amp |
AMP_CURRENT_THREAD_ID |
| Devin | Devin |
— |
| Gemini CLI | Gemini CLI |
— |
| Augment CLI | Augment CLI |
— |
| OpenCode | OpenCode |
— |
| Replit | Replit |
— |
| GitHub Copilot | GitHub Copilot |
— |
| Antigravity | Antigravity |
— |
| Pi | Pi |
— |
CI
| Laravel | PHP |
|---|---|
| 11, 12 | 8.2, 8.3, 8.4, 8.5 |
| 13 | 8.4, 8.5 |
License
The MIT License (MIT). Please see License File for more information.
All versions of agent-detector-laravel with dependencies
shipfastlabs/agent-detector Version ^1.1
laravel/framework Version ^11.0|^12.0|^13.0