Context Bloat: The Coding Agent Receipt
01 / The receipt starts with what you resend
A coding task might need three files, one failing test, and a short explanation. My suggested context budget starts there—not with the repository history. Context engineering guidance from Anthropic specifically identifies old tool results as candidates for removal once their useful information has been captured. ([anthropic.com](https://www.anthropic.com/research/effective-context-engineering-for-ai-agents?source=post_page-----f64bd1b56d9f---------------------------------------&utm_source=openai))
Before changing models, price the information you keep sending. The following receipt is an illustrative calculation, not a benchmark, a CheapRelay price quote, or a promise that smaller prompts produce equivalent results.
02 / A 12-request task costs $2.112 under these assumptions
Assume 12 model requests, each containing 80,000 input tokens and generating 2,000 output tokens. For this first calculation, assume no caching. Use hypothetical rates of $2 per million input tokens and $8 per million output tokens.
- ■ Instructions and tool definitions: 8,000 input tokens per request.
- ■ Repository material: 32,000 input tokens per request.
- ■ Previous conversation and tool results: 30,000 input tokens per request.
- ■ Current task and relevant evidence: 10,000 input tokens per request.
- ■ Input receipt: 960,000 tokens × $2 per million = $1.920.
- ■ Output receipt: 24,000 tokens × $8 per million = $0.192.
Total: $2.112 for the task. These are deliberately fixed-size requests so the arithmetic is inspectable. Your actual agent may send different amounts on every call; use its recorded usage rather than multiplying one unusually large request.
03 / Trim the packet to 20,000 tokens
For a controlled comparison, set a 20,000-token input budget: 4,000 for instructions and tools, 8,000 for relevant code, 3,000 for a working-state note, and 5,000 for the current task and evidence. Keep the same 12 requests and 24,000 total output tokens.
- ■ Trimmed input: 240,000 tokens × $2 per million = $0.480.
- ■ Unchanged output: 24,000 tokens × $8 per million = $0.192.
- ■ New total: $0.672.
- ■ Difference: $1.440 per task, or 68.2% of the original total.
That percentage is arithmetic, not an observed productivity gain. If trimming creates extra investigation, retries, or mistakes, add those costs back. Under these assumptions, one additional 20,000-input, 2,000-output request costs $0.056.
04 / Cut stale evidence before cutting requirements
My first cut would be completed investigative branches: unsuccessful searches, superseded file snapshots, and repeated successful test logs. Anthropic documents compaction and structured notes as ways to retain useful state without carrying the entire accumulated history. ([anthropic.com](https://www.anthropic.com/research/effective-context-engineering-for-ai-agents?source=post_page-----f64bd1b56d9f---------------------------------------&utm_source=openai))
Keep exact requirements, unresolved failures, relevant code, and verification commands. Replace a long investigation transcript with a short working note: objective, files changed, decisions, remaining questions, and tests still required. Keep paths to omitted evidence so the agent can retrieve it again.
For your own agent wrapper, consider a proposed 200-line cap on routine tool output, followed by targeted retrieval. Treat that as a configurable starting point, not a universal optimum. Never silently truncate the only failing assertion or the requirement explaining an edge case.
05 / Put cached tokens on a separate receipt
Caching changes the calculation. OpenAI documents reuse of matching prompt prefixes, so stable instructions should precede changing task material when designing a cache-friendly request. Actual eligibility and behavior depend on the API and model. ([developers.openai.com](https://developers.openai.com/api/docs/guides/prompt-caching?utm_source=openai))
Consider only a repeated 60,000-token prefix across 12 requests. With hypothetical cache-write pricing of $2.50 per million and cache-read pricing of $0.20 per million, one write costs $0.150 and 11 reads cost $0.132: $0.282 total. This excludes changing input and output. It assumes every later read hits and that write billing replaces ordinary input billing for that prefix.
Do not assume those hits occurred: inspect reported cached-token usage. ([developers.openai.com](https://developers.openai.com/cookbook/examples/prompt_caching101?utm_source=openai)) Reducing that same prefix to 15,000 tokens makes the illustrative subtotal $0.0705.
06 / Keep the relay bill and context budget separate
CheapRelay offers pay-as-you-go access through one API key, with no monthly fee or subscription. Its billing counts real tokens, including cache reads and writes. Sign up for CheapRelay, then compare complete-task receipts—not just headline token rates.
Record uncached input, cache writes, cache reads, output, retries, and whether verification passed. Your target is the lowest total cost for a correctly completed task, not the smallest prompt.
Registrarse Prueba los precios. Incluye crédito de registro.
Más lecturas
| Fecha | Pasillo | Idioma | Título |
|---|---|---|---|
| 2026-10-25 | Agentes de código baratos | EN | Coding Assistant Habits That Double Your Bill A receipt-style breakdown shows how oversized prompts and verbose answers turn a $0.60 coding session into $1.20, before retries. |
| 2026-10-25 | Agentes de código baratos | EN | Three AI CLIs, One Desktop, a $30 Budget A receipt-style plan for running Claude Code, Codex and Gemini CLI together, with a $30 usage budget and no invented token prices. |
| 2026-10-25 | Agentes de código baratos | EN | Coding Agents in CI: A $0.50 Pipeline Budget Build a receipt for every coding-agent run, reserve spend before requests, and stop retries before they turn a small fix into a large bill. |
| 2026-10-25 | Agentes de código baratos | EN | Claude Code on Windows: A PowerShell Cost Receipt Configure Claude Code with PowerShell environment variables, then audit a four-line token receipt without confusing example rates with real prices. |
| 2026-10-25 | Agentes de código baratos | EN | Gemini CLI vs Claude Code: The Shell Chore Receipt A concrete token-cost comparison for shell chores, with itemized receipts, retry math, cache caveats, and practical spending controls. |
| 2026-10-25 | Agentes de código baratos | EN | Cheap First, Escalate Later: A Coding Cost Receipt A worked token receipt shows how cheaper-first pair programming can cut API spending, with clear rules for escalating without wasting developer time. |