AI agents · OpenClaw · self-hosting · automation

Quick Answer

How to Reduce AI Coding Agent Token Costs: 2026 Guide

Published:

The short answer

Most coding agent spend is re-reading context, not writing code — so cut what goes into context and match the model and effort to the task. Anthropic’s cost documentation puts the average Claude Code bill at about $13 per developer per active day ($150–250 a month), with 90% of users under $30 a day. The eight tactics below work in Claude Code, Codex and Cursor; the commands named are Claude Code’s. Facts are as of October 15, 2026.

1. Clear between unrelated tasks

Every turn re-sends the conversation. Stale context from the previous task is paid for again on every message. Use /clear when switching work (rename the session first if you want to return), and /compact with instructions — for example /compact Focus on code changes and test output — when you need continuity. Remember that compacting a huge context is itself a large request; /clear is free.

2. Use the mid-tier model by default

Anthropic’s guidance: Sonnet handles most coding tasks and costs less than Opus; reserve Opus for architecture and multi-step reasoning. At list price Claude Opus 5.5 is $4/$20 per million input/output tokens and Sonnet 5.5 is exactly half, $2/$10; GPT-6.1 Sol is $2/$10 and GPT-6 Astra $10/$50. Set the cheaper model as default and switch up with /model only when stuck.

3. Lower effort on simple tasks

Thinking tokens are billed as output, and default budgets can reach tens of thousands of tokens per request. Lower effort with /effort for renames, small fixes and boilerplate. Some current models cannot disable thinking entirely, so effort is the lever, not an off switch.

4. Trim MCP servers and tool definitions

MCP tool definitions are deferred by default in Claude Code, but server instructions still enter context. Run /context to see what is consuming space, disable servers you are not using with /mcp, and prefer CLIs such as gh, aws or gcloud, which add no per-tool listing.

5. Move workflow instructions out of CLAUDE.md

CLAUDE.md (or AGENTS.md in other tools) loads into every session. Long instructions for PR reviews or migrations cost tokens even when you are doing something else. Move them into skills, which load only when invoked, and keep the always-on file short.

6. Filter verbose output with hooks

A hook can preprocess tool output before the model sees it — for example, grep a 10,000-line test log for failures and pass only those lines. Anthropic’s documentation shows a PreToolUse hook that rewrites test commands this way, cutting context from tens of thousands of tokens to hundreds.

7. Delegate noisy work to subagents — on a cheap model

Running tests, fetching docs or reading logs in a subagent keeps the output in the subagent’s context and returns only a summary. Subagents still bill their own requests, so assign them a smaller model. For parallel agent teams, keep spawn prompts short: each teammate also loads CLAUDE.md, MCP servers and skills.

8. Protect the prompt cache

Cached input is cheap: Sonnet 5.5 cache reads cost $0.10 per million tokens against $2 for fresh input; GPT-6.1 Sol cached input is also $0.10. Claude Code’s /usage now shows the share of input served from cache and the likely cause of misses. Avoid changing tool definitions or the system prompt mid-session, and do not leave sessions idle past the cache lifetime before a big turn.

Track before you optimise

Use /usage (session cost and cache stats; plan users get a breakdown by skills, subagents and MCP servers), set team spend limits in the Claude Console, and pilot with a small group to get a baseline. API-level tactics such as batching and routing are covered in how to cut AI API costs; caching mechanics in prompt caching explained. Model rates are in our current API prices.

Last verified: October 15, 2026.

Sources