rails-query

rails-query is a skill for Claude Code from lewispb/rails-query-skill. It costs 188 tokens per session (2,368 once invoked), scanned A, original, MIT.

A read-only way to query data in a Rails 8.2 or newer application. Rails is a Ruby web framework, and the tool can return database results as structured JSON locally or from a Kamal deployment.

In plain words
What is it for?
Use it for counts, lookups, aggregates, schema exploration, database investigations, and query-performance checks such as EXPLAIN plans.
Why use it?
It avoids opening a console, writing a temporary script, or using SSH for data questions, while blocking database writes.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the rails-query plugin — 1 skill shipped together

Good fit Use it for counts, lookups, aggregates, schema exploration, database investigations, and query-performance checks such as EXPLAIN plans.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/lewispb/rails-query-skill/rails-query
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add lewispb/rails-query-skill --skill rails-query
Clone the repo
git clone --depth 1 https://github.com/lewispb/rails-query-skill

Made for: Claude Code.

Or install rails-query, the plugin that ships this one along with the rest of its 1 skill.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for rails-query

README.md
[![agentmods](https://agentmods.dev/badge/skills/lewispb/rails-query-skill/rails-query.svg)](https://agentmods.dev/skills/lewispb/rails-query-skill/rails-query)
Your own site
<a href="https://agentmods.dev/skills/lewispb/rails-query-skill/rails-query"><img src="https://agentmods.dev/badge/skills/lewispb/rails-query-skill/rails-query.svg" alt="Measured on agentmods" height="20"></a>
Per session 188 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,368 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00188 $0.02368
Opus 5 $0.00094 $0.01184
Sonnet 5 $0.00038 $0.00474
Haiku 4.5 $0.00019 $0.00237

Measured 8d ago against content hash c77106acca0e, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

rails-query scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/rails-query/SKILL.md · 202 lines

How it starts

The opening of the file, as written. The whole thing — 202 lines — stays where its author put it; the contents beside it link to each section on GitHub.

rails-query

rails query is a Rails 8.2+ command for running read-only queries against the database. Input is a single expression, output is a single JSON object on stdout ({columns, rows, meta}; errors go to stderr with non-zero exit), and writes are blocked at the connection level. With a read replica configured it hits the replica automatically, so it's safe to point at production.

Prefer it over a console, a script, or SSH for any data question. One invocation, structured output, nothing to clean up.

The flow

1. Know where you're running

  • Local (bin/rails query) — development, tests, or anywhere you have the app checked out.
  • Remote via Kamal (bin/kamal query -d <destination>) — when the app is deployed with Kamal. Requires a small alias in config/deploy.yml (see "Kamal setup").

If you don't know whether Kamal is configured, check config/deploy.yml for an aliases: block.

2. Decide: Ruby expression or raw SQL

Default: Ruby (ActiveRecord). The expression is eval'd in the app context — scopes, associations, finders, aggregates all work. Model logic (encryption, default scopes, polymorphism) is honored.

--sql: raw schema access, cross-table joins without models, or aggregates awkward in AR.

Telltale sign you forgot --sql: SyntaxError: unexpected *; no anonymous rest parameter — your SQL got parsed as Ruby. Add --sql and retry.

3. Inspect the schema if it's unfamiliar

rails query has three introspection modes that work the same locally and remotely — crucial when you only have Kamal access:

bin/rails query schema           # every table
bin/rails query schema users     # columns + indexes + enums + associations for one table
bin/rails query models           # every AR model with its table and associations

Enums matter: if a column is an enum, User.where(status: "active") works but User.where(status: 0) might silently misfire. schema <table> tells you.

Over Kamal, cache the schema locally before jq-ing it — each round-trip is 10-30s. Dump schema / models / schema <table> to /tmp/rails-query-cache-<env>/ once, then jq against the files. Skip caching for single-query tasks or local runs.

Read the full file on GitHub · 202 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 202 lines · 188 tokens per session scan A c77106acca0e

Subscribe to this mod's changes

rails-query is a skill published in the GitHub repository lewispb/rails-query-skill (25 stars, last pushed 4mo ago), licensed MIT. It adds 188 tokens to every session and 2,368 once invoked, about $0.0009 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

schema-exploration

Lists tables, describes columns and data types, identifies foreign key relationships, and maps entity relationships in a database. Use when the user asks about database schema, table structure, column types, what tables exist, ERD, foreign keys, or how entities relate.

langchain-ai/deepagents · 57 tokens

ha-data-stores

Map of Hope Agent's local data stores and safe read-only query workflow. Use when the user asks where Hope Agent stores data, wants to inspect sessions/messages/memory/logs/background jobs/knowledge indexes/settings, asks the model to query local app data, or debugging requires checking persisted state. Trigger…

shiwenwen/hope-agent · 115 tokens

supabase

Supabase / PostgREST Row-Level-Security playbook — pull the anon (or leaked servicerole) key out of the frontend JS, map tables from the auto-generated OpenAPI spec, test anonymous RLS READ disclosures (PII/secret leaks), and anonymous RLS WRITE abuse (insert/update/delete — e.g. forging…

PentesterFlow/agent · 120 tokens

nornicdb-cypher-queries

Pick fast, predictable Cypher query shapes in NornicDB — point lookups, batch retrieval, pagination, search, traversal, batched UNWIND/MERGE writes, cleanup, multi-tenant isolation. Use when writing or reviewing Cypher whose latency or throughput matters; maps user intent to the executor's hot-path query templates.

orneryd/NornicDB · 79 tokens

dsql

Build with Aurora DSQL — manage schemas, execute queries, handle migrations, diagnose query plans, diagnose cluster performance, load data, and develop applications with a serverless, distributed SQL database. Covers IAM auth, multi-tenant patterns, MySQL-to-DSQL and PostgreSQL-to-DSQL schema conversion, foreign key…

awslabs/agent-plugins · 229 tokens

volcengine-rds-postgresql

A tool for operating PostgreSQL databases hosted by Volcano Engine's managed database service. PostgreSQL is a relational database used to store structured application data.

bytedance/agentkit-samples · 63 tokens