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,562 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, 10 hooks shipped together

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.

agentmods
npx agentmods add agents/oliver-kriska/claude-elixir-phoenix/ash-query-optimizer
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, 10 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.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.svg" alt="Measured on agentmods" 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,562 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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.02562
Opus 5 $0.00023 $0.01281
Sonnet 5 $0.00009 $0.00512
Haiku 4.5 $0.00005 $0.00256

Measured 6d ago against content hash ba0317363332, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, 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 6d 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 · 271 lines

How it starts

The opening of the file, as written. The whole thing — 271 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/SUMAsh.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 LOOPSAsh.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 CALLSMyApp.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 · 271 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. 6d 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 (538 stars, last pushed yesterday), licensed MIT. It adds 45 tokens to every session and 2,562 once invoked, about $0.0002 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 agents, from other repositories

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

genpage-entity-builder

Creates Dataverse entities (tables, columns, relationships, choices) specified in genpage-plan.md using the plugin's Node.js Web API scripts. Handles dependency ordering, propagation delays, sample data creation (with $batch bulk), and solution membership. Called by the genpage skill when new entities need creating …

microsoft/power-platform-skills · 73 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

craft-planner

Breaks down large tasks into manageable implementation steps for Craft CMS plugin development.

michtio/craftcms-claude-skills · 18 tokens

craft-code-reviewer-deep

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

michtio/craftcms-claude-skills · 62 tokens

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