ash-query-optimizer

ash-query-optimizer is an agent for Claude Code from oliver-kriska/claude-elixir-phoenix. It costs 45 tokens per session (2,556 once invoked), scanned A, original, MIT.

A review agent for Ash Framework queries, where Ash is an Elixir framework for building data-driven applications. It looks for inefficient data loading, including N+1 queries, which repeat database work unnecessarily.

In plain words
What is it for?
Use it when reviewing Ash queries, LiveView data loading, or domain actions to find problems with counts, sums, existence checks, loops, and calculated values.
Why use it?
It highlights ways a query may fetch more data or make more database requests than needed, without changing the source code.

Agent for Claude Code

Written for Claude Code: effort in frontmatter. Also seen: model in frontmatter; names the NotebookEdit tool.

Part of the phx plugin — 50 skills, 26 agents, 8 hooks shipped together

Good fit Use it when reviewing Ash queries, LiveView data loading, or domain actions to find problems with counts, sums, existence checks, loops, and calculated values.

Compare 6 agents from other repositories ↓
Install with agentmods
npx agentmods add agents/oliver-kriska/claude-elixir-phoenix/ash-query-optimizer
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/oliver-kriska/claude-elixir-phoenix

Made for: Claude Code.

Or install phx, the plugin that ships this one along with the rest of its 50 skills, 26 agents, 8 hooks.

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 ash-query-optimizer

README.md
[![agentmods](https://agentmods.dev/badge/agents/oliver-kriska/claude-elixir-phoenix/ash-query-optimizer/github.svg)](https://agentmods.dev/agents/oliver-kriska/claude-elixir-phoenix/ash-query-optimizer)
Your own site
<a href="https://agentmods.dev/agents/oliver-kriska/claude-elixir-phoenix/ash-query-optimizer"><img src="https://agentmods.dev/badge/agents/oliver-kriska/claude-elixir-phoenix/ash-query-optimizer/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 ash-query-optimizer

Your own site · 80×15
<a href="https://agentmods.dev/agents/oliver-kriska/claude-elixir-phoenix/ash-query-optimizer"><img src="https://agentmods.dev/badge/agents/oliver-kriska/claude-elixir-phoenix/ash-query-optimizer.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 45 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,556 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.00045 $0.02556
Opus 5.5 $0.00018 $0.01022
Sonnet 5.5 $0.00009 $0.00511
Haiku 4.5 $0.00005 $0.00256

Measured 19d ago against content hash 91b6744b3883, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

ash-query-optimizer 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 19d 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.

plugins/elixir-phoenix/agents/ash-query-optimizer.md · 270 lines

How it starts

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

Ash Query Optimizer

Detect N+1 patterns, load/aggregate/calculation mismatches, and inefficient data fetching in Ash Framework projects. Output is a findings file; you do not modify source code.

CRITICAL: Save Findings File First

Turn budget:

  1. First ~8 turns: Grep for load patterns in LiveViews and domain modules
  2. By turn ~10: Write initial findings — partial file beats no file
  3. Remaining turns: Deepen analysis with read/aggregate/combination alternatives

Default output path if none given: .claude/reviews/ash-query-opt.md

Iron Laws — Flag All Violations

  1. NO LOAD FOR COUNT/SUM — Ash.load(records, [:children]) followed by Enum.count/length/Enum.sum is an N+1; declare or inline an aggregate (count, sum, avg, min, max, list, first)
  2. EXISTS, NOT count > 0 — Presence checks must use the exists aggregate or exists/2 in expressions; count > 0 scans every matching row instead of short-circuiting
  3. NO LOADING IN LOOPS — Ash.load!/2, Ash.read!, or a domain action inside Enum.map/each/reduce is an N+1; batch with a single load or a bulk action
  4. DERIVED VALUES → CALCULATIONS — Values computed from attributes or relationships belong in a calculation on the resource, not post-load Map.put/Enum.map in callers. Calculations stay filterable and sortable in the query layer
  5. CUSTOMIZE LOADS WITH QUERIES, NOT POST-FILTERS — Filtering a loaded relationship with Enum.filter after Ash.load wastes a DB round trip; pass a query to load: Ash.load(users, posts: Ash.Query.filter(Post, published == true))
  6. SELECT FOR LARGE RESOURCES — Reading a resource with 20+ attributes when only a few are needed should use Ash.Query.select/2
  7. NO DIRECT REPO CALLS — MyApp.Repo.all/aggregate/one in resource-backed code skips policies, calculations, and aggregates; use Ash actions or Ash.aggregate
  8. PIN USER INPUT WITH ^ — Same rule as Ecto; user input in filter expr(...) must be pinned, not interpolated

Read the full file on GitHub · 270 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. 19d ago Changed · -1 lines 91b6744b3883
  2. 1mo ago First seen · 271 lines · 45 tokens per session scan A ba0317363332

Subscribe to this mod's changes

ash-query-optimizer is an agent published in the GitHub repository oliver-kriska/claude-elixir-phoenix (568 stars, last pushed today), licensed MIT. It adds 45 tokens to every session and 2,556 once invoked, about $0.0002 per session on Opus 5.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 agents, from other repositories

bug-investigator

Use when a bug, regression, or unexpected behaviour needs its root cause traced to specific code before any fix is designed. Investigates only — never edits files. Returns a structured report citing file:line evidence.

kardebadas/claude-plugin · 46 tokens

query-optimizer

Use this agent to optimize slow database queries, analyze EXPLAIN plans, and recommend index or query rewrites. Trigger when the user mentions "slow query", "optimize query", "EXPLAIN plan", "query performance", "database is slow", "N+1 queries", "index recommendation", or asks why a query takes too long. Examples…

iwritec0de/app-dev · 122 tokens

data-model-architect

Use when an orchestrator needs a Dataverse data model proposed (existing-table reuse, new tables in dependency-tier order, Mermaid ER diagram) for embedding in native-app-plan.md. Read-only — proposes, never mutates. Called by native-app-planner and /edit-app; not invoked directly by users.

microsoft/power-platform-skills · 67 tokens

data-engineer

Adversarial data and database engineer who assumes the design is mis-normalized and indexed for a workload that does not exist. Audits schemas, migrations, queries, ORM code, document shapes, stream contracts, and pipelines against normalization, dimensional modeling, key-value access patterns, columnar and…

testdouble/han · 216 tokens

doctrine-performance-optimizer

Read-only performance audit of Doctrine usage: N+1 queries, fetch modes, batch processing, missing indexes, and caching opportunities. Use proactively after adding entities, relations, repository queries, or when a page/endpoint is reported slow.

dev-toolings/superpowers-symfony · 53 tokens

craft-code-reviewer-deep

Deep code review on Opus for high-stakes PRs — release branches, security-sensitive code, large architectural changes, migrations, multi-service flows. Read-only. Use when extra scrutiny is worth the token cost; use craft-code-reviewer for daily review.

michtio/craftcms-claude-skills · 61 tokens