Iteratively summarize/compress project context until it fits target token budget.
Start the "Context Compression Loop" loop. - Goal: Project context document fits within the target token budget (default: 5000 tokens / ~4000 words) while retaining all information necessary for agent success. - Max iterations: 6 - Between iterations run: `wc -w CONTEXT.md` - Exit when: word count is under 4000 words AND the context still contains all critical constraints and conventions. Steps: 1. Measure the current context document size 2. If under budget, stop — exit condition met 3. Identify the lowest-value content: redundant examples, obvious statements, verbose explanations 4. Apply compression techniques: - Replace paragraphs with bullet points - Collapse multiple examples to one representative example - Remove information derivable from the codebase (file structure, obvious patterns) - Merge overlapping rules into single, more general statements - Remove historical context that doesn't affect current behavior 5. Verify no critical constraint was lost — cross-check against the last 5 agent failures 6. Re-measure and continue if still over budget Self-pacing instructions: After each iteration, run the check command, read the output, and only continue if the exit condition is not met. Stop when exit condition passes or max iterations reached. Give a short status update each pass.
How it works