query-agent

query-agent is an agent for Claude Code from ThibautBaissac/rails_ai_agents. It costs 0 tokens per session (675 once invoked), scanned A, original, MIT.

A Rails programming guide for putting complicated database queries into separate, reusable query objects. Rails is a Ruby web framework, and a query object packages database-search logic in one place.

In plain words
What is it for?
Use it for reports, dashboards, filtering, aggregations, reusable searches, and queries that need tests or protection against N+1 database requests.
Why use it?
It keeps multi-condition searches and reports easier to reuse and test, while addressing slow queries caused by repeatedly loading related records.

Agent for Claude Code

Written for Claude Code: installed under .claude/. Also seen: model in frontmatter.

Good fit Use it for reports, dashboards, filtering, aggregations, reusable searches, and queries that need tests or protection against N+1 database requests.

Compare 6 agents from other repositories ↓
Install with agentmods
npx agentmods add agents/thibautbaissac/rails_ai_agents/query-agent
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.

Clone the repo
git clone --depth 1 https://github.com/ThibautBaissac/rails_ai_agents

Made for: Claude Code.

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 query-agent

README.md
[![agentmods](https://agentmods.dev/badge/agents/thibautbaissac/rails_ai_agents/query-agent/github.svg)](https://agentmods.dev/agents/thibautbaissac/rails_ai_agents/query-agent)
Your own site
<a href="https://agentmods.dev/agents/thibautbaissac/rails_ai_agents/query-agent"><img src="https://agentmods.dev/badge/agents/thibautbaissac/rails_ai_agents/query-agent/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for query-agent

Your own site · 80×15
<a href="https://agentmods.dev/agents/thibautbaissac/rails_ai_agents/query-agent"><img src="https://agentmods.dev/badge/agents/thibautbaissac/rails_ai_agents/query-agent.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 675 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.00000 $0.00675
Opus 5.5 $0.00000 $0.00270
Sonnet 5.5 $0.00000 $0.00135
Haiku 4.5 $0.00000 $0.00068

Measured 3mo ago against content hash 8b1af882a4b8, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

query-agent 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 3mo 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.

.claude/agents/query-agent.md · 85 lines

How it starts

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

You are an expert in the Query Object pattern for Rails applications.

Your Role

  • Create reusable, testable query objects that encapsulate complex database queries
  • Always write RSpec tests alongside the query object
  • Optimize queries to avoid N+1 problems; follow Single Responsibility Principle

When to Use Query Objects

Use when: complex queries with multiple conditions, queries reused across the codebase, queries with business logic or composability needs, search/filtering/reporting logic, queries needing independent tests.

Don't use when: simple one-liner queries (use scopes), queries used only once, basic associations.

N+1 Prevention

Always use includes, preload, or eager_load. Consider strict_loading in Rails 8+:

class Entity < ApplicationRecord
  self.strict_loading_by_default = true
end

Query Object vs Scope

# Scope -- simple, single-purpose filters on the model
class Entity < ApplicationRecord
  scope :published, -> { where(status: 'published') }
  scope :recent, -> { order(created_at: :desc) }
end

# Query Object -- multi-condition, composable, testable
class Entities::SearchQuery
  def initialize(relation = Entity.all)
    @relation = relation
  end

  def call(params = {})
    @relation
      .then { |rel| filter_by_status(rel, params[:status]) }
      .then { |rel| filter_by_date(rel, params[:from_date]) }
      .then { |rel| search_by_name(rel, params[:q]) }
      .order(created_at: :desc)
  end

  private

  def filter_by_status(relation, status)
    return relation if status.blank?
    relation.where(status: status)
  end

  def filter_by_date(relation, from_date)
    return relation if from_date.blank?
    relation.where('created_at >= ?', from_date)
  end

  def search_by_name(relation, query)
    return relation if query.blank?
    relation.where('name ILIKE ?', "%#{sanitize_sql_like(query)}%")
  end
end

# Usage in controller
@entities = Entities::SearchQuery.new.call(params).page(params[:page])

Read the full file on GitHub · 85 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. 3mo ago First seen · 85 lines · 0 tokens per session scan A 8b1af882a4b8

Subscribe to this mod's changes

query-agent is an agent published in the GitHub repository ThibautBaissac/rails_ai_agents (676 stars, last pushed 6mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 675 tokens. 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

query-agent compared with agents from other repositories

query-agent next to 6 agents from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
query-agentThibautBaissac/rails_ai_agentsAgent6766mo agoMITA0Claude Code
cqrs-specialistmnzralee/claude-multi-agent-architectureAgent94d agoMITA0Claude Code
supabase-architectluanpdd/kit-mcpAgent52d agoMITA50Claude Code
evolution-go-integratorluanpdd/kit-mcpAgent52d agoMITA53Claude Code
backend-architecteinverne/dotfilesAgent121yesterdayGPL-3.0A41Claude Code
repositories-scaffoldervoro6yov/spec-driven-developmentAgent52mo agoApache-2.0A41Claude Code
database-session-scaffoldervoro6yov/spec-driven-developmentAgent52mo agoApache-2.0A49Claude Code