context-hygiene-systemlisted
Install: claude install-skill Beidou1507/code-claw
# Context Hygiene System
## Overview
Context hygiene is more than summarizing when the window gets full. It is a continuous cleaning system that budgets tool output, trims redundant history, compacts strategically, recovers from overflow, and keeps attachments plus queued commands in a stable order.
## Source Anchors
- `src/query.ts`
- `src/services/compact/`
- `src/services/contextCollapse/`
## Workflow
1. Start each turn with memory and skill-discovery prefetch so waiting time is hidden behind model streaming.
2. Apply tool-result budgets early and replace oversized results with persisted references when needed.
3. Run snip, microcompact, context collapse, and autocompact in a deliberate order instead of mixing them freely.
4. When compaction succeeds, rebuild task budget tracking, turn tracking, and post-compact messages from the new state.
5. Withhold prompt-too-long, media overflow, and max-output errors until recovery paths have been attempted.
6. Use context-collapse drains and reactive compaction as structured recovery steps before surfacing failure upstream.
7. At the end of the turn, collect tool-use summaries, memory attachments, skill attachments, and queued commands while deduplicating them.
8. Refresh the tool pool after the turn if capabilities changed so the next iteration sees the right tool surface.
## Design Rules
- Prefer preserving recent high-granularity context over collapsing everything into one coarse summary.
- Give each compaction layer a di