---
name: snowflake-weekly-credit-usage
description: "Every Monday: Snowflake credits used in the last 7 days against the week before, by warehouse, with the most expensive queries and who ran them. Use when the user asks for this, or when it runs on a schedule."
---

# Snowflake credit usage this week

Every Monday: Snowflake credits used in the last 7 days against the week before, by warehouse, with the most expensive queries and who ran them.

Snowflake spend creeps: a warehouse resized for one backfill and never resized back, a dashboard that refreshes every five minutes, a dbt model that started scanning the full table. The admin pages show credits by warehouse, but not which queries inside the warehouse used them.

The agent reads the account usage views every Monday, sums credits by warehouse for the week, and uses query attribution history to rank the queries and users behind the spend. Repeated queries are grouped by their parameterized hash, so one dashboard tile that ran 2,000 times shows up as one line.

## Two ways to get the data

Use the API or MCP route when you have an MCP server, a CLI or an API token for the app. Otherwise, if you can drive a browser the user is signed in to (Claude in Chrome, a Playwright or Chrome DevTools MCP server), use the browser route. Say which one you used.

## Route A: API or MCP server

### What you need

- A role with the `USAGE_VIEWER` and `GOVERNANCE_VIEWER` database roles in the `SNOWFLAKE` database (or imported privileges on it), and a small warehouse to run the queries.
- Access through the Snowflake CLI (`snow sql -q`) or a Snowflake-managed MCP server with a read-only SQL execution tool.

If something is missing, say what and stop; do not invent numbers.

### Steps

1. **Credits by warehouse** (Snowflake): `select warehouse_name, sum(credits_used) from snowflake.account_usage.warehouse_metering_history where start_time >= dateadd(day, -7, current_date) and start_time < current_date group by 1 order by 2 desc`, and the same for the 7 days before.
2. **Total billed credits** (Snowflake): From `snowflake.account_usage.metering_daily_history`, sum `credits_billed` by `service_type` for the same days. This adds serverless features (tasks, Snowpipe, clustering) and applies the cloud services adjustment, so it is the number to quote.
3. **Rank the expensive queries** (Snowflake): From `snowflake.account_usage.query_attribution_history`, sum `credits_attributed_compute` by `query_parameterized_hash`, `user_name` and `warehouse_name` for the week, top 10. Join `query_history` on `query_id` for a sample of the text. Queries under about 100 ms are not attributed.
4. **Turn credits into money**: Multiply by your price per credit from the prompt (it depends on edition, region and contract). Flag a warehouse up more than 25%, and a query whose credits doubled.
5. **Report**: Credits and estimated cost with the weekly change, warehouses ranked, the top queries with user and warehouse, and one line on where to save.

## Route B: the browser

### What you need

- Signed in to Snowsight with a role that can see Cost Management: ACCOUNTADMIN, or a role with the `USAGE_VIEWER` and `GOVERNANCE_VIEWER` database roles, and a warehouse to run worksheets.

If something is missing, say what and stop; do not invent numbers.

### Steps

Start at https://app.snowflake.com/. The user is signed in already; never type passwords or codes, and ask if a sign-in page appears.

1. **Open Cost Management in Snowsight**: Snowsight asks for the account if you have several; pick it, then switch your role to one with usage access (ACCOUNTADMIN, or a role granted `USAGE_VIEWER`). In the left menu open **Admin** > **Cost Management**.
2. **Credits by warehouse**: On the **Consumption** tab set the date range to **Last 7 days**, the usage type to **Compute**, and group by **Warehouse**. Read credits per warehouse; then move the range to the 7 days before for the comparison. Switch the grouping to **Service** to see serverless credits (tasks, Snowpipe, clustering) next to warehouse compute.
3. **The expensive queries**: The **Account Overview** tab lists **Most expensive queries** for the chosen range with credits, user and warehouse. Click a query to open it in **Query History** for the text. Repeated queries show as separate rows here; group them by the text yourself.
4. **Run the SQL when the UI rounds too much**: Open **Projects** > **Worksheets**, create a worksheet and run the account usage queries: credits by warehouse from `WAREHOUSE_METERING_HISTORY`, billed credits by service type from `METERING_DAILY_HISTORY`, and the top 10 from `QUERY_ATTRIBUTION_HISTORY` grouped by `query_parameterized_hash`. Download the results as CSV if you need them later.
5. **Report**: Credits and the dollar estimate at your price per credit, warehouses ranked with their change (flag any up more than 25%), the top queries with user and warehouse, serverless credits, and one line on where to save.

Note: Cost Management rounds to a decimal and shows the account's local time zone, so figures differ a little from a worksheet query. Account usage views lag: warehouse metering up to 3 hours, query attribution up to 8. Most expensive queries lists individual runs, not parameterized groups, so a dashboard tile that ran 2,000 times is spread across many rows.

