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

Don't trust large context windows

Hacker News Top

An analysis of why advertised large context windows for LLMs are misleading, as effective attention drops off around 100k tokens, and practical advice for developers to keep sessions in the 'smart zone' by using artifacts and handoffs.

What memory you're using with your Openclaw?

Reddit r/openclaw

A developer discusses building a custom memory plugin for the Hermes agent using Engram, which reconciles new information with existing memories to avoid staleness and duplication, and asks the OpenClaw community about their memory usage.