VanaAPI

← 文章

Keep Your Coding Agent Within a Daily Budget

终端里的 AgentEN2026-10-25

A daily coding budget needs more than a reminder in the prompt. Give each task a spending allowance, track usage across sessions, and put the stopping rule outside the agent. This walkthrough uses an illustrative $10 daily ceiling; choose an amount that fits your work.

§ Step 1: Define the day and divide the budget

Choose a reset time and timezone, such as midnight UTC. Count every agent session, background worker, and automated retry against that same day. Do not reset the ledger just because you restart your terminal.

For the $10 example, allocate $7 to implementation, $2 to testing and review, and $1 as safety headroom. These are planning allowances, not predictions. Keep the reserve unavailable to ordinary tasks rather than treating it as extra spending money.

§ Step 2: Connect one client and check billing

Start with one coding client before adding parallel workers. Vana API provides connection instructions for Claude Code, Codex, Gemini CLI, and OpenAI-compatible clients, with different base-path requirements. Follow the instructions for your client rather than copying another tool’s configuration. Create a Vana API account, configure your credentials locally, and keep them out of repository files. ([vanaapi.com](https://vanaapi.com/plug-in?locale=en))

Run one small task, then check the resulting charge and applicable token prices. Use Vana API’s published prices for your estimates instead of assuming that a client’s built-in pricing matches your bill. ([vanaapi.com](https://vanaapi.com/price?locale=en))

§ Step 3: Give the agent a bounded task

Write down the permitted files, expected change, verification command, and stopping condition. Specific prompts help avoid broad repository exploration and unnecessary file reads. ([code.claude.com](https://code.claude.com/docs/en/costs))

For example: Fix the empty-input handling in the parser. Change only the parser and its tests. Run the parser test suite. Stop after two unsuccessful repair attempts and summarize the blocker.

Set an initial task allowance of $1.50. Require approval before widening the scope or starting another attempt. Treat these instructions as workflow guidance, not financial enforcement.

§ Step 4: Add a run limit

For non-interactive Claude Code, an example command is claude -p --max-budget-usd 1.50 --max-turns 8 'Fix the parser empty-input bug and run its tests'. The budget flag uses estimated API spending; the turn flag limits agentic turns. Both apply to print mode. ([code.claude.com](https://code.claude.com/docs/en/cli-reference))

This is a run-level safeguard, not a shared daily cap. Claude Code documents that spending can exceed the estimated threshold, and earlier spending restored through a resumed conversation does not count toward that run’s cap. Leave headroom and track the daily total separately. ([code.claude.com](https://code.claude.com/docs/en/cli-reference))

§ Step 5: Enforce the daily total outside the agent

For unattended work, implement a shared ledger in a launcher or request gateway that you control. Before dispatching a request, reserve its conservative maximum cost. Use enforced context and output limits, current rates, and any separately billed token categories. Afterward, replace the reservation with the recorded charge.

  • Available budget: daily ceiling minus recorded spending, outstanding reservations, and safety headroom.
  • Dispatch rule: reject work whose reservation exceeds the available budget.
  • Concurrency rule: update the ledger atomically so workers cannot spend the same remaining allowance.
  • Failure rule: retain uncertain reservations until reconciled; do not assume a missing response means zero cost.

If you cannot bound request costs or intercept every worker, do not describe the setup as a guaranteed hard cap. Use supervised runs until those controls exist.

§ Step 6: Review progress before spending more

After each task, record its cost, changed files, test result, and whether it met the acceptance criteria. In Claude Code, the session usage display reports token statistics and an estimated dollar amount; that estimate may use list prices unless configured otherwise. Reconcile it with your actual billing records. ([code.claude.com](https://code.claude.com/docs/en/costs))

At $8 of recorded or reserved spending, pause implementation and assess what remains. Use the review allowance only for a defined verification task. When the dispatch rule blocks further work, save the patch, test results, and next action. Resume tomorrow from that checkpoint rather than increasing the budget automatically.