Claude Code Context Diet

•

Optimizes Claude Code session context by compressing tool outputs through deduplication, stripping, and truncation.

Combat token bloat and context degradation in Claude Code sessions with this essential hook. Claude Code's 1M-context window often degrades past 200K tokens, and tool results can rapidly inflate token usage, leading to slower, dumber sessions and faster rate-limit exhaustion. This package addresses these issues by applying three deterministic transformations to tool outputs—Dedupe, Strip, and Truncate—before they re-enter your context. This proactive approach significantly reduces token consumption, extending the useful life of your sessions without involving LLM calls or external telemetry, providing a crucial workaround for persistent context management challenges.

Key Features

01Deduplicates 'Read' results to prevent redundant context entries for the same file path and content.
02Truncates large tool results by replacing the middle section with a placeholder, preserving the head and tail.
030 GitHub stars
04Pure Node.js implementation with zero external dependencies, ensuring transparency and minimal overhead.
05Configurable settings for truncation thresholds, deduplication window size, and specific stripping patterns.
06Strips ANSI codes, spinner characters, trailing whitespace, and duplicate blank lines from 'Bash' output.

Use Cases

01Optimize and clean the output from 'Read', 'Bash', 'Grep', and 'Glob' tool commands before context re-entry.
02Reduce token consumption and improve session performance within Claude Code environments.
03Prevent context window degradation and extend the effective working duration of Claude Code sessions.