#Help needed: OpenClaw agent maxing out 200k context window
1 messages ยท Page 1 of 1 (latest)
Iโm checking the docs/source for how OpenClaw compacts history and whether this looks like a model/provider issue vs a config issue.
That sounds annoying. I think this is most likely tool-output bloat, not โ200k is too smallโ.
A few concrete things to check first:
-
Paste your version
openclaw --version -
Paste a status snapshot
openclaw status --all -
In the chat/session that keeps bloating, run:
/status
/context detail
/context detail is the big one, it shows what is actually consuming tokens.
- Paste these config bits from
openclaw.json:models.providers.ollama.baseUrlagents.defaults.contextPruningagents.defaults.compaction
Two likely causes from the docs:
- Session pruning is off by default for non-Anthropic providers, so with Ollama/Kimi, old tool results can pile up fast.
- If your Ollama base URL uses
/v1, that is wrong for OpenClaw and can break tool calling / dump raw tool JSON into history. It should be the native Ollama URL, for example:
{
models: {
providers: {
ollama: {
baseUrl: "http://your-ollama-host:11434"
}
}
}
}
If pruning is missing, Iโd try this first:
{
agents: {
defaults: {
contextPruning: {
mode: "cache-ttl",
ttl: "5m",
keepLastAssistants: 3,
softTrimRatio: 0.3,
hardClearRatio: 0.5,
minPrunableToolChars: 50000,
softTrim: { maxChars: 4000, headChars: 1500, tailChars: 1500 },
hardClear: { enabled: true, placeholder: "[Old tool result content cleared]" }
}
}
}
}
Also useful right now:
/compact
If the session is already cursed, just start fresh:
/new
Relevant docs:
If you paste the version, status, /context detail, and those config bits, I can usually pinpoint it pretty fast.
- OpenClaw 2026.4.22 (00bd2cf)
- Overview
โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Item โ Value โ
โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Version โ 2026.4.22 โ
โ OS โ linux 6.8.0-110-generic (x64) โ
โ Node โ 22.22.2 โ
โ Config โ ~/.openclaw/openclaw.json โ
โ Dashboard โ http://127.0.0.1:18789/ โ
โ Tailscale โ off โ
โ Channel โ stable (config) โ
โ Update โ pnpm ยท up to date ยท npm latest 2026.4.22 โ
โ Gateway โ local ยท ws://127.0.0.1:18789 (local loopback) ยท reachable 75ms ยท auth token ยท af853a79e598 (172. โ
โ โ 16.1.2) app 2026.4.22 linux 6.8.0-110-generic โ
โ Security โ Run: openclaw security audit --deep โ
โ Gateway self โ unknown โ
โ Gateway service โ systemd not installed โ
Node service โ systemd not installed โ
โ Agents โ 1 total ยท 0 bootstrapping ยท 0 active ยท 2 sessions โ
โ Secrets โ none
Status:
๐ฆ OpenClaw 2026.4.22 (00bd2cf)
๐ง Model: ollama/kimi-k2.6:cloud ยท ๐ unknown
๐งฎ Tokens: 235k in / 670 out
๐ Context: 59k/200k (30%) ยท ๐งน Compactions: 3
๐งต Session: agent:main:main โข updated just now
โ๏ธ Runtime: direct ยท Runner: pi (embedded) ยท Think: low
๐ชข Queue: collect (depth 0)
Context detail:
๐ง Context breakdown (detailed)
Workspace: /data/.openclaw/workspace
Bootstrap max/file: 12,000 chars
Bootstrap max/total: 60,000 chars
Sandbox: mode=off sandboxed=false
System prompt (run): 35,729 chars (~8,933 tok) (Project Context 16,408 chars (~4,102 tok))
Injected workspace files:
โข AGENTS.md: OK | raw 7,907 chars (~1,977 tok) | injected 7,907 chars (~1,977 tok)
โข SOUL.md: OK | raw 2,677 chars (~670 tok) | injected 2,677 chars (~670 tok)
โข TOOLS.md: OK | raw 952 chars (~238 tok) | injected 952 chars (~238 tok)
โข IDENTITY.md: OK | raw 504 chars (~126 tok) | injected 504 chars (~126 tok)
โข USER.md: OK | raw 905 chars (~227 tok) | injected 905 chars (~227 tok)
โข HEARTBEAT.md: OK | raw 1,438 chars (~360 tok) | injected 1,438 chars (~360 tok)
โข BOOTSTRAP.md: MISSING | raw 0 | injected 0
โข MEMORY.md: OK | raw 3,203 chars (~801 tok) | injected 3,203 chars (~801 tok)
Skills list (system prompt text): 4,349 chars (~1,088 tok) (8 skills)
Skills: clawhub, healthcheck, himalaya, node-connect, skill-creator, taskflow, taskflow-inbox-triage, weather
Top skills (prompt entry size):
โข skill-creator: 756 chars (~189 tok)
โข taskflow: 540 chars (~135 tok)
โข node-connect: 538 chars (~135 tok)
โข healthcheck: 488 chars (~122 tok)
โข clawhub: 429 chars (~108 tok)
โข taskflow-inbox-triage: 415 chars (~104 tok)
โข weather: 413 chars (~104 tok)
โข himalaya: 380 chars (~95 tok)
Tool list (system prompt text): 0 chars (~0 tok)
Tool schemas (JSON): 25,136 chars (~6,284 tok) (counts toward context; not shown as text)
Tools: read, edit, write, exec, process, canvas, nodes, cron, message, tts, gateway, agents_list, sessions_list, sessions_history, sessions_send, sessions_spawn, sessions_yield, subagents, session_status, web_fetch, browser, memory_search, memory_get
Top tools (schema size):
โข cron: 6,700 chars (~1,675 tok)
โข message: 5,767 chars (~1,442 tok)
โข browser: 2,799 chars (~700 tok)
โข nodes: 1,589 chars (~398 tok)
โข sessions_spawn: 1,333 chars (~334 tok)
โข exec: 1,096 chars (~274 tok)
โข process: 961 chars (~241 tok)
โข edit: 834 chars (~209 tok)
โข canvas: 661 chars (~166 tok)
โข gateway: 537 chars (~135 tok)
โข sessions_list: 432 chars (~108 tok)
โข web_fetch: 374 chars (~94 tok)
โข read: 304 chars (~76 tok)
Nice, version looks current, so this is probably not a stale-build bug.
What Iโd check next:
- Make sure Ollama is using the native API URL, not
/v1
If you use{ models: { providers: { ollama: { baseUrl: "http://your-ollama-host:11434" } } } }...:11434/v1, OpenClaw docs call that out as bad for tool calling, and it can dump ugly raw tool JSON into history.
Docs: https://docs.openclaw.ai/providers/ollama
- Enable session pruning explicitly
For non-Anthropic setups, this is the first thing Iโd try:{ agents: { defaults: { contextPruning: { mode: "cache-ttl", ttl: "5m", keepLastAssistants: 3, softTrimRatio: 0.3, hardClearRatio: 0.5, minPrunableToolChars: 50000, softTrim: { maxChars: 4000, headChars: 1500, tailChars: 1500 },
hardClear: { enabled: true, placeholder: "[Old tool result content cleared]" }
}
}
}
}
This trims old tool results before each LLM call, which is usually the real context killer.
Docs: https://docs.openclaw.ai/concepts/session-pruning
-
Then start a fresh session
/newIf the current thread is already bloated, fixing config alone wonโt magically make that history small.
-
Paste this too
/context detail
Thatโs the fastest way to see whether the growth is:
- tool results
- giant bootstrap/system prompt
- attachments/images
- just a runaway long transcript
If you want, paste these 3 config sections and I can sanity-check them:
models.providers.ollamaagents.defaults.contextPruningagents.defaults.compaction
Also useful docs:
My bet right now: either /v1 is in the Ollama URL, or pruning is off, and old tool output is eating the whole window.
"providers": {
"ollama": {
"baseUrl": "http://172.16.1.1:32769",
"api": "ollama",
"apiKey": "ollama-local",
"models": [
{
"id": "kimi-k2.6:cloud",
"name": "kimi-k2.6:cloud",
"api": "ollama",
"reasoning": false,
"input": [
"text"
],
"cost": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0
},
"contextWindow": 200000,
"maxTokens": 8192
},
{
"id": "nomic-embed-text",
"name": "nomic-embed-text",
"api": "ollama",
"reasoning": false,
"input": [
"text"
],
"cost": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0
},
"contextWindow": 2048,
"maxTokens": 2048
"defaults": {
"workspace": "/data/.openclaw/workspace",
"model": {
"primary": "ollama/kimi-k2.6:cloud"
},
"models": {
"ollama/kimi-k2.6:cloud": {
"alias": "kimi-k2.6"
}
},
"thinkingDefault": "low",
"memorySearch": {
"enabled": true,
"sources": [
"memory",
"sessions"
],
"experimental": {
"sessionMemory": true
},
"provider": "ollama"
},
"compaction": {
"memoryFlush": {
"enabled": true
}
},
"maxConcurrent": 4,
"subagents": {
"maxConcurrent": 8
}
}
},
Yep, this helps a lot.
Good news: your Ollama config looks correct. You are using the native API (api: "ollama", no /v1), so I donโt think this is the /v1 tool-calling bug.
What jumps out instead: you have no agents.defaults.contextPruning configured at all.
For this setup, thatโs the first thing Iโd fix. Without pruning, old tool results just keep piling up in the in-memory prompt until compaction has to save you.
Iโd change this first:
{
agents: {
defaults: {
contextPruning: {
mode: "cache-ttl",
ttl: "5m",
keepLastAssistants: 3,
softTrimRatio: 0.3,
hardClearRatio: 0.5,
minPrunableToolChars: 50000,
softTrim: {
maxChars: 4000,
headChars: 1500,
tailChars: 1500
},
hardClear: {
enabled: true,
placeholder: "[Old tool result content cleared]"
}
}
}
}
}
Second thing, a bit suspicious:
memorySearch: {
enabled: true,
sources: ["memory", "sessions"],
experimental: { sessionMemory: true }
}
That is not automatically bad, but if the agent likes calling memory_search, it can start pulling transcript-derived stuff back into the conversation. With pruning off, that can get ugly fast.
So while debugging, Iโd temporarily simplify it to:
memorySearch: {
enabled: true,
sources: ["memory"],
experimental: { sessionMemory: false },
provider: "ollama"
}
Then:
- restart OpenClaw
- start a fresh chat session with:
/new
- run:
/context detail
If it still blows up after that, paste the /context detail output. That report is the fastest way to see whether the bloat is coming from:
memory_searchreadexec- huge tool schemas/results
- or just plain transcript length
Docs: