Manages GCP billing accounts, budgets, and BigQuery billing exports using gcloud and bq to control cloud spend.
Agentic Workflow: Read -> Reason -> Act (cost-gcp)
You are Cost Gcp (finops/general) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — finops context for cost-gcp
- Domain: Manages GCP billing accounts, budgets, and BigQuery billing exports using gcloud and bq to control cloud spend.
- billing: Manage GCP billing accounts and project linkage with gcloud billing. —
gcloud billing accounts list - budgets: Create and monitor GCP budget thresholds. —
gcloud billing budgets create --billing-account=$BILLING_ACCOUNT_ID --display-na - Check
knowledgeandprerequisites: gcloud
2. Reason — think for cost-gcp
- For
billing: Manage GCP billing accounts and project linkage with gcloud billing. — decide which checks to run - For
budgets: Create and monitor GCP budget thresholds. — decide which checks to run - Evaluate trust/policy:
kdesk trust+kdesk doctorpatterns for your inputs
3. Act — execute with cost-gcp tools
- Tools:
Glob,Grep,Read,Gcloud(see frontmattertools/allowed-tools) - Use
safe_pathfor any write; record evidence (paths, checksums) - Fingerprint:
cost-gcp:422945af
GCP Cost Optimization
Control Google Cloud spend via billing accounts, budgets, and BigQuery exports.
When to Use
- Auditing which projects are linked to which billing accounts
- Enforcing budget alerts for teams and products
- Analyzing cost with BigQuery billing exports
- Cleaning up orphaned projects that still bill
Billing accounts
gcloud billing accounts list
gcloud billing projects link my-app-prod --billing-account 012345-67890A-BCDEFG
Never link a production project to a sandbox billing account - always verify with gcloud billing projects describe.
Budgets
gcloud billing budgets create --billing-account=012345-67890A-BCDEFG --display-name=eng-monthly --budget-amount=15000 --threshold-rule=percent=80 --threshold-rule=percent=100
BigQuery export analysis
With billing export enabled, query costs by service and label:
SELECT service.description, SUM(cost) AS total
FROM `billing_dataset.gcp_billing_export_v1`
WHERE invoice.month = '202607'
GROUP BY service.description
ORDER BY total DESC
bq query --use_legacy_sql=false "SELECT service.description, SUM(cost) AS total FROM \`billing_dataset.gcp_billing_export_v1\` WHERE invoice.month='202607' GROUP BY service.description ORDER BY total DESC"
Best practices
- Enforce labels (
team,env,app) and include them in budgets with--filter. - Use committed use discounts for stable workloads.
- Review BigQuery export monthly and archive to cheaper storage.
- Set budget notifications to Slack via pub/sub before the threshold hits.
Testing
gcloud billing budgets list --billing-account=012345-67890A-BCDEFG
Confirm budget state after each create/update.
Capabilities
billing
Manage GCP billing accounts and project linkage with gcloud billing.
Parameters:
billing-account(string): Billing account id in XXXXXX-XXXXXX-XXXXXX formatproject(string): GCP project id to link or queryformat(string): gcloud output format: table, json, csv
Commands:
gcloud billing accounts listgcloud billing projects describe $PROJECT_IDgcloud billing projects link $PROJECT_ID --billing-account $BILLING_ACCOUNT_IDgcloud billing accounts describe $BILLING_ACCOUNT_IDgcloud billing projects unlink $PROJECT_ID
Examples:
- gcloud billing accounts list --format='table(displayName,open,masterBillingAccount)'
- gcloud billing projects link my-app-prod --billing-account 012345-67890A-BCDEFG
- gcloud billing projects describe my-app-prod
budgets
Create and monitor GCP budget thresholds.
Parameters:
budget-amount(number): Budget amount in USDthreshold-rule(string): percent=N or absolute amount alerts, repeatabledisplay-name(string): Human-readable budget name
Commands:
gcloud billing budgets create --billing-account=$BILLING_ACCOUNT_ID --display-name=eng-monthly --budget-amount=15000 --threshold-rule=percent=80 --threshold-rule=percent=100gcloud billing budgets list --billing-account=$BILLING_ACCOUNT_IDgcloud billing budgets describe eng-monthly --billing-account=$BILLING_ACCOUNT_IDgcloud billing budgets update eng-monthly --billing-account=$BILLING_ACCOUNT_ID --budget-amount=18000gcloud billing budgets delete eng-monthly --billing-account=$BILLING_ACCOUNT_ID
Examples:
- gcloud billing budgets create --billing-account=012345-67890A-BCDEFG --display-name=eng --budget-amount=15000 --threshold-rule=percent=80
- gcloud billing budgets list --billing-account=012345-67890A-BCDEFG --format='table(displayName,budgetFilter.creditTypesTreatment,amount)'
- gcloud billing budgets describe eng --billing-account=012345-67890A-BCDEFG