CLAUDE.md for a Rails project

A CLAUDE.md for a Ruby on Rails app: the stack, the bin/rails and test commands, the fat-model convention, and the files an agent should never edit by hand. Copy it into your repo root, fill in the bracketed parts, and commit it so every Claude Code session reads it first.

When to use this

Use it on a Rails 7 app. The rule that earns its place here is the schema one: agents will happily edit schema.rb to make a test pass, which desyncs everyone else. Fill in the project name and switch the test command if you run RSpec.

The template CLAUDE.md

# [Project] — agent guide

## Stack
Ruby on Rails 7, Ruby 3.3, PostgreSQL. Dependencies with Bundler.

## Commands
- Install: `bundle install`
- Run: `bin/rails server`
- Migrate: `bin/rails db:migrate`
- Test: `bin/rails test`
- Lint: `bundle exec rubocop`

## Conventions
- Fat models, thin controllers. Push logic into models or service objects.
- Use strong parameters in every controller action that writes.
- Name things the Rails way so the conventions do the work for you.
- Prefer the Hotwire and asset setup already in the app over new front-end tools.

## How to work here
- Run the tests and rubocop before you call a task done.
- Keep each change focused on one task.

## Do not
- Do not edit `schema.rb` by hand; change it through a migration.
- Do not commit `config/master.key` or any credential.
- Do not skip or delete tests to make a task pass.

Why each section is there

  • Stack pins the Rails and Ruby versions so the agent uses current generators and syntax.
  • Commands give the real bin/rails, test and lint lines.
  • Conventions encode the Rails habits that keep a codebase readable.
  • Do not protects the schema, the credentials and the test suite.

You can build one from a form with the CLAUDE.md generator. For how an agent works from a file like this, read working with agents.

FAQ

RSpec or Minitest?

Either. The template uses the default Rails test command; swap it for bundle exec rspec if you use RSpec. Keep the rest the same.

Does the agent need to know my Rails version?

Yes. Pin it in the stack line. It changes which generators, defaults and syntax the agent should reach for.