How do you keep long sessions from eating the whole context window?

Reddit r/openclaw Tools

Summary

A user shares a custom Plugin SDK hook that gradually compresses older turns while keeping recent ones raw to prevent context window exhaustion in long OpenClaw sessions, reducing re-sent context by 80%.

I've been running multi-hour OpenClaw sessions and the context window fill-up is my main pain. Native compaction kicks in late (around the threshold) and it's all-or-nothing — once it summarizes, older detail is gone. What I wanted instead: compress \*gradually\*, every turn, but keep the last few turns completely raw so the agent doesn't lose the thread it's mid-way through. I ended up writing a Plugin SDK hook on before\_prompt\_build that does this — folds older turns into a compressed episodic view, keeps the trailing turns verbatim. On a long session it cut the re-sent context by roughly 80% without the agent losing track of earlier turns. Two questions for people running long sessions: 1. Do you rely on native compaction, or roll your own context management? 2. Has anyone found the right "keep N turns raw" number? I'm defaultingto 4 but it feels workload-dependent. (If useful, the hook is here — MIT core: [https://github.com/compresh/compresh-mcp](https://github.com/compresh/compresh-mcp) — but mostly curious how others are handling this.)
Original Article

Similar Articles

@rwayne: Context Mode solves the other half of AI Agent context issues: sandboxed tool outputs + persistent sessions. A 56 KB Playwright snapshot compressed to 299 bytes, 98% of data never entering the context. Every file edit, Git operation, task decision is stored into…

X AI KOLs Timeline

Context Mode is a tool that solves AI agent context problems by sandboxing tool outputs and persisting sessions, achieving up to 98% compression of Playwright snapshots and using BM25 retrieval to reduce context window usage. It supports 15 platforms including Claude Code, Gemini CLI, VS Code Copilot, and is used by major tech companies.