How to Reduce AI Coding Agent Costs: Tokens, Caching and Local Models
Prices per token fell this autumn, but agent bills did not, because agents read far more than they write. Here is where the tokens go and the eight levers that cut the cost of Claude Code, Cursor, Copilot and OpenCode without slowing you down.
Dmytro Vavreniuk
Product Engineer
Short version: most of an AI coding agent’s cost is input tokens it re-reads every turn, not code it writes. Keep the start of the prompt stable so prompt caching works (it cut our example session by 80%), pick the cache lifetime to match how you work, run a mid-tier model by default with cheap subagents for searching, keep always-on context and tool output small, never use fast mode for long runs, send bulk jobs to the Batch API at 50% off, offload grunt work to local models, and choose a plan that matches how often you actually use the agent.
Our most-read post is still a short guide on how to minimise Cursor token spending. It covers Cursor settings. This guide goes one level deeper and applies to any agent: why the bill looks the way it does, what the latest price changes mean, and which habits save money in Claude Code, Cursor, Copilot and open-source agents such as OpenCode.
What changed this autumn
| When | What happened |
|---|---|
| Autumn 2026 | Anthropic’s 5.5 generation lowers the price floor: Sonnet 5.5 at $2 / $10 per million input / output tokens, Opus 5.5 at $4 / $20, Haiku 5.5 at $0.10 / $0.50. Cache reads on Opus 5.5 and Sonnet 5.5 drop to 0.05x of the input price instead of the usual 0.1x. |
| Autumn 2026 | Claude Code makes prompt-cache lifetime configurable per bucket (main conversation vs subagents) with CLAUDE_CODE_PROMPT_CACHE_TTL and CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL (v2.1.242+). Subscriptions get a 1-hour cache on the main conversation; API keys default to 5 minutes. |
| Nov 2026 | Cursor’s plans are now Plus ($8, Grok models only), Premium ($30, third-party models billed at API list price on top), Super ($100) and Ultra ($200), with a usage pool that refreshes weekly. |
| Nov 2026 | GitHub Copilot bills agent and chat use in AI credits at $0.01 each: Pro ($10) includes $15 of credits, Pro+ ($39) $70, Max ($100) $200. Completions stay unlimited on paid plans. A 30% discount on Copilot Fusion usage runs until Dec 31. |
| Nov 2026 | Anthropic’s own Claude Code cost guide puts the enterprise average at about $13 per developer per active day and $150-250 per month, with 90% of users under $30 a day. |
Sources: Anthropic pricing, Claude Code costs, Claude Code prompt caching, Cursor pricing and Copilot plans, all checked on 25 November 2026. The pattern across vendors is the same: cheaper tokens, but metered usage everywhere, including flat plans that now come with credit pools. That makes your habits, not the sticker price, the main cost driver.
One detail that is easy to miss: Anthropic notes that Claude models from 4.7 onwards use a tokenizer that produces about 30% more tokens for the same text. When you compare a new model with an old one, compare the cost of a finished task, not the price per million tokens.
Where the tokens actually go
Models are stateless. On every turn, the agent sends the full context again, and the model reads all of it before writing a single token:
One agent turn = everything the model re-reads + what it writes
system prompt + tool definitions 5-25k tokens (every MCP server adds its tools here)
CLAUDE.md / AGENTS.md / rules 1-10k
conversation so far grows each turn
file contents the agent opened 2-50k per file batch
tool output (tests, logs, grep) 0-100k+ <- the silent killer
---------------------------------------------------
= input tokens for THIS turn re-sent on the NEXT turn too
+ thinking tokens billed as output
+ the answer / the diff billed as outputSo cost grows with the number of turns multiplied by the size of the context, and a session gets more expensive the longer it runs. Two consequences follow. First, the largest savings come from making repeated input cheap (caching) and small (context hygiene). Second, a single cat of a big log file is not a one-off cost: it stays in the context and is paid for again on every following turn until you clear or compact.
A worked example
Take a typical 40-turn session. The context starts at 20,000 tokens and grows by about 2,000 per turn to 100,000, so the average is 60,000 and the session reads 2.4 million input tokens in total. Each turn writes about 1,500 output tokens including thinking, 60,000 in total. With caching, only the 100,000 new tokens are written to the cache and the other 2.3 million are cache reads:
| Model | Cache writes | Cache reads | Output | Total, cached | Total, no cache |
|---|---|---|---|---|---|
| Haiku 5.5 | $0.01 | $0.02 | $0.03 | $0.07 | $0.27 |
| Sonnet 5.5 | $0.25 | $0.23 | $0.60 | $1.08 | $5.40 |
| Opus 5.5 | $0.50 | $0.46 | $1.20 | $2.16 | $10.80 |
| Opus 5.5 fast mode | $1.00 | $0.92 | $2.40 | $4.32 | $21.60 |
| Fable 5.2 | $1.00 | $0.46 | $2.40 | $3.86 | $21.60 |
Calculated from Anthropic list prices with a 5-minute cache and every read a hit. Three things stand out. Caching cuts the Sonnet 5.5 session from $5.40 to $1.08. Once input is cached, output becomes the largest line, which is why thinking effort matters (lever 4). And model choice still multiplies everything: the same session ranges from 7 cents to more than 4 dollars.
Lever 1: make prompt caching work for you
Caching stores the processed start of your prompt so the next request can reuse it. On Anthropic models a cache read costs 0.1x of the input price, 0.05x on Sonnet 5.5 and Opus 5.5 and 0.025x on Fable 5.2. Writing to the cache costs 1.25x for a 5-minute lifetime and 2x for a 1-hour lifetime. Agents such as Claude Code set cache breakpoints for you, but your behaviour decides whether they hit:
- Keep the prefix stable. The cache matches from the start of the prompt. Editing CLAUDE.md, adding an MCP server or changing the system prompt mid-session invalidates everything after it.
- Do not switch models mid-session. Each model has its own cache. In Claude Code, switching models, turning on fast mode and, on most model and auth combinations, changing effort all start from a cold cache. Decide before you start, or start a fresh session for the other model.
- Mind the lifetime. With a 5-minute cache, a 6-minute pause to review a diff means the next turn rewrites the whole context. On Opus 5.5 with a 150,000-token context, that is $0.75 for the rewrite instead of $0.03 for a read, every time you step away.
Claude Code now lets you choose the lifetime separately for the main conversation and for everything else (subagents, compaction). On a subscription the main conversation already gets 1 hour; on an API key or a cloud provider it defaults to 5 minutes. The 1-hour write pays for itself after two reads, so it is the right choice for long interactive sessions with pauses, while short-lived subagents should stay on 5 minutes. Configuration is in lever 2 below. With other agents, check whether your provider supports caching at all: some cache automatically, some only on request, and some open-model hosts only offer best-effort caching.
Lever 2: route work to the right model
Current Anthropic list prices, in dollars per million tokens:
| Model | Input | Output | Cache write 5m / 1h | Cache read | Note |
|---|---|---|---|---|---|
| Haiku 5.5 | $0.10 | $0.50 | $0.125 / $0.20 | $0.01 | Prompts over 100k tokens: $0.50 / $2.50 |
| Sonnet 5.5 | $2 | $10 | $2.50 / $4 | $0.10 | Cache reads at 0.05x |
| Opus 5.5 | $4 | $20 | $5 / $8 | $0.20 | Fast mode $8 / $40 |
| Fable 5.2 | $8 | $40 | $10 / $16 | $0.20 | Cache reads at 0.025x |
| Sonnet 4.6 (older) | $3 | $15 | $3.75 / $6 | $0.30 | Older and more expensive than Sonnet 5.5 |
Note the last row: if a pinned setting or an old config still points at a 4.x model, you pay more for less. An 80x input price gap between the cheapest and the most capable model means routing pays off quickly:
| Task | Model tier | Why |
|---|---|---|
| Search the repo, read files, summarise logs, write commit messages | Haiku-class or a local model | High token volume, low reasoning. This is where subagents spend most of their tokens. |
| Implement a feature from a clear plan, fix a failing test, refactor | Sonnet-class (default) | The best price per merged change for everyday work. |
| Architecture, a nasty concurrency bug, a migration plan | Opus-class, plan mode | Pay for reasoning once, then hand the plan to a cheaper model to execute. |
| Long unattended runs, overnight refactors | Sonnet-class, never fast mode | Nobody is waiting, so paying 2x for speed buys nothing. |
The pattern that works best for us: plan with a strong model, execute with a mid-tier one, and give exploration to a cheap subagent that returns file paths instead of file contents. In Claude Code that looks like this:
// .claude/settings.json (project) - cost-conscious defaults (strip the comments, JSON has none)
{
"model": "sonnet",
"env": {
"CLAUDE_CODE_PROMPT_CACHE_TTL": "1h", // main conversation: survive coffee breaks
"CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL": "5m", // subagents are short-lived, 1h writes cost 2x
"MAX_THINKING_TOKENS": "8000" // cap thinking where the model supports it
}
}
// .claude/agents/repo-search.md - a cheap subagent for exploration
---
name: repo-search
description: Find files, symbols and call sites. Read-only.
model: haiku
tools: Read, Grep, Glob
---
Return file paths and line numbers with one-line explanations. Never paste whole files.Watch out for agent teams and parallel subagents. Anthropic estimates that agent teams use about 7x more tokens than a standard session when teammates run in plan mode. They are worth it for large, parallel work, not for a single bug fix. In Cursor, the equivalent settings (Max mode, subagent models, fast mode) are covered in our Cursor guide.
Lever 3: keep context small
Everything in the context is paid for on every turn. Small habits add up:
- One task per session. Use
/clearwhen you switch tasks and/compactat natural breaks. An old debugging transcript is useless context for the next feature. - Lean always-on instructions. Keep CLAUDE.md, AGENTS.md or Cursor rules under about 200 lines. Move rarely needed instructions (release process, migration guide) into skills that load only when relevant.
- Disable MCP servers you are not using. Every connected server adds its tool definitions to every request. Ten servers you used once last month are a fixed tax on every turn.
- Point, do not explore. Giving the file and function name saves the agent a dozen search-and-read turns. The more precise the prompt, the fewer tokens of exploration.
- Trim tool output. The single biggest waste we see is a full test run or log dump pasted into the context. Put filtered commands in your project instructions so the agent uses them by default:
# Make tool output small BEFORE the agent sees it
# Tests: failures only, no progress bars
npx vitest run --reporter=dot 2>&1 | tail -n 60
go test ./... 2>&1 | grep -E '^(--- FAIL|FAIL|panic|ok )' | head -n 80
pytest -q --no-header -x 2>&1 | tail -n 40
# Logs: filter by the one thing you care about
kubectl logs deploy/api --since=15m | grep '"level":"error"' | tail -n 50
jq -c 'select(.trace_id == "4bf92f3577b34da6")' app.log | head -n 100
# Builds: errors, not the 4,000-line webpack report
npm run build 2>&1 | grep -iE 'error|failed' | head -n 40Structured logs make the last part easy: if every line is JSON with a level and a trace ID, one jq filter returns the 20 lines that matter instead of 20,000. See structured logging best practices for the format.
Lever 4: control thinking and fast mode
Thinking tokens are billed as output, and output is five times the price of input. On Opus 5.5, Sonnet 5.5, Haiku 5.5 and the Fable models extended thinking cannot be switched off, but you can lower the effort level or cap the budget with MAX_THINKING_TOKENS where the model supports it. High effort is worth paying for on a hard design question, not on renaming a variable.
Fast mode is the opposite trade: the same model, faster, at twice the price (Opus 5.5 goes from $4 / $20 to $8 / $40). It also stacks with cache prices and starts a fresh cache. Use it when you are actively waiting on a short task; never leave it on for long or unattended runs.
Lever 5: send bulk jobs to the Batch API
Not every AI task needs an interactive agent. Reviewing 300 files against one rule, writing docstrings or classifying a backlog are independent requests that nobody watches in real time. The Batch API processes them asynchronously at a flat 50% discount on input and output, and it combines with caching of a shared system prompt:
# Non-interactive work at 50% off: the Message Batches API
# Good fits: review 300 files for one rule, write docstrings, triage a backlog
import anthropic, pathlib
client = anthropic.Anthropic()
RULE = "Flag any SQL built with string concatenation. Reply 'OK' or list line numbers."
requests = [
{
"custom_id": str(path),
"params": {
"model": "claude-sonnet-5-5",
"max_tokens": 512,
"system": [{"type": "text", "text": RULE, "cache_control": {"type": "ephemeral"}}],
"messages": [{"role": "user", "content": path.read_text()}],
},
}
for path in pathlib.Path("src").rglob("*.py")
]
batch = client.messages.batches.create(requests=requests)
print(batch.id, batch.processing_status) # poll later; results usually arrive well within 24 hThe same idea applies to CI: a review gate that runs on every pull request does not need the most expensive model or real-time answers. We compared options in AI review gates in CI: the best-value stack.
Lever 6: offload grunt work to local and open models
Open-source agents such as OpenCode, Cline and Aider can talk to any OpenAI-compatible endpoint, including a model running on your own machine through Ollama (which serves one at http://localhost:11434/v1), LM Studio or llama.cpp. The marginal cost is electricity, and code never leaves your laptop, which also helps with the privacy questions we covered in local LLMs for session replay debugging.
Be realistic about where local models win. They are good at high-volume, low-reasoning work: summarising logs, searching and explaining code, commit messages, test data, simple single-file edits. For multi-file changes, frontier hosted models are usually cheaper per merged change, because a weaker model needs more retries and every retry re-reads the whole context. Our benchmarks of open coding models on real bug fixes show the same split. The pragmatic setup is hybrid: a hosted model for planning and hard edits, a local or very cheap model for everything that is mostly reading. The trade-offs are discussed in local vs remote AI agents.
Lever 7: pick the plan that matches your usage
| Tool | Individual plans | How usage is metered | Cost tip |
|---|---|---|---|
| Cursor | Plus $8 (Grok models only), Premium $30, Super $100, Ultra $200 | Weekly usage pool; on Premium and up, third-party models (Claude, GPT, Gemini) are billed at API list price on top | Plus is the cheapest paid agent seat if Grok and Composer models are enough for you. If you mostly use Claude or GPT, compare Premium plus usage against a direct subscription. |
| GitHub Copilot | Pro $10, Pro+ $39, Max $100 | AI credits at $0.01 each: $15 / $70 / $200 included; completions unlimited | Set a dollar budget; alerts fire at 75%, 90% and 100%. Copilot Fusion usage is 30% off until Dec 31. |
| Claude Code | Pro, Max and higher subscription tiers, or API pay-as-you-go | Subscription: 5-hour and weekly limits. API: per token, 5-minute cache by default | Daily heavy users usually come out ahead on a subscription; occasional users and CI jobs on the API. |
| OpenCode / Cline / Aider | Open source, bring your own key or local model | Whatever your provider charges, or electricity | The cheapest way to mix models: a strong hosted model for planning, a local one for grunt work. |
Use Anthropic’s average as a yardstick: about $13 per active day on API pricing. If you code with an agent most working days, that is roughly $270 a month at list price, more than most flat plans. If you use it twice a week, pay as you go is cheaper. Two traps to avoid: paying for a $30 plan and then also paying API list price for the third-party models you actually use, and keeping a plan that bills a model you no longer prefer. Our OpenCode vs Claude Code vs Cursor comparison covers the workflow differences behind the prices.
Lever 8: measure cost per result
You cannot reduce what you do not see. In Claude Code, /usage shows the current session’s usage at list prices, and organisations can configure their contracted rates so the estimate matches the invoice. Copilot lets you set a dollar budget with alerts at 75%, 90% and 100%, and Cursor shows the weekly pool. Then track two numbers, not one: cost per active day to catch runaway sessions, and cost per merged pull request to make sure that the cheaper setup is not just producing more retries. A setup that halves the token price and doubles the number of attempts saved nothing.
The expensive part of debugging is searching
Debugging is where agents burn the most tokens, because they do not know where to look. Without evidence, an agent greps the codebase, reads ten files, tails a log, guesses, runs the tests and tries again, and each step adds to a context that is re-read on every turn. Give it the evidence up front instead: the exact user session, the console error, the failing request and the matching backend trace. That turns a 40-turn search into a 5-turn fix.
This is what the LogNroll MCP server is for: the agent asks for one session and gets back the steps, errors and network failures of that session, a few thousand tokens instead of a whole log file. The workflow is described in AI agent debugging in production, and if the session ID travels to your backend as described in frontend to backend tracing, the agent can pull the matching server logs with one filtered query.
Cost checklist
| Item | How to check |
|---|---|
| Default model is mid-tier | Your settings name a Sonnet-class model. Opus or Fable only by explicit choice or in plan mode. |
| Cheap subagents | Search and exploration subagents run on Haiku-class or local models. |
| Cache-friendly sessions | No model switching mid-session. 1-hour TTL on long interactive sessions, 5 minutes on subagents. |
| Small always-on context | CLAUDE.md / rules under about 200 lines; rarely used instructions moved into skills; unused MCP servers disabled. |
| Trimmed tool output | Test, build and log commands in your instructions pipe through tail, grep or jq. |
| No fast mode for long runs | Fast mode only when you are actively waiting on a short task. |
| Batch for bulk jobs | Repo-wide reviews and doc generation go through the Batch API, not an interactive agent. |
| Cost is measured | You know your cost per active day and per merged PR, and a budget alert exists. |
Prices in this article are list prices as published on 25 November 2026. Several vendors run introductory discounts that end in December, so check the pricing pages before you lock in a plan.
Frequently asked questions
Why are AI coding agents so expensive?
Because every turn re-sends the whole context: system prompt, tool definitions, project rules, the conversation so far, files the agent opened and tool output such as test logs. A 40-turn session with an average context of 60,000 tokens processes about 2.4 million input tokens, even if you only typed a few sentences. Output, including thinking tokens, is priced 5x higher than input on most models.
How much does an AI coding agent cost per developer?
Anthropic reports that across enterprise deployments Claude Code averages about $13 per developer per active day and $150-250 per developer per month, with 90% of users staying under $30 per active day. Flat plans range from $8 a month (Cursor Plus) and $10 (Copilot Pro) to $200 (Cursor Ultra) for heavy users.
Does prompt caching really reduce AI agent costs?
Yes, it is the biggest single lever. Cache reads cost 0.1x of the normal input price on most Claude models and 0.05x on Sonnet 5.5 and Opus 5.5. In our example session, caching cut the input cost of a Sonnet 5.5 session from $4.80 to $0.48. Caching only works if the start of the prompt stays identical, so avoid switching models or editing rules files mid-session.
Should I use a 5-minute or 1-hour prompt cache TTL?
A 5-minute cache write costs 1.25x the input price and pays off after one read; a 1-hour write costs 2x and pays off after two reads. Use 1 hour for the main conversation of long interactive sessions where you pause to review diffs, and keep 5 minutes for short-lived subagents. In Claude Code, set CLAUDE_CODE_PROMPT_CACHE_TTL and CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL.
Are local models a good way to cut AI coding costs?
For high-volume, low-reasoning work, yes: summarising logs, searching code, writing commit messages and simple edits. Open-source agents such as OpenCode, Cline and Aider can talk to a local model through an OpenAI-compatible endpoint (Ollama, LM Studio, llama.cpp). For complex multi-file changes, a hosted frontier model is usually cheaper per merged change because it needs fewer retries.
Is a subscription or API billing cheaper for Claude Code?
If you use the agent most working days, a subscription is usually cheaper than paying per token, and it also gets a 1-hour prompt cache on the main conversation by default. API billing fits occasional use, CI pipelines and batch jobs, where the Batch API gives a flat 50% discount.
Further reading
- How to minimise Cursor token spending
- OpenCode vs Claude Code vs Cursor: real workflow comparison
- Local vs remote AI agents
- AI agent debugging in production
- LogNroll product overview
Spend tokens on fixing, not searching. Try LogNroll for free and give your coding agent the exact session, errors and logs behind a bug.