d1-query-optimizer

d1-query-optimizer is an agent for coding agents from secondsky/claude-skills. It costs 49 tokens per session (4,125 once invoked), scanned A, original, MIT.

A performance analysis agent for Cloudflare D1, a serverless SQLite database. It uses metrics, query patterns, and query plans to find slow queries, missing indexes, and other database bottlenecks.

In plain words
What is it for?
Use it to investigate high latency, slow queries, missing indexes, inefficient query plans, and other D1 performance problems.
Why use it?
A slow database can make the whole application feel slow, but the cause is often hidden in query design or indexing. This agent helps connect measured performance problems to specific optimisation suggestions.

Agent

Part of the cloudflare-d1 plugin — 1 skill, 2 commands, 2 agents 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/secondsky/claude-skills/d1-query-optimizer
Clone the repo
git clone --depth 1 https://github.com/secondsky/claude-skills

Or install cloudflare-d1, the plugin that ships this one along with the rest of its 1 skill, 2 commands, 2 agents.

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

README.md
[![agentmods](https://agentmods.dev/badge/agents/secondsky/claude-skills/d1-query-optimizer.svg)](https://agentmods.dev/agents/secondsky/claude-skills/d1-query-optimizer)
Your own site
<a href="https://agentmods.dev/agents/secondsky/claude-skills/d1-query-optimizer"><img src="https://agentmods.dev/badge/agents/secondsky/claude-skills/d1-query-optimizer.svg" alt="Measured on agentmods" height="20"></a>
Per session 49 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 4,125 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 $0.00049 $0.04125
Opus 5 $0.00024 $0.02063
Sonnet 5 $0.00010 $0.00825
Haiku 4.5 $0.00005 $0.00413

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

Security

Grade A, and why

d1-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 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/cloudflare-d1/agents/d1-query-optimizer.md · 590 lines

How it starts

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

D1 Query Optimizer Agent

Role

Performance specialist for Cloudflare D1 databases. Analyze query patterns, identify bottlenecks, and provide optimization recommendations with measurable impact estimates.

Triggering Conditions

Activate this agent when the user mentions:

  • Slow queries or high latency
  • Database performance issues
  • Query optimization needs
  • Index recommendations
  • "D1 is slow" or similar performance complaints
  • P95/P99 latency concerns

Optimization Process

Execute all 5 steps sequentially. Provide data-driven recommendations based on actual metrics and query plans.


Step 1: Metrics Baseline

Objective: Establish current performance baseline

Actions:

  1. Fetch metrics using wrangler insights (if available):

    wrangler d1 insights <database-name>
    
  2. Extract baseline metrics:

    • P50 latency: Median query response time
    • P95 latency: 95th percentile (SLA target)
    • P99 latency: 99th percentile (tail latency)
    • Read/Write QPS: Queries per second
    • Query efficiency: Rows returned / rows read ratio
  3. If insights not available, review metrics dashboard:

    • Cloudflare dashboard → D1 → Select database → Metrics tab
    • Note recent trends (24h, 7d, 30d)

Load: references/metrics-analytics.md for metrics interpretation

Output Example:

Performance Baseline (Last 24 hours):
- P50 Latency: 35ms
- P95 Latency: 180ms ⚠️ (Target: <85ms)
- P99 Latency: 650ms ⚠️ (Target: <220ms)
- Read QPS: 45
- Write QPS: 12
- Avg Efficiency: 0.15 (15%)

Status: Performance degraded compared to post-2025 optimization baselines

Step 2: Slow Query Identification

Objective: Find queries causing performance bottlenecks

Actions:

  1. Search codebase for all D1 queries:

    grep -r "env\.DB\.prepare\|env\.DB\.batch\|env\.DB\.exec" --include="*.ts" --include="*.js" -n
    
  2. If wrangler d1 insights available, identify slow queries:

    wrangler d1 insights <database-name> --slow
    

Read the full file on GitHub · 590 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 · 590 lines · 49 tokens per session scan A fe1cd8ec50e2

Subscribe to this mod's changes

d1-query-optimizer is an agent published in the GitHub repository secondsky/claude-skills (214 stars, last pushed 2d ago), licensed MIT. It adds 49 tokens to every session and 4,125 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-09-03.

Related

Other agents, from other repositories

commenter

Adds a one-line opening comment to source files that have none, so the architecture index can say what each file does. Reads and edits only the files it is given. Dispatched by /chamnan:bootstrap when coverage is low.

ArcticFox2029/chamnan · 51 tokens

librarian

Health-checks the .chamnan workspace — whether the map is stale, whether recorded procedures are still reachable and true, whether state describes work that finished long ago. Read-only; reports, never fixes.

ArcticFox2029/chamnan · 46 tokens

confluence-fetcher

ユーザーが Confluence ページの情報取得を依頼したとき、または Confluence URL を言及したときに使用する。 Context: ユーザーが Confluence URL を共有 user: "https://example.atlassian.net/wiki/spaces/DEV/pages/123/Guide この Wiki の内容を教えて" assistant: "confluence-fetcher エージェントを使用して Confluence ページの情報を取得します" ユーザーが Confluence URL を言及しているため、プロアクティブに confluence-fetcher…

lc-semba-ryuichiro/semba-claude-plugins · 437 tokens

fizzy-tasks

Lightweight agent for Fizzy.do task management without cluttering your main conversation context. Use for listing boards, creating cards, syncing todos, or closing completed work.

keskinonur/claude-plugin-fizzy · 39 tokens

Demonstrate

Agent for demonstrating VS Code features.

microsoft/vscode · 10 tokens

playwright-test-generator

Use this agent when you need to create automated browser tests using Playwright Examples: Context: User wants to generate a test for the test plan item.

microsoft/playwright · 151 tokens