Infracost cuts Claude token usage 79% by redesigning CLI for AI agents

Infracost, a CLI tool that estimates cloud infrastructure costs from Terraform, CloudFormation, and CDK, has redesigned its output for AI coding agents like Claude Code and Cursor. The result: up to 79% fewer output tokens and 67% lower API costs vs a bare-Claude baseline. The redesign revolves around two techniques: predicate pushdown into the CLI and a token-efficient output format.
Benchmark details
- 16 questions over a 3-project Terraform fixture with 1,171 resources
- Model: Claude Opus, 5 repeats per question
- Baseline: bare Claude with Bash and Read tools, no skill loaded
- Compared against Infracost skill with
--llmoutput flag
Key results
| Metric | Bare Claude | With Infracost skill (--llm) | Change |
|---|---|---|---|
| Correct answers | 5 / 11 (45%) | 11 / 11 (100%) | +6 |
| Total cost (USD) | $16.41 | $9.63 | -41% |
| Output tokens | 207,017 | 81,697 | -61% |
| Wall time | 50 min | 50 min | tied |
One example: the question "count distinct resources failing the tagging policy, deduplicated across projects" cost $3.51 with bare Claude and hit the 25-turn cap, returning no answer. With the redesigned CLI, the same question cost $0.25 and returned the correct answer.
Technical approach
- Predicate pushdown: Instead of having the agent pipe JSON through
jqor write Python parsers, the CLI accepts filtering flags (e.g.,--tag-policy), offloading computation to the tool itself. This reduces the number of turns and token consumption. - Token-efficient output format: The
--llmflag returns a compact, agent-friendly format rather than verbose human-readable tables or full JSON. This alone accounts for a significant share of the reduction.
Benchmark harness gotchas
Infracost open-sourced their harness setup to help others avoid pitfalls:
- Sandbox
HOMEfor baseline runs to avoid accidental skill loading - Set
TMPDIRto a project-local directory to circumvent macOS ACL issues - Prepend the test binary to
PATHrather than relying on system install - Use 5+ repeats per cell due to 20-30% token variance
- Re-run cells that hit turn caps (
--rerun-failed) and re-score if the verifier changes (--rescore)
If you maintain a CLI that AI agents call as a subprocess, the same two moves — predicate pushdown and a dedicated agent output format — likely apply. The redesign also improved the human-facing CLI, though the article focuses on the agent path.
📖 Read the full source: HN AI Agents
👀 See Also

Merlin: Local-first LLM context dedup – measure up to 71% chunk overlap, free & open-core
Merlin is a local-first context dedup tool that measured 22-71% chunk overlap across 22M passages from real agent/RAG sessions. Ships as HTTP proxy (Ollama/vLLM/SGLang/llama.cpp), MCP server (Claude/Cursor/OpenClaw), or standalone CLI. MIT open-core with daily usage caps.

Trepan: Local VS Code Security Auditor for AI-Generated Code
Trepan is an open-source VS Code extension that acts as a security gatekeeper for AI-generated code suggestions. It uses Ollama to run local security audits against project-specific rules in a .trepan/system_rules.md file.

Open-source CLI uses Claude Haiku to automate Xero expense auditing
A developer has released an open-source Python CLI tool that uses Claude Haiku 4.5 to automate Xero expense auditing. The tool follows a 'deterministic code first, then AI to fill in the gaps' approach, keeping costs to a few cents per audit run.

md-redline: GUI tool for reviewing and handing off markdown docs to Claude
md-redline is an open-source tool that lets you open markdown files in a GUI, leave inline comments stored as HTML markers in the .md file, and hand back off to Claude for updates. It runs locally with no account, cloud, or database required.