/rails-cto:rails-cto-qafrom rails-cto
Quality assurance for Ruby on Rails projects: linting, testing, and code review. Runs after creating or modifying any Ruby file, scoping review to branch changes and enforcing test coverage conventions.
Ships in rails-cto. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Every Ruby file must pass three gates before it's considered done: linting, testing, and code review. These aren't separate steps you do later — they're part of writing the code.
Before reviewing anything, understand what's being shipped.
Check the current branch and determine the base branch:
git branch --show-current
main, stop: "You're on main — run QA from a feature branch or staging."staging, the base branch is main.staging.Check working tree status: Run git status (never use -uall). Uncommitted changes are included in the review — no need to ask.
Scope the changes to this branch only:
git diff <base>...HEAD --stat
git log <base>..HEAD --oneline
Replace <base> with the base branch determined in step 1. This is what's about to be shipped. The rest of the QA workflow applies only to these files and changes — not the entire codebase.
Check review readiness: If there are no changes relative to the base branch, there's nothing to review. Let the user know and stop.
Make your changes to controllers, models, commands, tests, etc.
For each changed .rb file (excluding test files themselves), check that a corresponding test file exists. Map by convention:
app/models/post.rb → test/models/post_test.rbapp/controllers/posts_controller.rb → test/controllers/posts_controller_test.rbapp/commands/posts/create.rb → test/commands/posts/create_test.rbapp/services/posts/search.rb → test/services/posts/search_test.rbapp/jobs/sync_post_job.rb → test/jobs/sync_post_job_test.rbapp/components/forms/combo_select.rb → test/components/forms/combo_select_test.rbIf the test file does not exist, create it before proceeding. Invoke /rails-cto-minitest for the correct test structure and DSL. New or changed code without tests is not shippable.
Every test file MUST define a subject block exactly once at the top of the class. If a test file exists but has no subject, add one before running the tests. If a test file reassigns subject inline inside it or describe blocks, refactor it to use a let(:attributes) pattern with nested describe overrides instead. See the code review section below for correct vs wrong examples.
Invoke /rails-cto-static-analysis on the changed Ruby files. This scans for code smells, excessive complexity, and structural duplication — and auto-refactors when issues are found.
Do not proceed to RuboCop until static analysis passes or the user acknowledges remaining issues.
Scope: every .rb and .rake file that appears in git diff <base>...HEAD --name-only --diff-filter=AM plus any uncommitted modifications from git status. Do not run against the entire codebase.
The file is the unit, not the diff. CI runs rubocop on whole files — any offense in a file you modified will fail the build, even on lines you did not author. If you changed one line in a 200-line file and rubocop reports offenses on the other 199, fix them. "I didn't write that code" is not a valid reason to skip an offense in a file you touched.
Run autocorrect first:
bundle exec rubocop -A path/to/changed_file.rb
For multiple files:
bundle exec rubocop -A app/controllers/posts_controller.rb app/models/post.rb test/controllers/posts_controller_test.rb
Then review the output:
-A skips some by design) and cops without autocorrect support.Verification (required). After fixes, re-run without -A to confirm the file is clean:
bundle exec rubocop path/to/changed_file.rb
Exit code must be 0 and the report must show no offenses detected. If anything remains, fix it and re-run — repeat until clean.
Stop-gate. Do not proceed to section 6 (tests) until every changed .rb / .rake file exits rubocop with zero offenses. A changed file with lingering offenses is not shippable; it will fail CI.
After RuboCop passes, run the tests for the files you changed in parallel with coverage enabled:
COVERAGE=1 PARALLEL=1 bundle exec rails test test/path/to/relevant_test.rb
If you changed a model, run its model test. If you changed a controller, run its controller test. If you're unsure which tests cover your change, run the full suite:
COVERAGE=1 PARALLEL=1 bundle exec rails test
After tests pass, check for coverage/coverage.json in the project root. If it exists, read it to verify your tests adequately cover the changed code.
lines array: null = not relevant, 0 = uncovered, 1+ = covered..rb file you created or modified. Ignore files you didn't touch.If coverage/coverage.json does not exist, skip this step.
After linting and tests pass, review the changed code against these quality checks. This is where you catch the things that automated tools miss.
Look for repeated logic across the changed files and nearby code. If you see the same pattern three or more times, it probably belongs in a shared method, concern, or service object. Two similar lines are fine — three is a signal.
Also look for dead code — methods, variables, or constants that are no longer called or referenced anywhere. If code is no longer used, remove it. Don't leave commented-out code or orphaned methods behind.
Example:
# Repeated in multiple controllers — extract to a concern or helper
current_user.posts.where(active: true).order(created_at: :desc)
subject is requiredEvery test class must define a subject block exactly once at the top of the class. Do not reassign subject inside it or describe blocks. When different tests need different attributes, use a let(:attributes) block that subject references, and override it in nested describe blocks.
# WRONG — subject reassigned inline in each test
class PlanDecoratorTest < ActiveSupport::TestCase
describe "#price_summary" do
it "returns formatted price" do
subject = Fabricate.build(:plan, amount: 1200, interval: "month")
assert_equal "$12.00 / month", subject.price_summary
end
end
end
# ALSO WRONG — no subject, local variable instead
class PostTest < ActiveSupport::TestCase
describe "#host" do
it "returns the host" do
post = Fabricate.build(:post, url: "https://example.com/path")
assert_equal "example.com", post.host
end
end
end
# RIGHT — subject declared once, variations via let(:attributes)
class PlanDecoratorTest < ActiveSupport::TestCase
let(:attributes) { {} }
subject { Fabricate.build(:plan, **attributes) }
describe "#price_summary" do
describe "with monthly interval" do
let(:attributes) { { amount: 1200, interval: "month" } }
it "returns formatted price" do
assert_equal "$12.00 / month", subject.price_summary
end
end
end
end
For each changed method, think about what happens when things go wrong:
nil?Favor explicit handling over silent failures. A user should see a clear error message rather than a broken page or missing data. Handle errors at the boundaries — where user input enters the system and where external services are called.
Example:
# FRAGILE — blows up if post is nil
post.tags.pluck(:name)
# BETTER — handles the nil case
post&.tags&.pluck(:name) || []
Check for common Rails performance pitfalls in the changed code:
includes, preload, or eager_load.exists? instead of count > 0? Could this use pluck instead of loading full records?where clause on a column or a new foreign key, check that the column is indexed.Example:
# N+1 — each post loads its tags separately
@posts = Post.all
@posts.each { |b| b.tags.map(&:name) }
# FIXED — eager load the association
@posts = Post.includes(:tags).all
Every method and function in changed .rb, .rake, and .js files must have a comment directly above the declaration describing why it exists — not what it does (the code shows that). Focus on intent, context, or the business reason. This applies to all methods, not just new ones — if an existing method in a changed file is missing a comment, add one.
Scan each changed file for def (Ruby/Rake) or function/method declarations (JS) and verify a comment appears on the line(s) immediately above. If any are missing, add them before moving on.
Ruby / Rake (.rb, .rake) — plain comment above def:
# Ensures the user sees their most relevant posts first,
# because recently active tags reflect current interests.
def prioritized_posts
posts.joins(:tags).order("tags.updated_at DESC")
end
JavaScript (.js) — JSDoc above the function or method:
/**
* Debounces save requests to avoid overwhelming the server
* when the user types quickly in the autosave form.
*/
save() { /* ... */ }
Exceptions — skip comments for trivial/framework-conventional methods where the intent is self-evident: initialize with simple assignment, single-line delegation (delegate :name, to: :user), accessor-style methods (def name = @name), and standard Rails callbacks that are already named descriptively (before_save :normalize_email).
Remove any console.log, Rails.logger.debug, puts, pp, p, or binding.pry statements that were added during development. These should never ship to staging or production.
Scan any changed .html.erb files for inline variable assignments (<% variable = ... %>). The only acceptable assignment in ERB is local_assigns.fetch for partial local defaults. Everything else is untestable and must be moved out.
<%# WRONG — not testable %>
<% tags = post.tags.active.order(:name) %>
<% show_banner = current_account.trial? && current_account.days_remaining < 7 %>
<% display_name = "#{user.first_name} #{user.last_name}".strip %>
<%# RIGHT — testable in controller/model tests %>
<%= render partial: "tag", collection: @tags %>
<%= render "shared/trial_banner" if @show_trial_banner %>
<%= current_account.display_name %>
Move violations to:
Do not modify .rubocop.yml to suppress or work around warnings. If RuboCop flags something, fix the code — don't change the rules. Do not add rubocop:disable comments as a workaround.
Code should be explicit over clever. When reviewing, ask:
For each new code path or integration point, consider one realistic way it could fail in production (timeout, nil reference, race condition, stale data) and whether:
If a failure would be silent — no test, no error handling, no user feedback — flag it. Silent failures are the hardest bugs to find later.
This project uses rubocop-rails-omakase as its base with these overrides:
.rb fileEvery Ruby file must start with this comment:
# frozen_string_literal: true
Break long lines with string continuation or method chaining:
# WRONG — over 100 characters
Rails.logger.error "Failed to update embedding for tag #{tag_id}: #{result.errors.message_list.join(', ')}"
# RIGHT — split with continuation
Rails.logger.error "Failed to update embedding for tag #{tag_id}: " \
"#{result.errors.message_list.join(', ')}"
# WRONG
["title", "full_title"]
# RIGHT — rubocop-rails-omakase uses brackets with spaces
[ "title", "full_title" ]
# WRONG
{ :key => "value" }
# RIGHT
{ key: "value" }
| Step | Command |
|---|---|
| Autocorrect a file | bundle exec rubocop -A path/to/file.rb |
| Autocorrect multiple files | bundle exec rubocop -A file1.rb file2.rb |
| Check without fixing | bundle exec rubocop path/to/file.rb |
| Run related tests | PARALLEL=1 COVERAGE=1 bundle exec rails test test/path/to/test.rb |
| Run full test suite | PARALLEL=1 COVERAGE=1 bundle exec rails test |
| Static analysis | /rails-cto-static-analysis (invoked automatically after RuboCop) |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub mattsears/rails-cto --plugin rails-cto17 skills in this plugin
/rails-ctoOrchestrator skill for Ruby on Rails projects. Initializes sessions, routes to specialized skills, enforces mandatory QA gates, and runs the completion checklist. Invoke at the start of every Rails session./rails-cto-apiHow to build RESTful JSON APIs in a Rails 8 application following OpenAPI standards. Use when creating, modifying, or debugging API endpoints, serializers, authentication, documentation, or any code under the Api:: namespace. Also use when the user mentions "api", "endpoint", "api key", "serializer", "openapi", "swagger", "api documentation", "cors", "rate limit", "pagination cursor", "api versioning", or asks about exposing data to external consumers. Proactively apply these rules whenever touching API controllers, routes, or serializers, even if the user doesn't explicitly ask.
/rails-cto-architectHow to write comprehensive implementation plans for multi-step Rails features before any code is written. Use when the user has a spec, feature request, or multi-step task and wants to plan the approach before touching code. Also use when the user mentions "create a plan", "write a plan", "plan this", "plan a feature", "implementation plan", "build a new feature", "new feature", "how should I build", "how do I build", "architect this", "design this", "design a feature", "feature design", "spec", "requirements", or pastes long-form requirements. Proactively invoke this skill BEFORE writing any code for multi-file or multi-step work, even if the user doesn't explicitly say "plan" — every multi-step feature goes through architect first. Produces a bite-sized, task-by-task plan optimized for rails-cto-engineer to execute. Never writes code, never commits, and never generates plans that contain commit steps.
/rails-cto-commitStage and commit all outstanding code changes with a clear, human-friendly commit message. Use this skill whenever the user asks to commit, save their work, push changes, or says things like "commit this", "save my progress", "push this up", "ship it", "commit all", or "commit and push". Also triggers for "/commit-all". Do NOT use for cherry-picking, rebasing, or other advanced git operations./rails-cto-engineerThis file provides guidance to Claude Code (claude.ai/code) when working with Ruby on Rails projects./rails-cto-erbHow to write clean, well-formatted ERB templates for this Rails 8 project. Use when creating or modifying any ERB view, partial, layout, or component template. Also use when the user mentions "erb", "views", "partials", "templates", "html formatting", "attribute alignment", or asks about view-layer code. Proactively apply these rules whenever touching .html.erb files, even if the user doesn't explicitly ask for formatting help.
Other plugins' skills for the same job