Cutting AI Cost in OpenClaw: The Context Engine, Model Mixing, and Governance
A working field reference for enterprise teams: where OpenClaw spends, the forty levers that bring the bill down, and how to mix premium and local models while keeping a complete audit trail.
Where the money goes
OpenClaw is an open-source agent that runs real work across many steps, reaching for tools, notes, and files as it goes. The model it runs on has no memory between steps, so on every single step a part of OpenClaw called the context engine assembles the exact package the model will see. Whatever it packs, you pay for. And because it re-packs on every step, anything left in the package is paid for again and again. That re-packing decision is where most of your cost is made, and it is where most of your savings live.
The bill itself comes from text. Models read and write in small chunks called tokens (roughly three-quarters of a word each). You pay for tokens sent in (the package the context engine assembles) and tokens written back (the model's reply), and at most providers the reply costs several times more per token than the input. So three forces drive cost: how heavy the standing package is on every step, how much old material rides along, and how much the model writes back. This report walks through forty concrete levers across those forces, then the model-choice decisions and governance that hold the savings in place over time. The single most powerful idea is also the simplest: tune what the context engine includes, because that is the one cost surface every other cost flows through.
Incident operations platform baseline
The OpenClaw example follows alert ingestion, incident classification, runbook retrieval, dependency graph, remediation recommendations, review UI, audit log, pager, ticketing, CI connectors, tests, and deployment.
Costly default
The context engine packs broad bootstrap files, memory, raw logs, tool schemas, and premium routes into every step.
Optimized workflow
Context injection, bootstrap, memory, reducers, profiles, isolated workers, local routes, and chargeback shape the package per task risk.
Savings note: The package sent to the model shrinks and routine work moves to cheaper or local routes See Appendix A.1.
1. What you are paying for
OpenClaw runs on AI models, and you pay for text in both directions. The more text flows, the more you pay. Knowing which text is expensive tells you where to aim.
Every request has two halves. The input is everything the context engine packs and sends to the model: standing instructions, recent conversation, relevant saved notes, the files in play, and the results of tools. The output is what the model writes back. Input tokens are cheaper per token; output tokens cost several times more at most providers. A third, quieter cost is reasoning tokens, the hidden thinking some models do before they answer, which some providers bill as output and others fold into overhead.
Two patterns make cost climb faster than people expect. First, the standing package is paid on every step, so a heavy package multiplies across a long session. Second, history grows: without intervention a long conversation re-sends more and more of itself each turn, so a thirty-turn session can consume over a million tokens in total even though no single turn looked alarming. Most of this report is about flattening those two curves while keeping the work trustworthy.
Like a courier you pay by the pound, every trip
Send a single envelope and it is cheap. Send a box stuffed with every document you own, most of which the recipient does not need, and you pay for all that weight. Now imagine you send that same box on every trip of the day. With OpenClaw the question on every step is the same: what is actually in the box, and does it all need to be there this time?
openclaw status --usage and /context detail on a real session to see what is loaded and what it costs. You cannot trim a package you have not measured. Capture this as your baseline.Alert ingestion and classification packet
The platform classifies incoming alerts and routes them to incident classes.
Costly default
Raw alerts, full manifests, and complete logs go to a premium model for every classification.
Optimized workflow
Reducers produce compact incident packets with count, first failure, affected service, pointers, hashes, and confidence; local workers classify routine alerts.
Savings note: Token volume and model price both fall on the highest-volume path See Appendix A.2.
2. The context engine in depth
This is the heart of the bill. On every step the context engine assembles what the model sees. Tuning that assembly is the single highest-leverage thing you can do, and it starts with deciding how often the standing context is re-injected.
On each step the engine reaches for the standing instructions, the recent conversation, relevant saved notes, the files in play, and tool results, then packs them into one request. Because it re-packs every step, the standing material is the part to watch: it is paid repeatedly. The first knob is whether OpenClaw re-injects your workspace bootstrap files (the standing instructions, described in the next section) on every turn or more selectively.
2.1 Context injection mode
OpenClaw exposes a configuration key, contextInjection, that controls when bootstrap files are re-added to the system prompt. Three modes exist. "always" (the default) injects all bootstrap files on every single turn, so every follow-up message in a long session pays the full standing tax again. "continuation-skip" injects on the first turn and after any user prompt that follows a completed model response, but skips simple back-to-back continuations, removing duplicate injection. "never" performs no automatic injection at all; the agent must supply its own context, which is a large saving but only safe for specialized stateless agents.
Like an assistant re-packing your briefcase before every meeting
A careful assistant packs just what this meeting needs. A careless one keeps stuffing in everything from earlier "just in case," so the bag gets heavier all day. "always" re-stuffs the full standing kit every time. "continuation-skip" only re-stuffs when the situation actually changed.
A community case study measured roughly a 25 percent reduction in prompt tokens on multi-turn chats from this one change, and one report cited it among a handful of changes that took a monthly bill from over $1,500 to under $50. Volatile The exact percentage depends on session length and file sizes, so treat those numbers as direction, not a promise.
agents.defaults.contextInjection: "continuation-skip" for most interactive agents. Reserve "always" for compliance scenarios where every turn must restate rules, and use "never" only for purpose-built stateless automation that supplies its own prompts.2.2 Startup context
Separately, OpenClaw can inject a one-time prelude at the very first turn of a session, the startupContext, which can pull in recent daily memory logs (files named by date). The default is the last 2 days, up to 1,200 characters per file and 2,800 characters total. This buys session continuity but costs tokens on every session start, so for agents whose task is always fully specified in the request it is pure overhead.
startupContext.enabled: false for stateless automation agents. For interactive agents that rarely need two days of history, lower maxTotalChars from 2,800 to 800 to 1,200. Override per agent via agents.list[].startupContext so only agents that genuinely need continuity pay for it.Context injection by incident risk
A live investigation moves across several follow-up turns.
Costly default
OpenClaw injects full context every turn regardless of whether the task is a continuation.
Optimized workflow
Continuation-skip handles ordinary investigation follow-ups, while high-severity or regulated flows restate required safety rules.
Savings note: Duplicate standing context disappears from routine turns without weakening compliance paths See Appendix A.3.