{"id":5798,"date":"2026-10-20T04:39:22","date_gmt":"2026-10-20T04:39:22","guid":{"rendered":"https:\/\/aiopsschool.com\/blog\/?p=5798"},"modified":"2026-10-20T04:39:23","modified_gmt":"2026-10-20T04:39:23","slug":"20-ways-to-reduce-claude-token-costs-across-multiple-terraform-repositories","status":"publish","type":"post","link":"https:\/\/aiopsschool.com\/blog\/20-ways-to-reduce-claude-token-costs-across-multiple-terraform-repositories\/","title":{"rendered":"20 Ways to Reduce Claude Token Costs Across Multiple Terraform Repositories"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If you&#8217;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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The goal isn&#8217;t just to make Claude read less. It&#8217;s to help Claude find the right files, understand the architecture quickly, and make changes without repeatedly rediscovering the same information.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. The highest-impact techniques<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Maintain a concise <code>CLAUDE.md<\/code> per repository<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Document architecture, directory structure, conventions, validation commands, and safety rules. Avoid repeating generic Terraform knowledge.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">High impact<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Add a README to each Terraform module<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Explain purpose, inputs, outputs, dependencies, assumptions, and important design decisions. Use <code>terraform-docs<\/code> to generate reference tables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">High impact<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Use targeted file exploration<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ask Claude to inspect the relevant module, its callers, and related outputs instead of scanning every repository file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">High impact<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4. Create reusable Terraform modules<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Standardize common patterns such as VPCs, EKS, IAM, security groups, and remote state. Reuse implementations rather than asking Claude to rediscover or recreate them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">High impact<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5. Use short, task-specific prompts<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Specify the repository, environment, module, desired change, constraints, and validation. Avoid lengthy repeated background explanations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">High impact<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Repository and documentation optimization<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>#<\/th><th>Technique<\/th><th>How to apply it<\/th><\/tr><tr><td>6<\/td><td>Create a repository index<\/td><td>Keep a short root README listing repos, cloud provider, environments, and entry points.<\/td><\/tr><tr><td>7<\/td><td>Use <code>terraform-docs<\/code><\/td><td>Generate variable, output, provider, and module reference tables automatically.<\/td><\/tr><tr><td>8<\/td><td>Document dependencies<\/td><td>Record which modules depend on VPC outputs, IAM roles, subnet IDs, and remote state.<\/td><\/tr><tr><td>9<\/td><td>Keep documentation concise<\/td><td>Prefer key decisions and constraints over copying entire <code>.tf<\/code> files into Markdown.<\/td><\/tr><tr><td>10<\/td><td>Use a shared standards template<\/td><td>Standardize tagging, naming, provider versions, formatting, security, and validation rules across repos.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Example repository index:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>infra\/\n\u251c\u2500\u2500 repo-index.md\n\u251c\u2500\u2500 aws-networking\/\n\u2502   \u2514\u2500\u2500 CLAUDE.md\n\u251c\u2500\u2500 aws-eks\/\n\u2502   \u2514\u2500\u2500 CLAUDE.md\n\u251c\u2500\u2500 azure-platform\/\n\u2502   \u2514\u2500\u2500 CLAUDE.md\n\u2514\u2500\u2500 terraform-modules\/\n    \u251c\u2500\u2500 vpc\/\n    \u251c\u2500\u2500 eks\/\n    \u2514\u2500\u2500 iam\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Keep a separate <code>CLAUDE.md<\/code> in each repo only where repository-specific instructions add value. Avoid duplicating a huge set of shared instructions everywhere.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Claude Code workflow optimization<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>#<\/th><th>Technique<\/th><th>How to apply it<\/th><\/tr><tr><td>11<\/td><td>Exclude generated and irrelevant files<\/td><td>Configure appropriate <code>.gitignore<\/code> and Claude Code ignore rules for large generated directories and irrelevant artifacts.<\/td><\/tr><tr><td>12<\/td><td>Avoid dumping entire files<\/td><td>Use targeted searches, relevant line ranges, and concise command output.<\/td><\/tr><tr><td>13<\/td><td>Use focused Git diffs<\/td><td>Inspect <code>git diff<\/code> and changed files rather than repeatedly reviewing the entire repository.<\/td><\/tr><tr><td>14<\/td><td>Avoid repeated explanations<\/td><td>Put stable project rules in documentation instead of pasting them into every prompt.<\/td><\/tr><tr><td>15<\/td><td>Use reusable skills or commands<\/td><td>Create workflows for common tasks such as adding variables, reviewing IAM, and preparing Terraform plans.<\/td><\/tr><tr><td>16<\/td><td>Start a fresh conversation when appropriate<\/td><td>Begin a new task-specific session when old conversation history is no longer useful.<\/td><\/tr><tr><td>17<\/td><td>Use <code>\/compact<\/code> when available<\/td><td>Summarize relevant context when a long session is consuming too much context.<\/td><\/tr><tr><td>18<\/td><td>Avoid unnecessary subagents<\/td><td>Delegate only when parallel exploration provides enough benefit to justify extra model usage.<\/td><\/tr><tr><td>19<\/td><td>Select the model for the task<\/td><td>Use a less expensive suitable model for routine documentation or straightforward edits; reserve stronger models for complex architecture and debugging.<\/td><\/tr><tr><td>20<\/td><td>Track token usage and caching<\/td><td>Review Claude Code usage information and API usage metrics, where available, to identify expensive workflows and cache opportunities.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Exact commands, features, and pricing depend on whether you use Claude Code with a subscription or through API billing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Make Terraform validation cheaper<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Don&#8217;t ask Claude to run every possible check after every small change.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the narrowest appropriate validation first, then expand when needed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Recommended validation sequence<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Format: <code>terraform fmt -check -recursive<\/code> when appropriate for the repository.<\/li>\n\n\n\n<li>Initialize: <code>terraform init -backend=false<\/code> for configuration validation when a backend connection is unnecessary.<\/li>\n\n\n\n<li>Validate: Run <code>terraform validate<\/code> in the relevant initialized root module.<\/li>\n\n\n\n<li>Plan: Run <code>terraform plan<\/code> against the correct workspace, variables, credentials, and backend when a real infrastructure plan is required.<\/li>\n\n\n\n<li>Review: Inspect the plan and diff; don&#8217;t apply or destroy automatically.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Note that <code>terraform validate<\/code> checks configuration correctness, not whether a real deployment will succeed. A valid configuration may still fail during planning or deployment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Use a standard prompt across all repositories<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of explaining your working style every time, keep a reusable prompt template.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Work only in the relevant Terraform repository and module.<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Read the applicable CLAUDE.md and module README first.<\/li>\n\n\n\n<li>Inspect only the files and dependencies necessary for this task.<\/li>\n\n\n\n<li>Reuse existing modules, conventions, and variables.<\/li>\n\n\n\n<li>Avoid reading or reproducing unrelated files.<\/li>\n\n\n\n<li>Make the smallest safe change that satisfies the requirement.<\/li>\n\n\n\n<li>Run the narrowest relevant validation and report its results.<\/li>\n\n\n\n<li>Summarize changed files, assumptions, risks, and any remaining checks.<\/li>\n\n\n\n<li>Never run terraform apply or destroy without explicit approval.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Task: [describe the requested change]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Repository: [repository name\/path]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Environment: [dev\/stage\/prod]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Module: [module name]<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. Understand what actually drives token cost<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are three different things to optimize:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Input tokens<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reduce unnecessary source files, repeated instructions, lengthy chat history, and oversized command output.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Output and reasoning usage<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keep tasks focused, request concise reports, and avoid unnecessary retries or overly elaborate explanations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Billing per token<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">7. My recommended implementation order<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you have dozens of Terraform repos, I would implement these in this order:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Standardize a concise <code>CLAUDE.md<\/code> template.<\/li>\n\n\n\n<li>Generate module READMEs with <code>terraform-docs<\/code>.<\/li>\n\n\n\n<li>Create a repository index and shared standards.<\/li>\n\n\n\n<li>Configure exclusions for irrelevant files and generated artifacts.<\/li>\n\n\n\n<li>Build reusable Claude Code skills or commands for frequent Terraform work.<\/li>\n\n\n\n<li>Measure actual usage before and after, using comparable tasks.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re working with many Terraform repositories for AWS, Azure, Kubernetes, EKS, networking, and shared infrastructure modules, the biggest opportunity [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5798","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=5798"}],"version-history":[{"count":1,"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5798\/revisions"}],"predecessor-version":[{"id":5799,"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5798\/revisions\/5799"}],"wp:attachment":[{"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=5798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=5798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=5798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}