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

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:

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:

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:

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:

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

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

LoopGuard on GitHub · Pricing