tune-a-query

tune-a-query is a skill for Claude Code from erikdarlingdata/claude-plugins. It costs 66 tokens per session (2,144 once invoked), scanned A, original, MIT.

A guided method for investigating and improving one slow SQL Server query or stored procedure. SQL Server is Microsoft's database system; the method examines its history and execution plans, then tests alternatives on a database copy.

In plain words
What is it for?
Use it for a named slow query, query ID, stored procedure, screen, or report to compare versions and recommend an improvement.
Why use it?
It helps explain why a read query is slow without running the investigation query on production. Testing on a copy reduces the risk of affecting users or changing live data.

Skill for Claude Code

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

Part of the sqlserver-tune-a-query plugin — 1 skill shipped together

Good fit Use it for a named slow query, query ID, stored procedure, screen, or report to compare versions and recommend an improvement.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/erikdarlingdata/claude-plugins/tune-a-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 erikdarlingdata/claude-plugins --skill tune-a-query
Clone the repo
git clone --depth 1 https://github.com/erikdarlingdata/claude-plugins

Made for: Claude Code.

Or install sqlserver-tune-a-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 tune-a-query

README.md
[![agentmods](https://agentmods.dev/badge/skills/erikdarlingdata/claude-plugins/tune-a-query/github.svg)](https://agentmods.dev/skills/erikdarlingdata/claude-plugins/tune-a-query)
Your own site
<a href="https://agentmods.dev/skills/erikdarlingdata/claude-plugins/tune-a-query"><img src="https://agentmods.dev/badge/skills/erikdarlingdata/claude-plugins/tune-a-query/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 tune-a-query

Your own site · 80×15
<a href="https://agentmods.dev/skills/erikdarlingdata/claude-plugins/tune-a-query"><img src="https://agentmods.dev/badge/skills/erikdarlingdata/claude-plugins/tune-a-query.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 66 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,144 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.00066 $0.02144
Opus 5.5 $0.00026 $0.00858
Sonnet 5.5 $0.00013 $0.00429
Haiku 4.5 $0.00007 $0.00214

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

Security

Grade A, and why

tune-a-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 yesterday.

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/sqlserver-tune-a-query/skills/tune-a-query/SKILL.md · 87 lines

How it starts

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

Tune a query

Do the steps in order. Do not write a rewrite before step 4.

Steps 3 to 5 run queries. Run them on a copy of the database, never on production. The copy is a restored or cloned database on a server that no user depends on. If you do not know which server is the copy, ask before you run anything.

Steps 1 and 2, and getting the repro script in step 3, only read. On production, run only the sources that those steps name. Do not install anything on production, and do not run the slow query there.

This skill is for queries that read data. If the slow statement changes data (INSERT, UPDATE, DELETE or MERGE), ask the user how to test it on the copy.

1. Find it

  • Get the query text, its plans and its runtime history. Use the first source that you have:
    • The Performance Monitor MCP server (Lite or Darling): get_top_queries_by_cpu, get_top_procedures_by_cpu, get_query_store_top and get_query_trend. Tool names change between versions, so read the server's tool list first.
    • sp_QuickieStore for Query Store data, or sp_QuickieCache for the plan cache. Both are in Erik Darling's DarlingData repository.
    • The Query Store views: sys.query_store_query, sys.query_store_plan and sys.query_store_runtime_stats.
  • Record how often it runs, how long it takes, and whether that changed recently.
  • If it got slow on a specific day, look for what changed that day before you rewrite anything. Examples are a new plan, a deployment, a statistics update and a large data load. A query that got slow last Tuesday is a different problem from a query that was always slow.

2. Read the plan

  • Read the plan with a plan tool. Do not read the plan XML yourself. Use the sqlserver-query-plans plugin, the Performance Studio MCP server, or analyze_query_plan on the Performance Monitor MCP server.
  • Write down where the time goes: operator times, estimated rows against actual rows, spills and waits.
  • Cost percentages are estimates. If you have actual operator times, ignore the cost percentages.
  • A plan from the plan cache or Query Store has no actual row counts and no operator times. After step 3, get the actual plan from the copy and read it the same way.

Read the full file on GitHub · 87 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. yesterday First seen · 87 lines · 66 tokens per session scan A d2ca1460f118

Subscribe to this mod's changes

tune-a-query is a skill published in the GitHub repository erikdarlingdata/claude-plugins (33 stars, last pushed yesterday), licensed MIT. It adds 66 tokens to every session and 2,144 once invoked, about $0.0003 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-12-01.

Related

tune-a-query compared with skills from other repositories

tune-a-query next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
tune-a-queryerikdarlingdata/claude-pluginsSkill33yesterdayMITA66Claude Code
triage-issuesgoogleapis/mcp-toolboxSkill17ktodayApache-2.0A164Claude Code, Codex
postgresql-indexingprowler-cloud/prowlerSkill15kyesterdayApache-2.0A108Claude Code
sql-optimization-patternssickn33/agentic-awesome-skillsSkill51kyesterdayMITA28Claude Code
graphjin-evaldosco/graphjinSkill3.2k4d agoApache-2.0A27Claude Code, Codex
axiom-audit-grdb-performanceCharlesWiltgen/AxiomSkill1.3kyesterdayMITA43Codex
byted-bytehouse-slow-querybytedance/agentkit-samplesSkill4962d agoApache-2.0A74Claude Code, Codex