AGENTS.md templates / Ruby on Rails

AGENTS.md template for Ruby on Rails

A ready AGENTS.md for a Rails application. It tells agents to follow Rails conventions instead of inventing structure, which commands to run, and the migration and callback mistakes they make.

Updated 3 December 2026 · 51 lines · 2.1 KB
AGENTS.md
# AGENTS.md

A Ruby on Rails application with PostgreSQL.

## Commands

- `bin/setup`: install gems and prepare the database
- `bin/dev`: start the app on http://localhost:3000
- `bin/rails test`: run the test suite
- `bin/rails db:migrate`: apply migrations
- `bin/rubocop`: lint

## Project structure

- `app/models/`: Active Record models and domain logic
- `app/controllers/`: thin controllers: authorise, call the model, render
- `app/views/`: templates and partials
- `app/jobs/`: background jobs
- `db/migrate/`: migrations. `db/schema.rb` is generated; never edit it by hand
- `test/`: tests

## Rules for agents

- Follow Rails conventions. Do not add service objects, repositories or new top-level folders unless asked.
- Schema changes go through a migration. Never edit `db/schema.rb` by hand.
- No emails, API calls or other side effects in model callbacks. Use a job.
- Scope every record lookup to what the current user may access.

## Conventions

### Ruby on Rails

- Fat models, skinny controllers — but extract to service objects / interactors before the model hits 300 lines.
- Strong parameters on every controller write action.
- ActiveRecord scopes over ad-hoc `where` chains in controllers.
- Background jobs (Sidekiq / GoodJob) for anything > 200ms in a request.

### PostgreSQL

- UUIDv7 or bigint identity for PKs — never auto-increment integers for user-visible IDs.
- Indexes on every foreign key and on columns used in WHERE/ORDER BY. Check with `EXPLAIN ANALYZE`.
- Use `jsonb` (not `json`). Add GIN indexes only when you query into it.
- Transactions for multi-row writes. Be explicit about isolation level when it matters.

## 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 Ruby on Rails. Change them to match your project before you commit the file: an agent will run exactly what is written here.

Make it yours in the generator Add your database, test runner and other tools, pick your coding style, and get matching CLAUDE.md, Cursor and Copilot files. Free, runs in your browser. Already have instruction files? Context Doctor scans your repo and shows which files each coding tool is silently not loading. $19.

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:

ToolWhat to do
Claude CodeReads 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.
CursorReads 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.
CodexReads AGENTS.md from the root down to the folder you are in, with a shared 32 KiB limit across all of them.
GitHub CopilotReads 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 Ruby on Rails projects

These are the reasons the “Rules for agents” section says what it says.

Fighting the framework

Agents add service objects, repositories and custom folders to a codebase that follows plain Rails. The template says to use what Rails gives you first.

Editing schema.rb

Instead of writing a migration, an agent edits the schema file directly. The next db:migrate wipes the change.

Callbacks with side effects

Generated models send email or call APIs from after_save. It fires in tests, seeds and consoles. The template keeps side effects in jobs.

Unscoped queries in controllers

Model.find(params[:id]) with no ownership check is the most common generated security hole in Rails code.

Questions

Where does AGENTS.md go in a Ruby on Rails 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.

We use RSpec, not Minitest. What changes?

Replace the test command with bundle exec rspec and the test/ folder with spec/. Nothing else.

Templates for other stacks

Next.jsReactNode.js and TypeScriptExpressPythonFastAPIDjangoGoLaravelVueSvelteKitAstroNestJSFastifyHonoFlaskRustElectronSupabase