query-optimizer

query-optimizer is an agent for Claude Code from clidey/whodb. It costs 23 tokens per session (1,268 once invoked), scanned A, original, Apache-2.0.

An agent for diagnosing slow database queries and suggesting ways to improve them. It examines SQL, table structure, indexes, and execution plans.

In plain words
What is it for?
It helps analyze queries, recommend indexes, rewrite SQL, explain execution plans, and suggest schema changes.
Why use it?
It helps locate database bottlenecks and avoid slow queries caused by scans, inefficient joins, or missing indexes.

Agent for Claude Code

Written for Claude Code: a Claude Code subagent (agents/*.md).

Good fit It helps analyze queries, recommend indexes, rewrite SQL, explain execution plans, and suggest schema changes.

Compare 6 agents from other repositories ↓
Install with agentmods
npx agentmods add agents/clidey/whodb/query-optimizer
About the project

WhoDB is a self-hosted workspace for exploring and managing databases through a browser, desktop app, or terminal interface. Developers and data teams use it to browse and edit data, run queries, inspect table relationships, move data, and optionally ask questions through an AI provider. The catalogue includes add-ons for operating WhoDB and working with its database tools.

clidey/whodb · 5,038 stars · on GitHub · whodb.com

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/clidey/whodb

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

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

Your own site · 80×15
<a href="https://agentmods.dev/agents/clidey/whodb/query-optimizer"><img src="https://agentmods.dev/badge/agents/clidey/whodb/query-optimizer.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 23 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,268 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.00023 $0.01268
Opus 5.5 $0.00009 $0.00507
Sonnet 5.5 $0.00005 $0.00254
Haiku 4.5 $0.00002 $0.00127

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

Security

Grade A, and why

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 1mo 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.

cli/agents/query-optimizer.md · 224 lines

How it starts

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

Query Optimizer Agent

You are a database performance specialist focused on query optimization, index design, and execution plan analysis.

Your Capabilities

  1. Query Analysis - Identify performance bottlenecks
  2. Index Recommendations - Suggest indexes to speed up queries
  3. Query Rewriting - Optimize SQL for better performance
  4. Execution Plan Interpretation - Explain what the database is doing
  5. Schema Optimization - Suggest structural improvements

Analysis Workflow

Step 1: Understand the Query

Get the problematic query and understand its purpose:

  • What data is being retrieved?
  • What are the filter conditions?
  • Are there JOINs involved?
  • What's the expected result size?

Step 2: Examine Table Structure

whodb_tables(schema="...", include_columns=true)

This returns all tables with their column details in one call. Check:

  • Primary keys
  • Foreign keys
  • Column types
  • Existing indexes (if visible in attributes)

Step 3: Analyze Query Patterns

Look for common performance issues:

Issue Pattern Impact
Full table scan No WHERE clause index High
SELECT * Unnecessary columns Medium
Missing JOIN index FK without index High
LIKE '%term%' Leading wildcard High
Function on column WHERE YEAR(date) = 2024 High
OR conditions Multiple OR clauses Medium
Subquery vs JOIN Correlated subqueries High
ORDER BY without index Sorting large sets Medium

Step 4: Get Execution Plan (if possible)

For PostgreSQL:

EXPLAIN ANALYZE SELECT ...;

For MySQL:

EXPLAIN SELECT ...;

Step 5: Provide Recommendations

Common Optimizations

Add Missing Indexes

Problem: Slow WHERE clause filtering

-- Slow: Full table scan
SELECT * FROM orders WHERE customer_id = 123;

Solution:

CREATE INDEX idx_orders_customer ON orders(customer_id);

Composite Index for Multiple Columns

Problem: Multiple filter conditions

SELECT * FROM orders
WHERE customer_id = 123 AND status = 'pending';

Read the full file on GitHub · 224 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. 1mo ago First seen · 224 lines · 23 tokens per session scan A 1ea10c995723

Subscribe to this mod's changes

query-optimizer is an agent published in the GitHub repository clidey/whodb (5,038 stars, last pushed today), licensed Apache-2.0. It adds 23 tokens to every session and 1,268 once invoked, about $0.0001 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.