Agent skill

Expensive Snowflake Query Finder

by AltimateAI in AltimateAI/data-engineering-skills

Ranks the costliest, slowest or heaviest-scanning Snowflake queries from query history and suggests how to optimize them.

MITAuto-check passedDatabases

Install Expensive Snowflake Query Finder

skills CLI
$ npx skills add AltimateAI/data-engineering-skills --skill finding-expensive-queries -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install AltimateAI/data-engineering-skills finding-expensive-queries --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/AltimateAI/data-engineering-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/snowflake/finding-expensive-queries .claude/skills/finding-expensive-queries && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
finding-expensive-queries
GitHub stars
128
Token cost
~662 tokens
SKILL.md length
122 words
Files
1
Skills in repo
12
Repo updated
First seen
Licence
MIT

At a glance

Ranks the costliest, slowest or heaviest-scanning Snowflake queries from query history and suggests how to optimize them.

  • Works in 5 steps: Ask What to Optimize For → Find Expensive Queries by Cost → Get Performance Stats for Specific Queries → …
  • Finding the slowest or costliest queries from the last week
  • SKILL.md covers Workflow and Common Filters
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

The agent first asks what to optimize for: the time period, the metric (execution time, bytes scanned, cost or spillage), and whether to look at one warehouse or user or at all of them. It then queries `QUERY_ATTRIBUTION_HISTORY` for credit and cost analysis and `QUERY_HISTORY` for performance stats on specific queries, running the two separately rather than joining them.

Pattern checks look for queries with high compute credits, a repeated `query_hash` that points to a caching opportunity, scans where partitions scanned equals partitions total so nothing was pruned, and high gigabytes spilled under memory pressure. The answer is a ranked list of queries with key metrics, the common patterns, three to five optimization recommendations and specific queries to investigate next. A time range filter is always applied.

When your agent uses it

  • Finding the slowest or costliest queries from the last week
  • Looking for queries that scan the most data or spill to disk
  • Picking optimization candidates when warehouse costs rise

Example prompts

  • “Show the ten most expensive Snowflake queries from the last seven days by credits.”
  • “Which queries on the ANALYTICS_WH warehouse spill the most data to disk?”
  • “Find repeated queries in our history that would benefit from caching.”

Requirements

  • A Snowflake account with access to `QUERY_HISTORY` and `QUERY_ATTRIBUTION_HISTORY`

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Ask What to Optimize For
  2. Find Expensive Queries by Cost
  3. Get Performance Stats for Specific Queries
  4. Identify Patterns
  5. Return Results

What it can do on your machine

Read from SKILL.md and the folder at commit 705c68b. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are sql).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Expensive Snowflake Query Finder loads about 662 tokens when it runs. Until then it costs about 120 tokens; SKILL.md has 122 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~120
When it runs · the whole SKILL.md, loaded when a task matches
~662

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from AltimateAI/data-engineering-skills at commit 705c68b, republished under its MIT licence (© AltimateAI). 122 words, ~662 tokens.

