{"repo":"emanueleielo/compact-middleware","free":true,"listed":false,"github":"https://github.com/emanueleielo/compact-middleware","clone":"git clone https://github.com/emanueleielo/compact-middleware.git","description":"Claude Code's compaction engine, as a drop-in DeepAgents middleware","language":"Python","stars":44,"topics":["ai-agents","claude-code","compaction","context-management","deepagents","middleware","python"],"license":"MIT","category":"ai-agents","readme_excerpt":"compact-middleware Claude Code's compaction engine, as a drop-in DeepAgents middleware. Problem &bull; How it works &bull; Quick start &bull; Configuration &bull; Comparison --- Long-running AI agents hit the context window wall. The built-in SummarizationMiddleware does a single-pass summary with a generic prompt — it works, but it loses critical details and has no lightweight fallbacks. compact-middleware takes the battle-tested compaction pipeline from Claude Code and makes it a composable DeepAgents middleware. One import, and your agents handle 10x longer conversations without blowing the context window. --- The Problem What goes wrong Built-in middleware compact-middleware --- --- --- Summary loses file paths, code, user feedback Generic prompt 9-section structured prompt Every compaction = expensive LLM call Yes 3 free levels tried first Recently-read files vanish after compaction Yes Auto-restores top 5 files + active plan Compaction fails and retries forever Yes Circuit breaker after 3 failures No way to clear stale tool results cheaply Correct Time-based microcompaction (free) Token counting is pure heuristic Yes Hybrid: real API usage + heuristic tail --- How It Works Lightweight levels run every turn (each with its own trigger), matching Claude Code's query.ts pipeline. The expensive LLM summarization only fires when tokens exceed the global threshold: Levels 1-3 are free (no LLM call) and run unconditionally — each has its own internal trigger (group size, arg le","default_branch":null,"files":null,"tree":[],"storefront":"/r/emanueleielo","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/emanueleielo/compact-middleware/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}