Guides · Updated October 25, 2026
How to set a budget limit for Aider
Aider is bring-your-own-key: every message goes straight to your model provider and lands on your API bill. Aider has no setting that stops a session at a dollar amount. What it does have is a live cost readout, a few settings that control how many tokens each message sends, and a built-in cap on its own fix-and-retry cycles. The hard limit has to live at the provider. This guide covers all three layers and how to set them up so a long session can’t surprise you.
The short version
- Hard cap: set it on the API key or project at your provider (OpenRouter key credit limit, Anthropic Console workspace limit, OpenAI project budget). Aider can’t spend past what the key is allowed to.
- Watch: read the
Cost: $x message, $y session.line Aider prints after every reply, and run/tokensbefore a big request. - Shrink each message:
/dropfiles you’re done with,/clearbetween tasks, and set--max-chat-history-tokens. - Scripts and CI: wrap
aider --messageintimeoutand give the job its own key with its own limit.
1. Put the hard limit on the API key
Because Aider calls the provider directly with your key, the only place a real dollar limit can be enforced is the provider. Give Aider its own key so the limit applies to Aider alone and its usage shows up separately on the bill:
- OpenRouter: when you create a key you can give it a credit limit. Once the key has spent that much, requests with it fail. Good for a per-project or per-month Aider budget, and it works with any model OpenRouter routes to.
- Anthropic: in the Claude Console, create a workspace for Aider, set a spend limit on the workspace, and create the API key inside it.
- OpenAI: create a project for Aider, set its budget, and use a key from that project. Check in the dashboard whether the budget on your account blocks requests or only sends alerts, and set alerts either way.
- Prepaid credit is the bluntest cap there is: with auto-reload off, a key can’t spend more than the balance.
When the limit trips, Aider shows the provider’s error and the request fails. Nothing is lost: your files and Aider’s git commits are still there.
2. Read the cost line, and know when it’s missing
After each reply Aider prints something like:
Tokens: 18k sent, 6.1k cache hit, 412 received. Cost: $0.03 message, $1.84 session.
The session figure is the running total since you launched Aider. It resets when you quit, so it is a per-session meter, not a history. Two caveats:
- No pricing, no cost. Aider only prints a dollar figure when it knows the model’s per-token price. For a model it doesn’t recognize, you get the token counts only. Add the price yourself in
.aider.model.metadata.json(or point--model-metadata-fileat one) so the estimate shows up. - It’s an estimate. It comes from public list prices and the usage the provider reports. Your provider’s billing page is the real number.
For what the next message will cost, run /tokens. It breaks the request down into system prompt, chat history, repo map and each added file. Every part is re-sent with every message, so the biggest line on that list is what to cut.
3. Make every message smaller
Aider sends the files in the chat, the repo map and the chat history with each request. A session gets more expensive per message as it goes, even if your prompts stay short. The settings that matter most:
- Only add files that need editing. Use
/read-onlyfor reference files, and/dropa file as soon as you’re done with it. Aider warns when you add a lot of files for a reason. /clearbetween tasks. It drops the chat history but keeps the files./resetdrops both.--max-chat-history-tokens. A soft limit: when the history passes it, Aider summarizes the older messages with the weak model. Lower it to keep long sessions lean, for exampleaider --max-chat-history-tokens 8000.--map-tokens. The repo map defaults to 1024 tokens and grows when no files are in the chat. Lower it in huge repos, or set it to0when you’re adding the right files yourself. Large repos also benefit from--subtree-onlyand an.aiderignore.--cache-promptson models that support prompt caching (Anthropic, DeepSeek and others). Re-sent context that hits the cache is billed at a fraction of the normal input price.- Cheaper models where they’re good enough.
--weak-modelhandles commit messages and summaries. In architect mode,--editor-modelcan be a cheaper model than the one doing the planning. - Thinking budgets.
--thinking-tokensand--reasoning-effort(or/think-tokensand/reasoning-effortmid-chat) cap how much a reasoning model thinks per reply. Thinking tokens are billed as output.
4. Aider’s own retry limit
Aider loops less than agentic tools because you drive each turn. Its one automatic cycle is the fix-and-retry after an edit: if the edit didn’t apply cleanly, or lint fails, or tests fail with --auto-test and --test-cmd set, Aider sends the error back to the model and tries again. That cycle is capped at three reflections per message; after that you see Only 3 reflections allowed, stopping. Lint and test fixes also ask first (“Attempt to fix lint errors?”) unless you run with --yes-always.
The loop you actually pay for is the human one: you type “still failing, try again”, the model makes the same change, and the chat gets longer each time. When the cost line climbs and the error doesn’t change:
/undothe last Aider commit (or several) to get back to a clean state.- Run the failing command with
/runor/testso the model sees the full, real output instead of your summary. /clear, then restate the problem with the new fact. The old attempts in the history pull the model toward the same fix.- Ask before editing:
/ask why does this test still fail? Don’t change any code yet.
5. Scripted and CI runs
aider --message "..." runs one instruction and exits, and --yes-always approves every prompt. In a script that means nobody is watching the cost line. Put the limits around the process:
# one key per pipeline, with its own credit limit at the provider export OPENROUTER_API_KEY="$AIDER_CI_KEY" timeout 15m aider --yes-always --no-auto-commits \ --max-chat-history-tokens 6000 --map-tokens 512 \ --message "Fix the failing test in tests/test_parser.py" src/parser.py tests/test_parser.py
timeout(or your CI job’s timeout) bounds the wall-clock time, and with it the number of requests.- A dedicated key with a small credit limit bounds the money, whatever the script does.
- Don’t put
aider --messagein a shellwhileloop that retries until tests pass. That is the runaway loop, just written by you.
More on per-run caps for headless agents in setting a hard budget for AI coding agents in CI.
Where LoopGuard fits
LoopGuard enforces session and daily caps and blocks no-progress repeats through the hook systems of Claude Code, Codex CLI and Cursor. Aider has no tool-call hooks to attach to, so LoopGuard doesn’t guard Aider sessions. For Aider, the key-level limit above is the hard stop. If you also use one of those three agents, npm i -g loopguard-cli && loopguard init adds per-session and daily caps to them in a minute, and loopguard report shows what they spent.
Related
- How to stop runaway Claude Code, Codex and Cursor agent loops
- How to track AI coding agent token costs per session
- How to set a spending limit for Claude Code
- How to limit Cursor agent usage costs
- How to cap OpenAI Codex CLI spend
- Claude Code usage limit reached: why it happens and how to monitor it
- How to set a hard budget for AI coding agents in CI
- Claude Code stuck in a loop: how to break it and stop it repeating the same command
- Codex usage limit reached: 5-hour and weekly limits explained
- Cursor agent stuck in a loop: how to stop it, roll back, and keep it from repeating
- Why Claude Code uses so many tokens, and how to use fewer
- GitHub Copilot agent mode stuck in a loop: how to stop it and keep it from repeating
- Cline stuck in a loop: how to stop it, roll back, and cap what it spends
- Gemini CLI usage limits: daily quotas, the June 2026 change, and keeping costs in check
- Codex stuck in a loop: how to stop it, undo it, and keep it from repeating