If you’re working with many Terraform repositories for AWS, Azure, Kubernetes, EKS, networking, and shared infrastructure modules, the biggest opportunity is to reduce repeated code exploration, unnecessary context, and duplicated instructions.
The goal isn’t just to make Claude read less. It’s to help Claude find the right files, understand the architecture quickly, and make changes without repeatedly rediscovering the same information.
1. The highest-impact techniques
1. Maintain a concise CLAUDE.md per repository
Document architecture, directory structure, conventions, validation commands, and safety rules. Avoid repeating generic Terraform knowledge.
High impact
2. Add a README to each Terraform module
Explain purpose, inputs, outputs, dependencies, assumptions, and important design decisions. Use terraform-docs to generate reference tables.
High impact
3. Use targeted file exploration
Ask Claude to inspect the relevant module, its callers, and related outputs instead of scanning every repository file.
High impact
4. Create reusable Terraform modules
Standardize common patterns such as VPCs, EKS, IAM, security groups, and remote state. Reuse implementations rather than asking Claude to rediscover or recreate them.
High impact
5. Use short, task-specific prompts
Specify the repository, environment, module, desired change, constraints, and validation. Avoid lengthy repeated background explanations.
High impact
2. Repository and documentation optimization
| # | Technique | How to apply it |
|---|---|---|
| 6 | Create a repository index | Keep a short root README listing repos, cloud provider, environments, and entry points. |
| 7 | Use terraform-docs | Generate variable, output, provider, and module reference tables automatically. |
| 8 | Document dependencies | Record which modules depend on VPC outputs, IAM roles, subnet IDs, and remote state. |
| 9 | Keep documentation concise | Prefer key decisions and constraints over copying entire .tf files into Markdown. |
| 10 | Use a shared standards template | Standardize tagging, naming, provider versions, formatting, security, and validation rules across repos. |
Example repository index:
infra/
├── repo-index.md
├── aws-networking/
│ └── CLAUDE.md
├── aws-eks/
│ └── CLAUDE.md
├── azure-platform/
│ └── CLAUDE.md
└── terraform-modules/
├── vpc/
├── eks/
└── iam/
Keep a separate CLAUDE.md in each repo only where repository-specific instructions add value. Avoid duplicating a huge set of shared instructions everywhere.
3. Claude Code workflow optimization
| # | Technique | How to apply it |
|---|---|---|
| 11 | Exclude generated and irrelevant files | Configure appropriate .gitignore and Claude Code ignore rules for large generated directories and irrelevant artifacts. |
| 12 | Avoid dumping entire files | Use targeted searches, relevant line ranges, and concise command output. |
| 13 | Use focused Git diffs | Inspect git diff and changed files rather than repeatedly reviewing the entire repository. |
| 14 | Avoid repeated explanations | Put stable project rules in documentation instead of pasting them into every prompt. |
| 15 | Use reusable skills or commands | Create workflows for common tasks such as adding variables, reviewing IAM, and preparing Terraform plans. |
| 16 | Start a fresh conversation when appropriate | Begin a new task-specific session when old conversation history is no longer useful. |
| 17 | Use /compact when available | Summarize relevant context when a long session is consuming too much context. |
| 18 | Avoid unnecessary subagents | Delegate only when parallel exploration provides enough benefit to justify extra model usage. |
| 19 | Select the model for the task | Use a less expensive suitable model for routine documentation or straightforward edits; reserve stronger models for complex architecture and debugging. |
| 20 | Track token usage and caching | Review Claude Code usage information and API usage metrics, where available, to identify expensive workflows and cache opportunities. |
Exact commands, features, and pricing depend on whether you use Claude Code with a subscription or through API billing.
4. Make Terraform validation cheaper
Don’t ask Claude to run every possible check after every small change.
Use the narrowest appropriate validation first, then expand when needed.
Recommended validation sequence
- Format:
terraform fmt -check -recursivewhen appropriate for the repository. - Initialize:
terraform init -backend=falsefor configuration validation when a backend connection is unnecessary. - Validate: Run
terraform validatein the relevant initialized root module. - Plan: Run
terraform planagainst the correct workspace, variables, credentials, and backend when a real infrastructure plan is required. - Review: Inspect the plan and diff; don’t apply or destroy automatically.
Note that terraform validate checks configuration correctness, not whether a real deployment will succeed. A valid configuration may still fail during planning or deployment.
5. Use a standard prompt across all repositories
Instead of explaining your working style every time, keep a reusable prompt template.
Work only in the relevant Terraform repository and module.
- Read the applicable CLAUDE.md and module README first.
- Inspect only the files and dependencies necessary for this task.
- Reuse existing modules, conventions, and variables.
- Avoid reading or reproducing unrelated files.
- Make the smallest safe change that satisfies the requirement.
- Run the narrowest relevant validation and report its results.
- Summarize changed files, assumptions, risks, and any remaining checks.
- Never run terraform apply or destroy without explicit approval.
Task: [describe the requested change]
Repository: [repository name/path]
Environment: [dev/stage/prod]
Module: [module name]
6. Understand what actually drives token cost
There are three different things to optimize:
Input tokens
Reduce unnecessary source files, repeated instructions, lengthy chat history, and oversized command output.
Output and reasoning usage
Keep tasks focused, request concise reports, and avoid unnecessary retries or overly elaborate explanations.
Billing per token
Where supported, prompt caching can lower the cost of repeated input. Cached tokens may still count toward context usage, and subscription billing may work differently from API billing.
One crucial point: fewer tokens do not always mean a proportionally lower bill. Caching, model choice, subscription limits, and API pricing all affect the result.
7. My recommended implementation order
If you have dozens of Terraform repos, I would implement these in this order:
- Standardize a concise
CLAUDE.mdtemplate. - Generate module READMEs with
terraform-docs. - Create a repository index and shared standards.
- Configure exclusions for irrelevant files and generated artifacts.
- Build reusable Claude Code skills or commands for frequent Terraform work.
- Measure actual usage before and after, using comparable tasks.
My strongest recommendation: build a small Terraform documentation and workflow standard that you can apply to every repository, rather than manually optimizing each project differently.
One last detail matters for deciding the next steps: are you using Claude Code with a Claude subscription, or using Claude Code with an API key from Anthropic, DeepSeek, or another provider? The best cost-saving methods differ depending on the billing model.