How do you keep long sessions from eating the whole context window?
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:
- Do you rely on native compaction, or roll your own context management?
- 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 — but mostly curious how others are handling this.)