Pre-Session vs Post-Session Budget Enforcement for AI Coding Agents
Only limits that block calls before overspending actually protect agent budgets.

AI coding agent budget caps stop unexpected API bills only when enforcement sits in the call path and blocks LLM calls before they go over an authorized budget. Post-session controls record what was spent after the chance to stop it has passed, whereas a managed platform for running coding agents such as Ellipsis, which handles budgets and sandboxes on its own infrastructure, is meant to apply limits before a session continues. Graceful shutdown also needs mid-session controls that return the best result so far, lower model cost, or checkpoint work before more spending is approved.
Why token-metered agents broke the budget models built for per-seat SaaS
Per-seat forecasting assumes that the cost of each licensed user stays much the same. Token-metered agents break that assumption in their day-to-day work. A single agent orchestrating a refactor can consume resources very differently from one handling a narrowly scoped change, while both occupy the same line in a headcount spreadsheet. The gap between light and heavy use can be orders of magnitude. So headcount cannot reliably tell teams how much agents will use.
The generated code is not the main cost driver. Repository maps, file reads, system prompts, and retry iterations account for the bulk of tokens consumed in a real session. As context expands, more work does not necessarily mean proportionately more useful output. Uber ranked engineers on internal leaderboards by AI tool usage, illustrating how incentives can turn consumption itself into a status signal. Gartner's 2026 outlook warns that a significant share of agentic AI projects will be cancelled by 2027 because of escalating costs, unclear business value, or inadequate risk controls.
What “budget enforcement” actually means — and what it does not
Monitoring reads what happened and exposes it through dashboards, logs, and alerts. Enforcement intercepts what is about to happen and evaluates it against policy before allowing it to proceed. A hard cap and an alert at the same threshold are not equivalent because only the cap prevents the call that would cross it. Databricks' guidance states the distinction explicitly. “Alerts notify after spending occurs. Hard limits stop the agent from making further LLM calls.”
A control can constrain activity without enforcing a complete task budget. API rate limits govern call counts or frequency, while workflow timeouts constrain duration and spend alerts report financial consumption. Technical Disclosure Commons' Adaptive Computational Budgeting for AI Agents in Collaborative Environments describes existing controls as “rudimentary” because they do not holistically integrate processing time, tokens, and API calls.
How post-session enforcement fails when agents run unsupervised
Post-session-only enforcement relies on spending coming to a stop before anyone acts to correct it. Autonomous work removes that dependable stopping point. Context expansion and replanning can turn a bounded request into dozens of calls, each including the accumulated history. A failing test or broken tool call can also trigger silent retries with no default cap. A documented 2025 case involving a four-agent LangChain pipeline ran in an infinite loop for 11 days before anyone intervened.
Alerts during a session shorten the reporting delay, but they do not remove the dependency on human intervention. An alert at 2 AM still needs a person to see it and stop execution before further spending occurs. The session does not pause merely because notification succeeds. Without an in-call-path limit, a shared budget can be exhausted while the alert awaits attention.
Anthropic shipped spend-threshold alerts, per-group and per-user spend dashboards, and an Analytics API exporting to Datadog and CloudZero on 2 July 2026. These controls provide useful enterprise visibility. However, a warning that a limit is approaching and an export of recorded usage do not themselves block the next LLM call. Their value is attribution, reporting, and response. The limitation follows from their architectural position.
How do hard spending limits stop agents before costs spiral?
Pre-session enforcement means that the decision precedes the LLM call's dispatch. Some controls establish authorization at session start. Others evaluate it at every call boundary. Both belong inside the call path, where denial can prevent additional consumption. Hard caps at the session, developer, and time-period level turn a spending policy into an execution boundary.
The enforcement layer must also be outside the agent. Ramp Labs Research found that coding agents based their judgments about more spending on how the prompt was framed, independently of how far their work had got. The worker freezes when it reaches its token limit, and a separate controller model evaluates whether to approve more spending. Its evidence is a snapshot of tasks completed, tokens used, files modified, tests run, and commands executed.
The Commons framework combines processing time, LLM tokens, and API calls because a token-compliant task can still run for hours or incur downstream API costs. Narrow context provides a complementary control before execution begins. Referencing specific files or modules instead of indexing an entire codebase reduces overhead before any cap is tested. OpenAI's API lets teams set organization-level and project-level spend limits, while Claude Code's /usage command shows real-time session token consumption so a developer can step in.
Adaptive mid-session enforcement as a middle path between hard stops and uncapped spend
A hard stop can protect the budget while damaging the usefulness of the work. Stopping a long-running refactor at 90% completion can leave the codebase in a partial state and waste tokens already spent. Adaptive enforcement addresses that trade-off without moving outside the call path. It changes the permitted next action as consumption approaches the limit. The budget still applies unless more spending is approved.
The Commons framework describes graceful termination, quality throttling, and checkpointing as dynamic responses. Graceful termination stops processing and returns the best result achieved within budget. Quality throttling switches to a faster, less resource-intensive model as the limit approaches. Checkpointing pauses the work, saves state, and can prompt the user before more spending is approved.
Quality throttling also makes model routing a runtime control. The choice of model can change during a session, with simple tasks moving to smaller models while frontier models are kept for complex reasoning. Administrative consoles set organizational limits, team policies define department allocations within them, and user and session budgets remain within team limits. A developer's local configuration cannot authorize spending beyond that hierarchy.
What a complete audit trail requires beyond cost visibility
Enforcement establishes what an agent may do, but it does not by itself explain what happened. Execution observability records tool calls, API invocations, data accesses, and system interactions. Intent observability records the goal state and decision context behind those actions, including the reasoning that can be checked. Both are needed for an accountable workflow. Without them, a blocked call shows a boundary was applied but provides too little context to judge the work that reached it.
The EU AI Act's Article 12 requires high-risk AI systems to record events automatically so they can be traced and monitored and risks can be found. It does not mandate recording whether each governance intervention was a hard gate or a soft gate. Operational accountability extends beyond that regulatory distinction. Multi-agent attribution chains cannot reliably be reconstructed after the fact if they were not instrumented during execution. Logs must link actions to their decision context as the work happens.
Every LLM call should have an audit event containing the model, provider, resolved endpoint, token counts, cost in USD, enforcement verdict, and findings. Useful attribution also includes the user, workspace, repository, branch, and task identifier, together with tool calls, files read or modified, and commands executed. Retry counts, final outcomes, approvals for write, delete, and network actions, and links to resulting pull requests or commits explain what the expenditure produced. These details expose tasks that consume the most tokens for the least output, supporting workflow changes and routing to cheaper models.
How sandbox isolation and credential scoping make pre-session enforcement enforceable
A budget cap cannot govern calls that bypass it. An agent with broad filesystem access, persistent credentials, and unrestricted network egress can invoke tools directly or preserve access across sessions. Sandboxing therefore bounds filesystem access, network egress, credentials, and git scope. Each boundary closes a route through which execution could incur spending or expose data outside the enforcement layer.
Credentials must be minted fresh for each session and revoked when it ends. A persistent API key is standing authorization that survives the budget under which it was issued. Declarative YAML makes the intended boundary reviewable as code. Configuration checked into the repository defines filesystem, network, process, and inference controls, so changes can be reviewed, versioned, and audited like other infrastructure changes.
Resource isolation also needs to reach below model calls. The “propose/dispose” pattern applies container constraints through --pids-limit, --memory, and --cpus, bounding runaway builds or fork bombs independently of the agent's reports. Shadow AI remains outside those protections entirely. An agent running outside the sandbox on a developer's laptop or through an ungoverned MCP server connection produces no enforcement signal, audit event, or budget attribution in the governance layer. Sensitive code can leave unseen because that layer governs only activity routed through it.
Putting the architecture together — what teams need before scaling agents across an engineering organization
Teams should establish session isolation and scoped credentials first, because a cap without an isolation boundary is advisory. Credentials should be issued at session start and revoked on completion, without persistent keys handed to agents. Versioned YAML should define the controls governing that environment. This makes the execution perimeter reviewable before broader access is granted.
Next, teams should set hard per-session and per-developer token budgets in the call path before giving agents more access to production systems. The budget policy should also account for processing time and downstream API calls where those resources contribute to task cost. The decisive criterion is whether the control blocks further LLM calls before they exceed authorization. Organization-level reporting and real-time usage displays remain useful, but neither establishes that property on its own.
With those limits in place, teams should define how execution approaches them. Quality throttling, graceful termination, or checkpointing should produce an intentional transition that avoids an unexpected abort during a refactor. Full audit events should then link each call's enforcement verdict to its token counts, tool activity, and cost in USD. These records make both spending decisions and completed work queryable afterward.


