context-hygiene-kit

Installs a bounded scored context cache with lifecycle hooks into Claude Code projects.

1|Updated May 28, 2026
One-click install
npx skills add https://github.com/dhanesh/agent-skills --skill context-hygiene-kit-dhanesh
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: context-hygiene-kit
Source: https://github.com/dhanesh/agent-skills/tree/main/context-hygiene-kit
Command: npx skills add https://github.com/dhanesh/agent-skills --skill context-hygiene-kit-dhanesh

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve? Long Claude Code sessions suffer from two failure modes: context bloat, where the window grows unbounded until responses degrade, and context rot, where compaction summarizes away the specific decisions, constraints, and file:line references that mattered. This kit installs a token-budget-capped, scored, tiered cache plus deterministic per-turn capture so durable facts survive compaction and sessions stay lean. ## Core Features & Use Cases - Bounded scored ledger: A stdlib-only Python ContextLedger curates context cards under a hard token budget via greedy knapsack eviction, preserving high-salience kinds (decisions, constraints, file refs) verbatim. - Deterministic harvester: harvest.py captures DECISION:/CONSTRAINT:/FILE: marker lines, the latest user request, and file:line references from the trusted channel only — no model summarization, closing the prompt-injection surface. - Three lifecycle hooks: Stop (capture + flush every turn), PreCompact (anti-rot digest refresh), and SessionStart (inject digest instead of raw history), merged additively into settings.json. - Use Case: A developer running multi-hour refactoring sessions installs the kit once per project; after a compaction or abrupt terminal close, the next session loads a ranked digest of verbatim decisions instead of replaying or losing history. ## Quick Start Ask Claude to set up context hygiene for this project by running the kit's install script at project scope, then restart Claude Code so the hooks load.

Frequently Asked Questions about context-hygiene-kit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stop Claude Code context from bloating in long sessions?▼

Install this kit once per project or globally; it registers a SessionStart hook that loads a token-budget-capped digest instead of raw history. The ledger's curate() enforces a hard budget cap, so the hot context window stays bounded regardless of session length.

How to make Claude remember decisions across compaction?▼

Tag facts inline with marker lines like DECISION: or CONSTRAINT: as you work. The Stop hook harvests them deterministically every turn, and the PreCompact hook refreshes a lossless digest so high-salience kinds survive the summarizer verbatim.

Does this context cache work with global Claude Code installs?▼

Yes, running install.sh --global places scripts and hooks in ~/.claude/context-hygiene and registers them in ~/.claude/settings.json, covering every project. Memory stays per-project: each repo gets its own .context/ directory created on the first turn.

Can I run context-hygiene-kit alongside world-model-ledger?▼

Yes, but avoid two project-scoped installs in the same repo because both ship colliding harvest.py and hooks/stop.sh filenames. Install at least one with --global; the settings.json hook merges are additive and the marker namespaces are disjoint.

What are the limitations of the deterministic harvester?▼

The harvester captures only marker lines, the latest substantive user request, and file:line references from user and assistant text; tool_result blocks are never ingested. Facts without markers require explicit CLI ingest, and worst-case loss on abrupt close is one in-flight turn.

Why does the installer fail or skip hook merging?▼

The installer runs a 27-test suite as a gate, so failing tests block the guarantees from shipping. Without jq and an existing settings.json, it writes settings.hooks.json for manual merge instead of merging automatically.