## The report

- **Credits billed** in the last 7 days and the estimated cost, with the weekly change.
- **By warehouse**: credits and change.
- **Costliest queries**: a shortened query, user, warehouse, runs and credits.
- **Serverless**: credits used by tasks, Snowpipe and other services.
- One line on the biggest saving, such as a warehouse to shrink or a schedule to slow down.

## Post it to Briefkin

When `BRIEFKIN_TOKEN` is set, or `~/.config/briefkin/env` exists (the installer from https://briefkin.dev/docs writes it), also send the result to the user's Briefkin board as one card. Keep the `item_key` the same on every run so the card updates in place, use a new `event_id` per run, and put today's real numbers in place of the example ones. If the request fails, say so once and carry on.

```bash
[ -n "${BRIEFKIN_TOKEN:-}" ] || . ~/.config/briefkin/env
curl -sS -X POST "${BRIEFKIN_URL:-https://briefkin.dev}/v1/events" \
  -H "authorization: Bearer $BRIEFKIN_TOKEN" \
  -H "content-type: application/json" \
  -d @- <<'JSON'
{
  "v": 1,
  "event_id": "snowflake-weekly-credit-usage/<date of this run, e.g. 2026-10-16>",
  "item_key": "snowflake-weekly-credit-usage",
  "project": "Acme Snowflake",
  "source": "Snowflake credit usage this week skill",
  "kind": "metric",
  "title": "412.6 credits this week, up 13%",
  "metric": {
    "label": "Credits used, last 7 days",
    "value": 412.6,
    "better": "lower",
    "period_start": "<start of the period, ISO 8601>",
    "period_end": "<end of the period, ISO 8601>"
  },
  "glance": [
    {
      "type": "Grid",
      "props": {
        "columns": 3
      },
      "children": [
        {
          "type": "Stat",
          "props": {
            "label": "Estimated cost",
            "value": 1238,
            "prefix": "$",
            "better": "lower"
          }
        },
        {
          "type": "Stat",
          "props": {
            "label": "vs last week",
            "value": 13,
            "unit": "%"
          }
        },
        {
          "type": "Stat",
          "props": {
            "label": "Top warehouse",
            "value": "TRANSFORM_WH"
          }
        }
      ]
    }
  ],
  "widget": [
    {
      "type": "Bars",
      "props": {
        "unit": "credits",
        "items": [
          {
            "label": "TRANSFORM_WH",
            "value": 198.4
          },
          {
            "label": "BI_WH",
            "value": 121.7
          },
          {
            "label": "LOAD_WH",
            "value": 58.3
          },
          {
            "label": "ADHOC_WH",
            "value": 21.9
          },
          {
            "label": "Serverless",
            "value": 12.3
          }
        ]
      }
    },
    {
      "type": "Table",
      "props": {
        "columns": [
          "Query",
          "User",
          "Runs",
          "Credits"
        ],
        "align": [
          "left",
          "left",
          "right",
          "right"
        ],
        "rows": [
          [
            "merge into analytics.fct_events using ...",
            "DBT_PROD",
            168,
            46.2
          ],
          [
            "select * from raw.events where event_date >= ?",
            "MAYA",
            4,
            18.9
          ],
          [
            "select count(distinct user_id) from analytics.sessions ...",
            "LOOKER",
            2016,
            14.6
          ],
          [
            "create or replace table analytics.dim_users as ...",
            "DBT_PROD",
            7,
            9.8
          ]
        ]
      }
    },
    {
      "type": "Callout",
      "props": {
        "text": "TRANSFORM_WH rose 31% after fct_events switched to a full merge on Tuesday. An incremental filter on event_date would cut most of it.",
        "tone": "warn"
      }
    }
  ],
  "size": "md"
}
JSON
```

Widgets come from the Briefkin catalog (https://briefkin.dev/v1/catalog). Without a token, just give the user the report.

Set `period_start` and `period_end` to the window the number covers: the tile names it from them ("Last 7 days", "Today", "This month"). For a count right now (open items, a balance), send `"period_label": ""` so no period shows; for another name, send it as `period_label` (at most 24 characters).

## Run it on a schedule

Suggested: Mondays at 8:00 (`0 8 * * 1`). From cron, with the agent signed in on that machine:

```bash
0 8 * * 1 claude -p "Run the snowflake-weekly-credit-usage skill"
# Codex: codex exec, Gemini CLI: gemini -p, Copilot CLI: copilot -p, OpenCode: opencode run
```

Or use the agent's own scheduler (Claude Code routines, Codex automations, Claude or ChatGPT scheduled tasks): https://briefkin.dev/skills/snowflake-weekly-credit-usage#schedule

Source: https://briefkin.dev/skills/snowflake-weekly-credit-usage
