PluginBench
Skill
Official
Pass
Audit score 90

write-query

anthropics/knowledge-work-plugins

Write optimized SQL queries for your dialect with best practices and performance tuning.

What is write-query?

Translates natural-language data requests into production-ready SQL queries optimized for your specific database dialect (Snowflake, BigQuery, Postgres, etc.). Use this when you need to build queries with CTEs, joins, aggregations, or when optimizing performance on large partitioned tables.

  • Converts natural language descriptions into complete SQL queries with proper structure and formatting
  • Supports multiple SQL dialects including Snowflake, BigQuery, PostgreSQL, Redshift, Databricks, MySQL, SQL Server, DuckDB, and SQLite
  • Discovers and inspects database schema when a warehouse connector is available to build accurate queries
  • Applies performance best practices including partition filtering, early WHERE clauses, and appropriate JOIN types
  • Generates multi-CTE queries with descriptive naming and comments explaining non-obvious logic
  • Provides dialect-specific syntax and optimization recommendations

How to install write-query

npx skills add https://github.com/anthropics/knowledge-work-plugins --skill write-query
Claude Code
Cursor
Windsurf
Cline

How to use write-query

  1. 1.Invoke the skill with `/write-query` followed by a description of the data you need
  2. 2.Specify your SQL dialect (Snowflake, BigQuery, Postgres, etc.) if not already known in the session
  3. 3.Provide table names if you know them, or let the skill discover schema from connected warehouse
  4. 4.Review the generated query, explanation, and performance notes
  5. 5.Copy the query to run in your database, or request modifications for variations

Use cases

Good for
  • Translate a business question like 'count orders by status for the last 30 days' into optimized SQL
  • Build complex cohort analysis queries with multiple CTEs and window functions
  • Optimize queries against large partitioned tables by applying partition filters and performance tuning
  • Get correct syntax for dialect-specific functions and features across different database systems
  • Create parameterized queries for recurring analysis that can be adjusted for different time ranges or filters
Who it's for
  • Data analysts writing SQL queries against data warehouses
  • Engineers building analytics pipelines and reports
  • Product managers translating business questions into data queries
  • Anyone needing to optimize query performance on large datasets

write-query FAQ

What SQL dialects are supported?

PostgreSQL (Aurora, RDS, Supabase, Neon), Snowflake, BigQuery, Redshift, Databricks SQL, MySQL (Aurora, PlanetScale), SQL Server, DuckDB, SQLite, and others.

Can it discover my database schema automatically?

Yes, if a data warehouse MCP server is connected. The skill will search for relevant tables, inspect columns and types, and identify partitioning keys.

Does it handle complex queries with multiple CTEs and joins?

Yes. It structures complex queries using CTEs for readability, applies performance best practices like early filtering and appropriate JOIN types, and avoids common pitfalls like correlated subqueries.

What performance optimizations does it apply?

It filters early, uses partition filters when available, prefers EXISTS over IN for large subqueries, avoids SELECT *, and applies dialect-specific optimizations like Snowflake clustering or BigQuery partitioning.

Can it run the query for me?

If a data warehouse is connected, it can execute the query and analyze results. Otherwise, the query is ready to copy-paste into your database.

Full instructions (SKILL.md)

Source of truth, from anthropics/knowledge-work-plugins.


name: write-query description: Write optimized SQL for your dialect with best practices. Use when translating a natural-language data need into SQL, building a multi-CTE query with joins and aggregations, optimizing a query against a large partitioned table, or getting dialect-specific syntax for Snowflake, BigQuery, Postgres, etc. argument-hint: "<description of what data you need>"

/write-query - Write Optimized SQL

If you see unfamiliar placeholders or need to check which tools are connected, see CONNECTORS.md.

Write a SQL query from a natural language description, optimized for your specific SQL dialect and following best practices.

Usage

/write-query <description of what data you need>

Workflow

1. Understand the Request

Parse the user's description to identify:

  • Output columns: What fields should the result include?
  • Filters: What conditions limit the data (time ranges, segments, statuses)?
  • Aggregations: Are there GROUP BY operations, counts, sums, averages?
  • Joins: Does this require combining multiple tables?
  • Ordering: How should results be sorted?
  • Limits: Is there a top-N or sample requirement?

2. Determine SQL Dialect

If the user's SQL dialect is not already known, ask which they use:

  • PostgreSQL (including Aurora, RDS, Supabase, Neon)
  • Snowflake
  • BigQuery (Google Cloud)
  • Redshift (Amazon)
  • Databricks SQL
  • MySQL (including Aurora MySQL, PlanetScale)
  • SQL Server (Microsoft)
  • DuckDB
  • SQLite
  • Other (ask for specifics)

