Skip to Content
IDEsAider

Tokenminning in Aider

Aider is a terminal git-native coding agent. Every message resends the repo map, conversation history, and configured conventions. Most spend comes from repo map bloat, architect/edit two-model cycles, and duplicated instructions in CONVENTIONS.md—not from one verbose reply.

Work through the sections below in order. For the general technique stack, see Where to start. For underlying patterns, see Context hygiene, Model routing, and Prompt hygiene. If you use OpenRouter as your provider, read that guide for key caps and model lists.

Quick checklist

  1. Run /tokens in Aider or check your provider dashboard after a heavy week.
  2. Refresh the repo map only when structure changes—avoid /map-refresh every message.
  3. Use a mid-tier model for most edits. Reserve architect mode and frontier models for large refactors.
  4. Keep CONVENTIONS.md and .aider.conf.yml instructions short.
  5. Scope files with /add—do not map the entire monorepo for a one-line fix.
  6. Commit in small batches so /drop and map size stay manageable.

Typical impact when you follow the list: 30–50% savings by trimming repo map size; 40–70% by avoiding architect mode on small tasks; 20–40% on input by shorter conventions files. Benchmark on /tokens and your provider bill.

How Aider bills a request

Aider is BYOK: OpenAI, Anthropic, OpenRouter, Ollama, and others via API keys in .aider.conf.yml or environment variables. Each message sends:

  • Your prompt
  • Repo map — summarized tree of relevant files (major input cost)
  • Files explicitly added with /add
  • CONVENTIONS.md / .aider.conventions.md when configured
  • Chat history in the session

Architect mode uses two models—one plans, one edits—roughly doubling inference on those tasks.

Repo map tokens scale with repository size and /add scope. Refreshing the map or adding large directories spikes input immediately.

1. Measure first

Where to look:

  • /tokens — context breakdown in the Aider session
  • Provider dashboard — Anthropic, OpenAI, OpenRouter Activity 
  • Git diff size — large multi-file commits often correlate with large maps

After a heavy week, check whether spend is map-dominated (input) or architect/loop-dominated (output). That tells you which section below to prioritize.

2. Match the model to the task

See Aider’s model docs  and your provider pricing. This is Aider’s version of Model routing: default cheap, escalate only on failure.

Start here:

  • Single model, mid-tier — most /add + edit sessions
  • Weak model for map, strong for edit — advanced config for large repos (when supported)
  • Architect mode — cross-cutting refactors that need a plan first
  • Frontier — only when mid-tier fails on complex design

Costs more than you expect:

  • Architect mode for one-file fixes
  • /map-refresh habitually
  • /add of entire packages
  • OpenRouter frontier IDs without fallbacks

3. Trim what rides along every request

Input bloat in Aider usually comes from the repo map and conventions—not your prompt text alone.

Repo map

The map is Aider’s largest standing input cost.

  • /add only files the task touches
  • Use .aiderignore for generated code, vendored deps, and build artifacts
  • Avoid /map-refresh unless files were added/removed structurally
  • Split monorepo work by package—run Aider from subdirectory when possible

CONVENTIONS and config

Instructions in CONVENTIONS.md and aider.conf.yml inject every session.

  • Short conventions — test commands, commit style, architecture one-liners
  • Do not duplicate README and conventions content
  • Move rare workflows to comments the agent reads on demand via /add of a doc file

Architect vs edit

Architect mode plans then edits with a second model.

  • Skip architect for localized bugs and single-file features
  • Use architect when the change spans many files and needs an explicit plan first
  • Review the architect plan before edit phase—reject broad plans early

Git scope

Aider works best with focused git context.

  • Work on a clean branch with small diffs
  • /clear chat when switching unrelated tasks—history adds tokens
  • /drop files removed from scope

See Context hygiene for the general just-in-time retrieval pattern.

New session per task

Run /clear or restart Aider when switching tasks. Map + history from task A should not ride along on task B.

4. Write tighter prompts

Aider-specific versions of Prompt hygiene:

Too broad:

Fix this bug. Also review the whole auth system and suggest improvements.

Scoped:

Fix ONLY the null check in auth/login.ts line 42. No explanations. Max 1 file changed.

Use /add auth/login.ts before the prompt so the map stays minimal.

5. Set spending guardrails

Aider does not enforce your inference budget. You set the limits.

  • Set provider or OpenRouter key spending limits 
  • Disable architect mode in .aider.conf.yml for daily driver alias
  • Use /tokens before large refactors—if map > 50% of context, /drop or narrow /add
  • Separate API keys for experiments vs production repos

For metering and caps in products you ship, see Article I and Article IV.

Troubleshooting

High input — repo map or conventions bloat. .aiderignore; narrow /add; shorten CONVENTIONS.

High output — architect mode on small task or frontier model. Single-model mid-tier; skip architect.

Map refresh every message — habit or unstable tree. Refresh only on structural changes.

OpenRouter cost surprise — wrong model slug or no fallbacks. See Tokenminning with OpenRouter.

Context overflow — too many /add files. /drop; work subdirectory-by-subdirectory.

When Aider optimization is not enough

Trimming Aider configuration does not fix production agent loops in your own API routes. If customer-facing features dominate spend, instrument with per-feature tags and apply Context hygiene, Prompt caching, and Output and RAG. Narev  provides normalized USD across providers if you need cross-provider cost math.

Last updated on