/infracost:iac-generationfrom infracost
Enforces cost optimization and FinOps/tagging policy compliance when generating infrastructure as code. Analyzes Terraform, CloudFormation, and Terragrunt with Infracost for real-time cost feedback.
Ships in infracost. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Assists when creating or modifying infrastructure as code (IaC) to ensure best practices are followed and costs are optimized from the start. Uses Infracost to analyze code as it's being written, providing real-time feedback on cost implications and optimization recommendations.
The output includes actionable insights: more cost-effective resource types, savings opportunities, FinOps policy violations flagged before deploy, and guidance on the user's organization's guidelines (tagging policies, required resource configurations) so problems are caught early rather than during code review.
Directly supported IaC types: Terraform, CloudFormation, Terragrunt. CDK is not yet directly supported.
Other IaC languages are also indirectly supported if you convert the resource definitions to Terraform (written to a temporary directory) and then scan that directory.
This skill uses Infracost capabilities (list policies / guardrails / budgets, price, scan, and
the inspect drill-ins). Each has two bindings — a typed MCP tool call and an infracost … CLI
command — listed in BINDINGS.md.
Rule: if the Infracost MCP server is available, use its tools; otherwise run the equivalent CLI command from BINDINGS.md. The Claude Code plugin starts the MCP server automatically.
Before generating IaC, satisfy the three preflight capabilities (see BINDINGS.md): the CLI is
present, the user is authenticated, and an organization is selected. With MCP these are resolved on
the first tool call (failures come back as readable errors, not a dropped connection); with the CLI,
check them inline. Never run infracost auth login — it is interactive. On an authentication
error, have the user run infracost auth login in a separate terminal, then retry. On "no
organization selected", the error lists the available org slugs; ask which one to use and have the
user run infracost org switch <slug> (add --repo to pin it to this repo), then retry — the
running MCP server picks up the selection on its next call. Relay these actionable messages to the
user — don't retry blindly.
Five capabilities matter for this workflow:
When writing or modifying IaC, follow this order:
Before generating any code, use the three "what's the org configured?" capabilities so the generated infrastructure is compliant by construction:
requirements, note any mandatory tags and the allowed_values lists. If a tagging policy allows a list of acceptable values (or no specific value) and you're not sure which to pick, ask the user. E.g., if a policy requires cost_center ∈ {engineering, marketing}, ask which one to apply.total_threshold / increase_threshold / increase_percent_threshold) and the actions (pr_comment / block_pr). A block_pr action means the threshold is a hard constraint — the generated infrastructure must stay under it. Soft constraints (alert / PR comment only) become warnings to surface.env=production, team=frontend, etc.), note where that budget currently sits versus its amount. Budgets reflect actual org-wide cloud billing, not the preview — treat them as context for the user, not a hard constraint on the code.Narrow the policies call when you know the provider (e.g. providers = aws) to skip downloading provider plugins for clouds you're not touching.
While drafting resources, use the price capability with a small Terraform snippet to get a cost on what you've written so far. This is faster than writing the whole file and scanning — useful for choosing between two configurations:
provider "aws" { region = "us-east-1" }
resource "aws_instance" "web" {
instance_type = "m5.xlarge"
root_block_device {
volume_size = 100
volume_type = "gp3"
}
}
The result includes per-resource cost components and any applicable FinOps recommendations (e.g. "use Graviton for ~20% savings"). Use it to make informed sizing / region / type calls as you go.
For non-USD pricing pass a currency (any ISO 4217 code).
Once the IaC files are complete, scan the directory.
Read the summary block first. Most of what you need is there:
monthly_cost — total cost of what you generated.total_yearly_savings — sum of potential savings per year if every FinOps issue were fixed. Savings are always quoted per year ($X/yr); costs stay monthly.failing_policies, failing_tagging_policies — counts; if non-zero, drill in.triggered_guardrails, over_budget — counts; if any guardrail with block_pr triggered, the generated code must be changed.critical_diagnostics, warning_diagnostics — non-zero means the scanner couldn't fully analyze something; surface via the per-project diagnostics capability.When the summary flags an issue, the inspect capabilities surface the detail. Each reads the latest cached scan automatically; target a specific previously-scanned directory by passing its path.
| Question | Capability |
|---|---|
| Everything failing right now (policies + guardrails + budgets in one view) | everything currently failing |
| Top N savings opportunities | top N savings (default n=10) |
| Resources missing / with-invalid a specific tag | list resources by predicate with missing_tag or invalid_tag |
| Resources by cost band | list resources by predicate with min_cost / max_cost |
| Group resources by type / provider / file | aggregate resources by dimension (e.g. group_by=type) |
| Per-project parse / lint diagnostics | per-project diagnostics (defaults to all severities; critical_only to filter) |
| Which resources fail a specific policy | policy detail (e.g. policy = "Use GP3") |
| Per-resource detail under a policy | policy detail (policy + resource, e.g. "Use GP3" + "aws_ebs_volume.data") |
| Detail for one budget (matching resources + savings) | budget detail (e.g. budget = "Production budget") |
| Triggered state + monthly cost for one guardrail | guardrail detail (e.g. guardrail = "Cost increase > $100") |
Adjust the IaC based on what the drill-ins surface. Re-scan to confirm:
block_pr guardrails are under threshold.When you make a non-obvious sizing / tagging decision based on an Infracost finding, add a brief comment to the IaC explaining the choice (e.g. "using Graviton — ~20% cheaper than equivalent x86", "team tag required by org tagging policy"). Be terse. Avoid mentioning Infracost unless absolutely necessary — comments rot less when they reference the constraint, not the tool that surfaced it.
jq pipelines, python3 -c heredocs, or shell post-processing to mangle output — Infracost returns structured data already (typed JSON via MCP; --llm via the CLI). If the data you need isn't on one of the typed shapes, that's a signal we should add it; file an issue describing the gap.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
infracost, finops, cost-optimization, tagging-policy, cloud-costs
4 skills in this plugin
/fix-findingsWalk a user through Infracost FinOps findings and apply fixes — either locally in their repo (when the task carries enough context to make a code edit), or by asking Agents to draft and open a PR / ticket on their behalf. Use this skill when the user asks to "fix the findings", "apply the recommendations", "open PRs for the FinOps issues", or otherwise wants to act on Agents' investigation results rather than just look at them./infracost-price-lookupLook up cloud resource pricing by generating sample Terraform and pricing it with Infracost. Use this skill when the user asks "how much does X cost?" or wants to compare pricing between resource configurations, instance types, regions, or cloud providers. This does not require the user to have any existing infrastructure code./npx claudepluginhub infracost/agent-skills --plugin infracostOther plugins' skills for the same job