Remember the dialect for future queries in the same session.

3. Discover Schema (If Warehouse Connected)

If a data warehouse MCP server is connected:

  1. Search for relevant tables based on the user's description
  2. Inspect column names, types, and relationships
  3. Check for partitioning or clustering keys that affect performance
  4. Look for pre-built views or materialized views that might simplify the query

4. Write the Query

Follow these best practices:

Structure:

  • Use CTEs (WITH clauses) for readability when queries have multiple logical steps
  • One CTE per logical transformation or data source
  • Name CTEs descriptively (e.g., daily_signups, active_users, revenue_by_product)

Performance:

  • Never use SELECT * in production queries -- specify only needed columns
  • Filter early (push WHERE clauses as close to the base tables as possible)
  • Use partition filters when available (especially date partitions)
  • Prefer EXISTS over IN for subqueries with large result sets
  • Use appropriate JOIN types (don't use LEFT JOIN when INNER JOIN is correct)
  • Avoid correlated subqueries when a JOIN or window function works
  • Be mindful of exploding joins (many-to-many)

Readability:

  • Add comments explaining the "why" for non-obvious logic
  • Use consistent indentation and formatting
  • Alias tables with meaningful short names (not just a, b, c)
  • Put each major clause on its own line

Dialect-specific optimizations:

  • Apply dialect-specific syntax and functions (see sql-queries skill for details)
  • Use dialect-appropriate date functions, string functions, and window syntax
  • Note any dialect-specific performance features (e.g., Snowflake clustering, BigQuery partitioning)

5. Present the Query

Provide:

  1. The complete query in a SQL code block with syntax highlighting
  2. Brief explanation of what each CTE or section does
  3. Performance notes if relevant (expected cost, partition usage, potential bottlenecks)
  4. Modification suggestions -- how to adjust for common variations (different time range, different granularity, additional filters)

6. Offer to Execute

If a data warehouse is connected, offer to run the query and analyze the results. If the user wants to run it themselves, the query is ready to copy-paste.

Examples

Simple aggregation:

/write-query Count of orders by status for the last 30 days

Complex analysis:

/write-query Cohort retention analysis -- group users by their signup month, then show what percentage are still active (had at least one event) at 1, 3, 6, and 12 months after signup

Performance-critical:

/write-query We have a 500M row events table partitioned by date. Find the top 100 users by event count in the last 7 days with their most recent event type.

Tips

  • Mention your SQL dialect upfront to get the right syntax immediately
  • If you know the table names, include them -- otherwise Claude will help you find them
  • Specify if you need the query to be idempotent (safe to re-run) or one-time
  • For recurring queries, mention if it should be parameterized for date ranges

Related skills

More from anthropics/knowledge-work-plugins and the wider catalog.

WRwrite-spec logo

write-spec

Official
anthropics/knowledge-work-plugins

Transform vague ideas into structured feature specs and PRDs with goals, requirements, and success metrics.

2.2k installsAudited
ZOzoom-apps-sdk logo

zoom-apps-sdk

Official
anthropics/knowledge-work-plugins

Reference skill for Zoom Apps SDK. Use after routing to an in-client app workflow when building web apps that run inside Zoom meetings, webinars, the main client, or Zoom Phone.

1.1k installsAudited
ZOzoom-cobrowse-sdk logo

zoom-cobrowse-sdk

Official
anthropics/knowledge-work-plugins

Reference skill for Zoom Cobrowse SDK. Use after routing to a collaborative-support workflow when implementing browser co-browsing, annotation tools, privacy masking, remote assist, or PIN-based session sharing.

1.1k installs
ZOzoom-general logo

zoom-general

Official
anthropics/knowledge-work-plugins

Cross-product Zoom reference skill. Use after the workflow is clear when you need shared platform guidance, app-model comparisons, authentication context, scopes, marketplace considerations, or API-vs-MCP routing.

1.1k installs
ZOzoom-mcp logo

zoom-mcp

Official
anthropics/knowledge-work-plugins

Guidance for the bundled Zoom MCP connectors. Use after routing to an MCP workflow when planning or troubleshooting tool-based access to meetings, recordings, meeting assets, or transcripts. Route Zoom Docs requests to the dedicated Docs MCP server and Whiteboard-specific requests to `zoom-mcp/whiteboard`.

1.2k installs
ZOzoom-oauth logo

zoom-oauth

Official
anthropics/knowledge-work-plugins

Reference skill for Zoom authentication. Use after routing to an auth workflow when choosing app credentials, grant types, scopes, token refresh behavior, or debugging Zoom OAuth failures.

1.1k installs