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
knowledgereferences 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 doctorpatterns for your inputs
3. Act — execute with cost-azure tools
- Tools:
Glob,Grep,Read,Az(see frontmattertools/allowed-tools) - Use
safe_pathfor 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
az cost-management query --type ActualCost --timeframe MonthToDate --scope /subscriptions/$SUBSCRIPTION_ID --aggregation '{"totalCost":{"name":"PreTaxCost","function":"Sum"}}'
Group by dimension for a breakdown:
az cost-management query --type ActualCost --timeframe LastMonth --scope /subscriptions/$SUB --grouping '{"type":"Dimension","name":"ServiceName"}'
Budgets
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
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:
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 AmortizedCosttimeframe(string): MonthToDate, LastMonth, or custom start/endscope(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_IDaz cost-management export list --scope /subscriptions/$SUBSCRIPTION_IDaz 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 nameamount(number): Budget amount in USDtime-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 costaz consumption budget listaz consumption budget show --budget-name engineering-monthlyaz consumption usage list --top 10 --metric usageaz 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