Download SKILL.mdSave it as .claude/skills/finding-expensive-queries/SKILL.md (or your agent's skills folder).
name
finding-expensive-queries
description
Finds and ranks expensive Snowflake queries by cost, time, or data scanned. Use when: (1) User asks to find slow, expensive, or problematic queries (2) Task mentions "query history", "top queries", "most expensive", or "slowest queries" (3) Analyzing warehouse costs or identifying optimization candidates (4) Finding queries that scan the most data or have the most spillage Returns ranked list of queries with metrics and optimization recommendations.

Finding Expensive Queries

Query history → Rank by metric → Identify patterns → Recommend optimizations

Workflow

1. Ask What to Optimize For

Before querying, clarify:

  • Time period? (last day, week, month)
  • Metric? (execution time, bytes scanned, cost, spillage)
  • Warehouse? (specific or all)
  • User? (specific or all)
2. Find Expensive Queries by Cost

Use QUERY_ATTRIBUTION_HISTORY for credit/cost analysis:

sql
SELECT
    query_id,
    warehouse_name,
    user_name,
    credits_attributed_compute,
    start_time,
    end_time,
    query_tag
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_ATTRIBUTION_HISTORY
WHERE start_time >= DATEADD('days', -7, CURRENT_TIMESTAMP())
ORDER BY credits_attributed_compute DESC
LIMIT 20;
3. Get Performance Stats for Specific Queries

Use QUERY_HISTORY for detailed performance metrics (run separately, not joined):

sql
SELECT
    query_id,
    query_text,
    total_elapsed_time/1000 as seconds,
    bytes_scanned/1e9 as gb_scanned,
    bytes_spilled_to_local_storage/1e9 as gb_spilled_local,
    bytes_spilled_to_remote_storage/1e9 as gb_spilled_remote,
    partitions_scanned,
    partitions_total
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
WHERE query_id IN ('<query_id_1>', '<query_id_2>', ...)
  AND start_time >= DATEADD('days', -7, CURRENT_TIMESTAMP());
4. Identify Patterns

Look for:

  • High credits_attributed_compute queries
  • Same query_hash repeated (caching opportunity)
  • partitions_scanned = partitions_total (no pruning)
  • High gb_spilled (memory pressure)
5. Return Results

Provide:

  1. Ranked list of expensive queries with key metrics
  2. Common patterns identified
  3. Top 3-5 optimization recommendations
  4. Specific queries to investigate further

Common Filters

sql
-- Time range (required)
WHERE start_time >= DATEADD('days', -7, CURRENT_TIMESTAMP())

-- By warehouse
AND warehouse_name = 'ANALYTICS_WH'

-- By user
AND user_name = 'ETL_USER'

-- Only queries over cost threshold
AND credits_attributed_compute > 0.01

-- Only queries over time threshold
AND total_elapsed_time > 60000  -- over 1 minute

© AltimateAI, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/snowflake/finding-expensive-queries of AltimateAI/data-engineering-skills.

Open the folder on GitHubat commit 705c68b

Compare with similar skills

Expensive Snowflake Query Finder next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Expensive Snowflake Query Finder compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Expensive Snowflake Query Finder this skillAltimateAI/data-engineering-skills128—~662Automated safety check: PassMIT
Snowflake Developmentsickn33/agentic-awesome-skills47k2 repos~2.1kAutomated safety check: PassMIT
Snowflake Developmentalirezarezvani/claude-skills28k—~3.2kAutomated safety check: PassMIT
Uipath Process MiningUiPath/skills168—~4.3kAutomated safety check: NotesMIT
Dynamic Tables TutorialKilo-Org/kilo-marketplace190—~2.8kAutomated safety check: PassApache-2.0
Pytorch Clickhousepytorch/test-infra113—~2.8kAutomated safety check: PassCustom licence

Similar skills

  • Snowflake Development

    sickn33/agentic-awesome-skills

    Comprehensive Snowflake development assistant covering SQL best practices, data pipeline design (Dynamic Tables, Streams, Tasks, Snowpipe), Cortex AI functions, Cortex Agents, Snowpark Python, dbt…

    47k GitHub starsUsed in 2 repos~2.1k tokens
    DatabasesAuto-check passed
  • Snowflake Development

    alirezarezvani/claude-skills

    A skill your agent uses when writing Snowflake SQL, building data pipelines with Dynamic Tables or Streams/Tasks, using Cortex AI functions, creating Cortex Agents, writing Snowpark Python…

    28k GitHub stars~3.2k tokensUpdated 1 mo ago
    DatabasesAuto-check passed
  • UiPath Process Mining via uip pm — build and operate a process app end-to-end from a CSV / event log: templates, data mapping, upload, ingest, the dbt (Snowflake) transformation layer, publish, and…

    168 GitHub stars~4.3k tokensUpdated today
    DatabasesAuto-check: notes
  • Dynamic Tables Tutorial

    Kilo-Org/kilo-marketplace

    Interactive tutorial that teaches Snowflake Dynamic Tables hands-on.

    190 GitHub stars~2.8k tokensUpdated 11 days ago
    DatabasesAuto-check passed
  • Pytorch Clickhouse

    pytorch/test-infra

    Load this FIRST whenever working with PyTorch CI data (any pytorch/ org repo), the torchci/HUD codebase, or the PyTorch HUD ClickHouse database.

    113 GitHub stars~2.8k tokensUpdated today
    DatabasesAuto-check passed
  • Official

    Analyzes BigQuery slot use, query costs and execution bottlenecks from INFORMATION_SCHEMA to diagnose slow queries, slot contention and unpartitioned scans.

    21k GitHub stars~2.3k tokensUpdated today
    DatabasesAuto-check passed

More from AltimateAI/data-engineering-skills

All 12 skills in this repo
  • Altimate Data Warehouse Delegate

    AltimateAI/data-engineering-skills

    Delegates dbt and warehouse tasks such as lineage, migrations and cost attribution to the altimate-code CLI agent and relays its answer back.

    128 GitHub stars~1.4k tokensUpdated yesterday
    Auto-check passed
  • dbt Model Builder

    AltimateAI/data-engineering-skills

    Creates or modifies dbt models in line with a project's own conventions, then runs dbt build and dbt show to check the output instead of stopping at compile.

    128 GitHub stars~890 tokensUpdated yesterday
    Auto-check passed
  • dbt Error Debugging

    AltimateAI/data-engineering-skills

    Walks through fixing dbt compilation, database and test errors: read the full error, check upstream models, apply a fix, then verify with dbt build and a data preview.

    128 GitHub stars~1.1k tokensUpdated yesterday
    Auto-check passed
  • dbt Incremental Models

    AltimateAI/data-engineering-skills

    Helps choose an incremental strategy, design a reliable unique_key and debug failing dbt incremental models, and says when a plain table is the better choice.

    128 GitHub stars~2.3k tokensUpdated yesterday
    Auto-check passed
  • dbt Model Documentation

    AltimateAI/data-engineering-skills

    Writes model and column descriptions in dbt schema.yml files, matching the project's existing documentation style and recording grain, business rules and caveats.

    128 GitHub stars~1.2k tokensUpdated yesterday
    Auto-check passed
  • Migrating SQL To Dbt

    AltimateAI/data-engineering-skills

    Converts legacy SQL to modular dbt models. An agent skill from AltimateAI/data-engineering-skills.

    128 GitHub stars~762 tokensUpdated yesterday
    Auto-check passed

Works with

Questions about Expensive Snowflake Query Finder

What does Expensive Snowflake Query Finder do?

Ranks the costliest, slowest or heaviest-scanning Snowflake queries from query history and suggests how to optimize them. The agent first asks what to optimize for: the time period, the metric (execution time, bytes scanned, cost or spillage), and whether to look at one warehouse or user or at all of them. It then queries `QUERY_ATTRIBUTION_HISTORY` for credit and cost analysis and `QUERY_HISTORY` for performance stats on specific queries, running the two separately rather than joining them.

When should I use Expensive Snowflake Query Finder?

Expensive Snowflake Query Finder fits situations like: finding the slowest or costliest queries from the last week; looking for queries that scan the most data or spill to disk; picking optimization candidates when warehouse costs rise.

How do I install Expensive Snowflake Query Finder in Claude Code?

Run `npx skills add AltimateAI/data-engineering-skills --skill finding-expensive-queries -a claude-code`. Or copy the skill folder (skills/snowflake/finding-expensive-queries in AltimateAI/data-engineering-skills) into .claude/skills/finding-expensive-queries in your project. Claude Code loads it when a task matches its description.

How do I install Expensive Snowflake Query Finder in Codex?

Run `npx skills add AltimateAI/data-engineering-skills --skill finding-expensive-queries -a codex`. Or copy the skill folder (skills/snowflake/finding-expensive-queries in AltimateAI/data-engineering-skills) into .agents/skills/finding-expensive-queries in your project. Codex loads it when a task matches its description.

Can I use Expensive Snowflake Query Finder in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add AltimateAI/data-engineering-skills --skill finding-expensive-queries -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/finding-expensive-queries, .gemini/skills/finding-expensive-queries, .github/skills/finding-expensive-queries and .opencode/skills/finding-expensive-queries in your project.

What does Expensive Snowflake Query Finder need to run?

SKILL.md names no scripts, command-line tools or credentials: Expensive Snowflake Query Finder is instructions for the agent only. Our summary lists: A Snowflake account with access to `QUERY_HISTORY` and `QUERY_ATTRIBUTION_HISTORY`.

Does Expensive Snowflake Query Finder access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Expensive Snowflake Query Finder safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Expensive Snowflake Query Finder use?

Expensive Snowflake Query Finder is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Expensive Snowflake Query Finder use?

About 662 tokens (SKILL.md is roughly 2.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Expensive Snowflake Query Finder?

Skills that share tags, products or a category with Expensive Snowflake Query Finder: Snowflake Development (sickn33/agentic-awesome-skills, 47k stars), Snowflake Development (alirezarezvani/claude-skills, 28k stars), Uipath Process Mining (UiPath/skills, 168 stars) and Dynamic Tables Tutorial (Kilo-Org/kilo-marketplace, 190 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Expensive Snowflake Query Finder?

AltimateAI (a GitHub organization) maintains it in AltimateAI/data-engineering-skills, which has 128 GitHub stars. The repository holds 12 skills in this directory. The repository was last updated on October 8, 2026.

Source: AltimateAI/data-engineering-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.