{"slug": "query-inspector-a-claude-code-skill-for-extracting-and-tuning-sql-orm-queries", "title": "[query-inspector] A Claude Code skill for extracting and tuning SQL/ORM queries", "summary": "A developer released query-inspector, a Claude Code plugin that extracts SQL and ORM queries from a project's source and flags missing indexes, N+1 problems and anti-patterns before a commit rather than in production. The tool infers the SQL that JPA derived methods, @Query, QueryDSL, Kotlin JDSL and MyBatis dynamic queries will generate without executing them, labeling each query EXACT, INFERRED or AMBIGUOUS, and optionally runs a read-only EXPLAIN against a development database with production hosts blocked by default. It ships as two skills, tuning-report and inventory-report, and currently targets Kotlin/Java stacks with partial Python support.", "body_md": "**query-inspector** is a Claude Code skill that extracts the SQL/ORM queries from your project's source, then diagnoses and tunes **missing indexes / N+1 problems / anti-patterns**.\n\nQueries that run fine until the data piles up. N+1 problems that sail through code review. The real SQL your ORM generates, invisible in the code. It catches all of this right before you commit, not after it reaches production.\n\nThese problems share one trait: **they surface only after you ship.**\n\nquery-inspector moves that moment to just before the commit.\n\nIt's a Claude Code plugin, made of two skills:\n\n`tuning-report`` inventory-report`\nNeither one touches your code; they only produce reports.\n\nRun it right before a commit, and it surfaces performance problems that would otherwise appear only after you ship.\n\nThere were already ways to check query performance: runtime SQL logging (p6spy, Hibernate statistics) or APM. But those surface a problem only **after** the query runs.\n\nquery-inspector checks **before anything runs, on the changes you're about to commit**. Inferring the SQL an ORM will generate without executing it is an approach that only became practical with recent advances in AI.\n\nIt analyzes only **what changed since your last tuning**, not the whole project every time. That keeps it fast and lets it sit naturally in your usual `git add` -> run query-inspector -> commit flow.\n\nA full-project scan is available too.\n\nExplicit SQL is taken as-is, and for **JPA derived methods / `@Query` / QueryDSL / Kotlin JDSL / MyBatis dynamic queries** it infers the SQL that will actually be generated, then analyzes or catalogs it.\n\nEvery query carries an `EXACT` / `INFERRED` / `AMBIGUOUS` confidence label, so you know how far to trust each one.\n\nEven without a database it catches most problems (missing indexes / N+1s / SQL-dialect mismatches / anti-patterns).\n\nIt connects to your development database and runs a real **`EXPLAIN`** only when you want more certainty.\n\nFor safety, production hosts are blocked by default, and only read-only queries run.\n\nIt doesn't stop at \"this might be slow.\"\n\nYou get a **`CREATE INDEX` statement** with the right column order, the exact `file:line`, and copy-ready **Action Items**.\n\nA developer, or the AI assisting that developer, can read the report and start fixing right away.\n\nIt compares the previous run's suggestions against your current code and flags the ones **still not applied**.\n\nEven files you didn't touch this run are included in the check.\n\nThe current version focuses on Kotlin/Java (JPA, Hibernate, QueryDSL, MyBatis, native SQL). Python (Django/SQLAlchemy) is supported too, though not as thoroughly validated as the primary stacks.\n\nMore stacks are planned.\n\nSQL dialects (MySQL/MariaDB, PostgreSQL) are auto-detected.\n\nReports come out in the language you're chatting with Claude in (you can also force a specific one).\n\nA slice of what `tuning-report` produces after scanning your changes:\n\n```\n# Query Tuning Report - incremental (2 changed files)\n- Severity (open): 🔴 3 / 🟡 2 / ⚪ 1   /   Follow-up: ✅ 2 resolved / ⚠️ 2 still open\n\n## 🔴 [critical] Missing index - FK `orders.user_id` - OrderMapper.xml\n- Why critical: it is the N+1 child query, so every user triggers a full scan of `orders`.\n- Suggestion:  CREATE INDEX idx_orders_user_id ON orders (user_id);\n- Verify (live EXPLAIN): `type: ALL -> ref`.\n```\n\nPoint the same project at `inventory-report` and it lists the queries as a **catalog** instead of tuning:\n\n```\n# Query Inventory\n- Queries: 24 ( SELECT 18 / INSERT 3 / UPDATE 2 / DELETE 1 )\n\n#### [order-03] Orders for a given user\n- Source: OrderMapper.xml:42 (selectOrdersByUser) / Type: SELECT\n- Target: orders / Access columns: WHERE user_id, ORDER BY created_at\n- Index coverage: ❌ uncovered (no index on user_id)\n```\n\nUse the tuning report to find what to fix, and the inventory to see everything that runs.\n\nInstall and usage are in the GitHub README: [github.com/jogakdal/query-inspector](https://github.com/jogakdal/query-inspector)\n\nIf you have Claude Code, you can install it with these two commands:\n\n```\nclaude plugin marketplace add jogakdal/query-inspector\nclaude plugin install query-inspector@query-inspector-marketplace\n```\n\nWant to see the output first? Browse the [sample report](https://github.com/jogakdal/query-inspector/blob/main/examples/sample-report.md) and the [Docker example](https://github.com/jogakdal/query-inspector/tree/main/examples/docker-mysql) in the repo.\n\nIt's still v1.0.0. After trying it, please file feedback via [GitHub issues](https://github.com/jogakdal/query-inspector/issues) and it'll go into the next iteration; a star is welcome if you find it useful.\n\nRun it before your next commit.", "url": "https://wpnews.pro/news/query-inspector-a-claude-code-skill-for-extracting-and-tuning-sql-orm-queries", "canonical_source": "https://dev.to/jogakdal/query-inspector-a-claude-code-skill-for-extracting-and-tuning-sqlorm-queries-172d", "published_at": "2026-10-06 00:55:48+00:00", "updated_at": "2026-10-06 01:17:32.638869+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-agents", "mlops"], "entities": ["Claude Code", "query-inspector", "JPA", "Hibernate", "QueryDSL", "MyBatis", "Kotlin JDSL", "GitHub"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/query-inspector-a-claude-code-skill-for-extracting-and-tuning-sql-orm-queries", "markdown": "https://wpnews.pro/news/query-inspector-a-claude-code-skill-for-extracting-and-tuning-sql-orm-queries.md", "text": "https://wpnews.pro/news/query-inspector-a-claude-code-skill-for-extracting-and-tuning-sql-orm-queries.txt", "jsonld": "https://wpnews.pro/news/query-inspector-a-claude-code-skill-for-extracting-and-tuning-sql-orm-queries.jsonld"}}