Why Your AI Agent Is Burning Through Tokens (And How to Fix It)
A single conversation can balloon to 424,000 input tokens without you realizing it. Here's what causes token bloat in AI agents and how context pruning brings it back under control.
OCLauncher Team
Building AI tools that work while you sleep.

Why Your AI Agent Is Burning Through Tokens (And How to Fix It)
Last week we noticed something alarming in our production logs: a routine OpenClaw conversation had ballooned to 424,000 input tokens in a single LLM request. That’s roughly the length of a 300-page book — sent to the API on every single message.
The agent was working fine. No errors, no crashes. It was just quietly spending 10–20x more on API calls than it needed to.
If you’re running an AI agent — whether self-hosted or through a platform — this is probably happening to you too. Here’s why, and what you can do about it.
What’s Eating Your Tokens
AI agents like OpenClaw work by maintaining a conversation history that gets sent to the LLM with every new message. Each turn of the conversation includes:
- The system prompt (instructions, personality, tool definitions)
- Every previous user message and assistant response
- The results of every tool call the agent has made
That last one is the problem.
When an agent runs a command, fetches a file, or queries an API, the full output of that operation gets stored in the conversation history. A single config.schema command might return 30,000 characters of JSON. A session transcript dump could be 50,000+. These outputs pile up silently because the agent keeps working — it never tells you the context is getting bloated.
Here’s what the token breakdown looked like in our 424K case:
| Source | Tokens | Share |
|---|---|---|
| Tool call results (accumulated) | ~350,000 | 82% |
| Previous assistant responses | ~45,000 | 11% |
| System prompt + tool definitions | ~20,000 | 5% |
| User messages | ~9,000 | 2% |
Over 80% of the tokens were old tool outputs that the agent no longer needed. They were just sitting in the conversation history, getting replayed turn after turn, costing money every time.
What This Costs You
Token pricing varies by provider, but the numbers add up fast. Here’s what 424K input tokens would cost per message with popular models:
| Model | Input Price (per 1M tokens) | Cost per 424K-token request |
|---|---|---|
| Claude Sonnet 4.5 | $3.00 | $1.27 |
| Claude Opus 4 | $15.00 | $6.36 |
| GPT-4o | $2.50 | $1.06 |
| Gemini 2.5 Pro | $1.25 | $0.53 |
If the agent handles 50 messages per day at this bloated level, you’re looking at $50–300/month in wasted API costs — just on input tokens. And that’s for a single user.
The other cost is less obvious: quality. Most LLMs perform worse when the context window is packed. Important instructions get buried under pages of stale tool output. The model’s attention gets diluted. Responses become less relevant and less coherent.
How Context Pruning Fixes This
Context pruning is a strategy that automatically trims old, low-value content from the conversation history before sending it to the LLM. The idea is simple: keep what the agent needs to maintain coherence, discard what it doesn’t.
OpenClaw supports a pruning mode called cache-ttl that works in two stages:
Soft trim kicks in when context usage reaches a threshold (default: 75% of the model’s context window). It takes older tool outputs and truncates them — keeping the first and last 2,000 characters while removing the middle. This preserves enough context for the agent to understand what a tool returned without carrying the full payload.
Hard clear activates at a higher threshold (default: 90%). It removes old tool outputs entirely, keeping only the most recent assistant responses so the agent doesn’t lose track of the conversation.
Both stages are progressive — they only activate when needed, and they prioritize removing the oldest, largest tool outputs first.
What We Changed
In runtime version 0.6.11, we enabled context pruning by default for all OCLauncher instances. Here are the specific settings:
{
"contextPruning": {
"mode": "cache-ttl",
"ttl": "5",
"keepLastAssistants": 5,
"softTrimRatio": 0.75,
"hardClearRatio": 0.9,
"minPrunableToolChars": 2000,
"softTrim": {
"maxChars": 20000,
"headChars": 2000,
"tailChars": 2000
},
"hardClear": {
"enabled": true
}
}
} What each setting does:
ttl: 5— tool outputs older than 5 turns become eligible for pruningkeepLastAssistants: 5— always preserve the 5 most recent assistant responsessoftTrim— truncate large tool outputs to 20K chars max, keeping 2K from the head and tailhardClear— when context hits 90%, remove old tool outputs entirelyminPrunableToolChars: 2000— don’t bother trimming small outputs
We also added guidance for the agent itself: avoid calling commands that produce huge outputs (like full schema dumps), use limit parameters when querying history, and prefer concise tool usage.
The expected result: that 424K request drops to roughly 30,000–50,000 tokens — an 88–93% reduction. The agent works the same way, just without dragging around a novel’s worth of stale data.
What You Can Do
If you’re using OCLauncher: you don’t need to do anything. Runtime version 0.6.11 and later include these defaults automatically. You can check your version on the dashboard and update if needed.
If you’re self-hosting OpenClaw: add the contextPruning block above to your openclaw.json file under agents.defaults. OpenClaw’s file watcher picks up changes automatically — no restart required.
If you’re building your own agent: the principle applies regardless of framework. Audit your conversation history regularly. Look for large tool outputs that persist across turns. Implement some form of trimming — even a simple “drop tool results older than N turns” strategy will save you significant costs.
The takeaway: an AI agent that seems to be running fine can still be wasting the majority of its token budget on stale context. A few lines of configuration can cut your API costs by 90% without any change in behavior.
Want to run your own AI agent without managing infrastructure? Sign up for OCLauncher — context pruning and automatic updates are included out of the box.