Jump straight to the numbers

← All articles

36,000 to 12,000 Tokens: Trim Your Agent's Context

01 / A six-turn example: 36,000 input tokens become 12,000

A coding agent can spend more tokens rereading your project than writing your fix. Old tool output, unrelated files, and repeated instructions can all travel into later requests. On a tiny budget, controlling that input is often the first useful optimization.

Consider an illustrative task with six model requests. At an average of 6,000 input tokens per request, that is 36,000 input tokens. Reduce the average to 2,000 and the total becomes 12,000: about 67% fewer input tokens. This is arithmetic, not a benchmark or a promised bill reduction. Output tokens, cache pricing, and extra requests still affect the bill.

02 / Set a $1 experiment limit before opening the repository

Choose one small task: fix an empty-input crash, add one validation rule, or repair one failing test. Avoid starting with a repository-wide cleanup. Write down the acceptance test before asking the agent to investigate.

For example: empty search input should return an empty list, and the existing search tests should pass. That gives the agent a finish line without requiring a tour of the application.

  • ■ Set a personal experiment budget, such as $1. Use a provider-side hard spending limit if available; a note in your prompt is not an enforceable cap.
  • ■ Record your starting usage or balance and the model you selected.
  • ■ Review usage after each short work cycle. One apparent agent turn may trigger several billed requests.

03 / Send one relevant file, not the whole project

Begin with the failing test, the error message, and the smallest relevant function or file. Include paths so the agent can request more precisely. State any important constraint, such as preserving the public function signature.

A useful opening instruction is: Fix the empty-input failure in src/search.ts. Start with this function and its failing test. Inspect additional files only when needed, and explain what information is missing.

Do not paste dependency directories, generated bundles, lockfiles, or secrets by default. Configure your agent's ignore and context controls where supported. A search exclusion does not necessarily prevent another tool from reading a file, so check what your particular client actually sends.

04 / Trim terminal output before it becomes conversation history

A thousand lines of test output can become expensive baggage. First run the narrowest relevant test. Keep the failing assertion, the useful stack frames, and enough surrounding output to explain the failure.

  • ■ Search for a function name before asking the agent to read several directories.
  • ■ Prefer a bounded excerpt around a match over a complete file dump.
  • ■ For repeated failures, report what changed instead of reposting identical logs.
  • ■ Keep full logs locally so you can retrieve omitted details if necessary.

Trimming must preserve evidence. Removing the exception type or the actual and expected values may force another request, cancelling the saving.

05 / Replace stale history with a compact handoff

Deleting text from your latest message does not necessarily remove earlier messages from the API request. Many agents keep previous tool results in their conversation history. Use the client's compaction feature, or start a fresh session with a short handoff when the history becomes mostly irrelevant.

Include five things: the goal, relevant paths, confirmed findings, changes already made, and the next test. For example: Empty search crashes in src/search.ts. Added an early return. Focused tests pass; full suite not run. Next, inspect the diff for unintended changes.

Keep unresolved questions explicit. A summary that turns a guess into a fact can make the next session confidently wrong.

06 / Check the receipt, not just the context counter

Compare input tokens, output tokens, cache reads, cache writes, and total charges where your client or provider exposes them. Cached input may cost less than uncached input, but it is not automatically free. Rewriting a stable prefix can also reduce cache reuse.

CheapRelay offers pay-as-you-go API access for tools including Claude Code, Codex, and Gemini CLI, with no monthly fee or subscription. Billing covers real tokens, including cache reads and writes. Sign up for CheapRelay when you are ready to measure a small, bounded coding task.

Keep the smaller context only if the fix remains correct. The target is less irrelevant input, not the fewest tokens at any cost.

Sign up Try the prices yourself, sign-up credit included.

More reading

DateAisleWritten inTitle
2026-10-28Coding agents, cheaplyEN$1 Budget: Catch a Coding Agent Loop Before It Spends
Spot repeated tool calls, rising token use and stalled edits early, then stop and restart a coding agent within a tiny budget.
2026-10-28Coding agents, cheaplyEN$1 Budget: Codex and Claude Code on One Tiny Repo
Compare Codex and Claude Code on one tiny Python repo with a $1 planning budget, identical tasks, local tests, and honest cost tracking.
2026-10-28Coding agents, cheaplyEN$0.50 task budget: Claude Code, fewer file reads
A beginner workflow for limiting Claude Code's file reads, narrowing searches, and checking token spending on a tiny pay-as-you-go budget.
2026-10-28Coding agents, cheaplyENSave Tokens: 6 Claude Code Commands for 2026
A practical 2026 guide to /compact, /clear, /context and other Claude Code commands that reduce waste on pay-as-you-go billing.
2026-10-28Coding agents, cheaplyEN$2 Budget: Connect a VS Code Assistant
Connect a VS Code assistant to an OpenAI-compatible API, test one small task, and track token costs with a $2 planning budget.
2026-10-28Coding agents, cheaplyEN$1 Test Budget, 2 Variables: Claude Code on a Relay
Connect Claude Code to CheapRelay with two environment variables, then run a small test and check token charges before spending more.