AGENTS.md template for Laravel
A ready AGENTS.md for a Laravel application. It covers controllers, Eloquent models and form requests, the Artisan and test commands, and the validation and mass-assignment mistakes agents make.
# AGENTS.md A Laravel application on PHP 8.3. ## Commands - `composer install`: install PHP dependencies - `php artisan serve`: start the app on http://localhost:8000 - `php artisan test`: run the test suite - `php artisan migrate`: apply migrations - `./vendor/bin/pint`: format to the Laravel code style ## Project structure - `app/Http/Controllers/`: thin controllers - `app/Http/Requests/`: form requests: validation and authorisation - `app/Models/`: Eloquent models - `database/migrations/`: migrations. Never edit one that has run in production - `routes/web.php, routes/api.php`: route definitions - `tests/Feature/, tests/Unit/`: tests ## Rules for agents - Validation and authorisation live in form requests, not in controllers. - Models declare `$fillable`. Never use `$guarded = []` or pass `$request->all()` to `create` or `update`. - Eager-load relations where the collection is built (`with(...)`). - Never run `migrate:fresh`, `migrate:reset` or `db:wipe` without asking. ## Conventions ### Laravel / PHP - Eloquent for CRUD, query builder when Eloquent is awkward, raw SQL as a last resort. - Form Requests for validation — not inline in controllers. - Jobs + Queues for anything slow. Events for cross-cutting notifications. - Use Blade components / Livewire / Inertia consistently — pick one per project. ## Guardrails - Never commit secrets, API keys, or credentials. If you spot one in a diff, stop and flag it. - Do not invent dependencies. If a package is not already in the manifest, confirm before adding it. - When a command fails, read the actual error. Do not retry blindly or bypass with `--force`. - Prefer editing existing files over creating new ones. - Run the tests and the linter before saying a task is done, and say what you ran.
The commands and folders are the common defaults for Laravel. Change them to match your project before you commit the file: an agent will run exactly what is written here.
How to use it
Save the file as AGENTS.md in the root of your repository and commit it. Then check each tool you use:
| Tool | What to do |
|---|---|
| Claude Code | Reads AGENTS.md only when no CLAUDE.md exists in or above the folder. If you have a CLAUDE.md, put @AGENTS.md on its first line. |
| Cursor | Reads AGENTS.md from the project root, in the desktop app and the terminal. In the app, rules in .cursor/rules must be .mdc files. The terminal reads only plain .md files there. |
| Codex | Reads AGENTS.md from the root down to the folder you are in, with a shared 32 KiB limit across all of them. |
| GitHub Copilot | Reads AGENTS.md on some surfaces only. Keep a .github/copilot-instructions.md as well if your team relies on Copilot. |
Details and sources: the AGENTS.md compatibility matrix.
What agents get wrong in Laravel projects
These are the reasons the “Rules for agents” section says what it says.
Validation inside controllers
Agents inline $request->validate([...]) in every method. The template sends validation to form requests so rules live in one place.
Mass assignment left open
$guarded = [] or Model::create($request->all()) shows up in generated code because it makes the error go away.
N+1 queries in Blade
A loop in a view that touches a relation runs one query per row. The template asks for eager loading where the collection is built.
Running artisan commands that destroy data
migrate:fresh is an agent’s quick fix for a migration error. It drops every table. It is listed under things to never run without asking.
Questions
Where does AGENTS.md go in a Laravel project?
In the root of the repository, next to your manifest file. Tools read it from the folder you start them in and, for most tools, from parent folders too.
Does Claude Code read AGENTS.md?
Only when there is no CLAUDE.md in or above the working folder. If you already have a CLAUDE.md, keep it and make its first line @AGENTS.md so both tools read the same rules.
How long should the file be?
Short enough that every line is something the agent would get wrong without it. Codex shares a 32 KiB budget across all the AGENTS.md files it loads, and long files get followed less closely by every tool.
Does this cover Livewire or Inertia?
Add a line naming which one you use and where its components live. Agents otherwise mix Blade, Livewire and Inertia patterns in one feature.