# Cost Azure

> Tracks Azure cloud spend with Cost Management queries, exports, budgets, and consumption APIs to keep billing under control. Use when working with cost management, budgets, finops or when the user mentions cost management, budgets, finops.

- Skill: `opknock/cost-azure` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/cost-azure`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/cost-azure/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- License: MIT
- Author: OpKnock (https://skillmd.com/u/opknock)
- Updated: 2026-11-23
- Page: https://skillmd.com/skills/opknock/cost-azure

---


Tracks Azure cloud spend with Cost Management queries, exports, budgets, and consumption APIs to keep billing under control.

## Agentic Workflow: Read -> Reason -> Act (cost-azure)

You are **Cost Azure** (finops/general) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.

### 1. Read — finops context for `cost-azure`
- Domain: Tracks Azure cloud spend with Cost Management queries, exports, budgets, and consumption APIs to keep billing under control.
- **cost-management**: Query Azure cost data and manage exports via az cost-management. — `az cost-management query --type ActualCost --timeframe MonthToDate --scope /subs`
- **budgets**: Create Azure budgets and view consumption data. — `az consumption budget create --budget-name engineering-monthly --amount 15000 --`
- Check `knowledge` references before acting

### 2. Reason — think for `cost-azure`
- For `cost-management`: Query Azure cost data and manage exports via az cost-management. — decide which checks to run
- For `budgets`: Create Azure budgets and view consumption data. — decide which checks to run
- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs

### 3. Act — execute with `cost-azure` tools
- Tools: `Glob`, `Grep`, `Read`, `Az` (see frontmatter `tools`/`allowed-tools`)
- Use `safe_path` for any write; record evidence (paths, checksums)
- Fingerprint: `cost-azure:599281d1`

# Azure Cost Optimization

Understand and reduce Azure spend with Cost Management CLI queries.

## When to Use

- Monthly cost analysis per resource group or service
- Setting budget alerts for subscriptions
- Automating cost data exports to storage for BI
- Spotting VM overspend before invoice day

## Query cost

```bash
az cost-management query --type ActualCost --timeframe MonthToDate --scope /subscriptions/$SUBSCRIPTION_ID --aggregation '{"totalCost":{"name":"PreTaxCost","function":"Sum"}}'
```

Group by dimension for a breakdown:

```bash
az cost-management query --type ActualCost --timeframe LastMonth --scope /subscriptions/$SUB --grouping '{"type":"Dimension","name":"ServiceName"}'
```

## Budgets

```bash
az consumption budget create --budget-name eng-monthly --amount 15000 --time-grain monthly --start-date 2026-08-01
```

Attach action groups so budget thresholds page the FinOps on-call.

## Exports to storage

```bash
az cost-management export create --name monthly-export --type ActualCost --timeframe MonthToDate --storage-account $SA --container $CONTAINER --scope /subscriptions/$SUB
az cost-management export run --name monthly-export --scope /subscriptions/$SUB
```

## VM rightsizing

Check actual utilization before resizing:

```bash
az monitor metrics list --resource $RESOURCE_ID --metric PercentageCPU --interval PT1H
```

## Best practices

- Always scope queries to the subscription, not the tenant root.
- Set budgets at 80% and 100% of forecast spend.
- Export daily Parquet files to a lake and aggregate there.
- Apply Azure Hybrid Benefit for Windows/Linux VMs before paying on-demand.

## Capabilities

### cost-management
Query Azure cost data and manage exports via az cost-management.

**Parameters:**
- `type` (string): ActualCost or AmortizedCost
- `timeframe` (string): MonthToDate, LastMonth, or custom start/end
- `scope` (string): Subscription or resource-group scope URI

**Commands:**
- `az cost-management query --type ActualCost --timeframe MonthToDate --scope /subscriptions/$SUBSCRIPTION_ID --aggregation '{"totalCost":{"name":"PreTaxCost","function":"Sum"}}'`
- `az cost-management query --type ActualCost --timeframe LastMonth --scope /subscriptions/$SUBSCRIPTION_ID --grouping '{"type":"Dimension","name":"ServiceName"}'`
- `az cost-management export create --name monthly-export --type ActualCost --timeframe MonthToDate --storage-account $SA --container $CONTAINER --scope /subscriptions/$SUBSCRIPTION_ID`
- `az cost-management export list --scope /subscriptions/$SUBSCRIPTION_ID`
- `az cost-management export run --name monthly-export --scope /subscriptions/$SUBSCRIPTION_ID`

**Examples:**
- az cost-management query --type ActualCost --timeframe LastMonth --scope /subscriptions/$SUB --grouping '{"type":"Dimension","name":"ResourceGroupName"}'
- az cost-management query --type ActualCost --timeframe MonthToDate --scope /subscriptions/$SUB --aggregation '{"totalCost":{"name":"PreTaxCost","function":"Sum"}}'
- az cost-management export create --name daily-export --type ActualCost --timeframe MonthToDate --storage-account sa --container cost

### budgets
Create Azure budgets and view consumption data.

**Parameters:**
- `budget-name` (string): Unique budget name
- `amount` (number): Budget amount in USD
- `time-grain` (string): monthly, quarterly, or annually

**Commands:**
- `az consumption budget create --budget-name engineering-monthly --amount 15000 --time-grain monthly --start-date 2026-08-01 --category cost`
- `az consumption budget list`
- `az consumption budget show --budget-name engineering-monthly`
- `az consumption usage list --top 10 --metric usage`
- `az monitor metrics list --resource $RESOURCE_ID --metric PercentageCPU --interval PT1H`

**Examples:**
- az consumption budget create --budget-name eng-monthly --amount 15000 --time-grain monthly --start-date 2026-08-01
- az consumption usage list --top 20 | jq '.[] | {name: .name.value, quantity: .quantity}'
- az consumption budget show --budget-name eng-monthly

## References
- [Azure Cost Management + Billing](https://learn.microsoft.com/en-us/azure/cost-management-billing/)
- [az cost-management CLI reference](https://learn.microsoft.com/en-us/cli/azure/cost-management)
- [Azure Consumption CLI](https://learn.microsoft.com/en-us/cli/azure/consumption)

