From infracost
Analyze infrastructure as code (IaC) projects to estimate cloud costs, identify savings opportunities, and flag FinOps policy violations. This skill should be used when asking about the cost of a cloud project, how to optimize costs, or when there are specific questions about FinOps policies or tagging compliance in an IaC codebase. The skill uses the Infracost CLI and its plugins to perform the analysis, so it requires the user to have those set up and authenticated. The output is a detailed cost report that highlights key insights and recommendations for cost optimization.
npx claudepluginhub infracost/agent-skills --plugin infracostThis skill uses the workspace's default tool permissions.
Analyze infrastructure as code (IaC) projects to estimate cloud costs, identify savings opportunities, and flag FinOps policy violations.
Audits cloud infrastructure costs from IaC like Terraform/Pulumi and configs, runs Infracost/AWS Cost Explorer/GCP Billing scanners, produces prioritized optimization plan with changes and savings estimates.
Validates IaC using Terraform, CloudFormation, Pulumi, CDK: runs validation, security policy checks, Infracost cost estimation, and drift detection. Activates on terraform plan or infrastructure review.
Audits AWS IaC code for Well-Architected Cost Optimization Pillar, checking oversized instances, S3 storage classes, scaling schedules, unused resources, data transfer, and cost alerts.
Share bugs, ideas, or general feedback.
Analyze infrastructure as code (IaC) projects to estimate cloud costs, identify savings opportunities, and flag FinOps policy violations.
Supported IaC types: Terraform, CloudFormation, Terragrunt. CDK is not yet directly supported.
important: Ensure that infracost-preview is available on the path. If it is not, offer to install it for the user by triggering the /infracost:install skill.
infracost-preview login
Run the scan command, pointing to your IaC files or a repository root:
# Single CloudFormation template
infracost-preview scan /path/to/cloudformation.yaml
# Terraform project directory
infracost-preview scan /path/to/terraform/
# Repository root (auto-discovers all IaC projects in nested directories)
infracost-preview scan /path/to/repo
JSON is written to stdout. Diagnostics and warnings are written to stderr.
The output can be very large for repos with many resources, so always pipe it to a file:
infracost-preview scan /path/to/repo
After analyzing, use the inspect command to explore the results instead of parsing raw JSON. Always start with a summary, then drill into areas of interest using the available flags.
Important: The inspect command reads from JSON and you DO NOT NEED to write any scripts to handle the JSON output yourself. Just use the inspect command with the appropriate flags to view the data in an engaging, actionable way.
# Scan and save to file
infracost-preview scan /path/to/repo
**Important**: The inspect command does not require the plugin paths to be specified, the command can be run without them
# Inspect the results (always pass --file to read from the saved JSON)
infracost-preview inspect [flags]
Available flags (combine as needed):
--summary — high-level overview of projects, costs, and policy counts (default when no flags given)--failing — only show policies that have failing resources (finops and tagging)--group-by <key>[,<key>] — group results by one or more dimensions: type, provider, project, policy. Comma-separated or repeated. Single dimension aggregates with counts; multiple dimensions show individual rows with file locations.--policy <name> — drill into a specific policy to see its failing resources, file locations, and issue counts--policy <name> --resource <address> — full detail for one resource under a policy: issue descriptions, savings, attributes, file location with a code snippet--top N — show only the top N most expensive resources--project <name> — filter to a specific project--provider <name> — filter by cloud provider (aws, google, azurerm)--costs-only — hide free resourcesAlways start with a summary or high-level grouping, then offer to drill deeper. The inspect command supports a progressive drill-down:
--summary or --group-by=policy to see what's failing--policy "Use GP3" to list the failing resources for that policy, with file locations--policy "Use GP3" --resource "aws_ebs_volume.data" to see full issue detail with a code snippetWhen presenting results, always offer the user a list of policies or resources they can drill into next. For example:
You have 3 failing FinOps policies. Would you like to drill into one?
- Use GP3 — 2 failing resources
- Use Graviton — 5 failing resources
- Required Tags — 12 failing resources
After showing a policy overview, offer to drill into specific resources:
Use GP3 has 2 failing resources. Want to see the detail for one?
aws_ebs_volume.data— modules/storage/main.tf:10aws_ebs_volume.logs— modules/logging/main.tf:25
The resource detail view includes a code snippet showing the relevant lines from the source file — use this to explain what needs to change and suggest a fix.
Important: When the user asks about a specific resource (e.g., "show me the issue with the lambda", "what's wrong with the RDS instance?"), always drill down to the resource level using --policy <name> --resource <address> and include the code snippet in your response. Don't just describe the issue — show it with the snippet so the user can see exactly what needs to change.
Make the output engaging with emojis, tables, and graphs where appropriate.
Summarize the costs of the cloud resources, focusing on the following:
To compare cost changes between branches, use git worktree:
# Create a worktree for the baseline
git worktree add /tmp/infracost-baseline origin/main
# Run against both and compare
infracost-preview scan /path/to/repo
infracost-preview scan /tmp/infracost-baseline/path/to/repo
# Clean up
git worktree remove /tmp/infracost-baseline
Compare the two JSON files to identify cost differences introduced by the current branch.
Always present cost analysis in an engaging, actionable way tailored to what the data shows. Don't just dump raw numbers — tell a story with the data: