LxveAce / Projects / Claude Compact Controller

Claude Compact Controller

A hook system for Claude Code that manages context window compression automatically. Tracks session state, backs up transcripts, and handles compaction events — with zero external dependencies.

v1.0.0 Stable MIT Node.js

Overview

Claude Code uses a context window that can fill up during long sessions. When it does, the system compresses older messages to make room. The Compact Controller hooks into that lifecycle and gives you visibility and control over the process.

It installs directly into Claude Code's hooks API and handles three events: Stop (when a session ends), PreCompact (before compression), and PostCompact (after compression). Each event triggers configurable actions like transcript backups, state snapshots, and threshold checks.

3 Hook Events
0 Dependencies
1 File

Features

🛑

Stop Hook

Fires when a Claude Code session ends. Captures final session state, writes a summary, and archives the transcript to a vault directory for later reference.

PreCompact Hook

Fires before context compression begins. Takes a snapshot of the current context window state so you have a record of what existed before messages were compressed.

PostCompact Hook

Fires after compression completes. Logs the compression ratio, tracks how much context was recovered, and updates session state with the new window boundaries.

📦

Transcript Vault

Automatically backs up full session transcripts before they get compressed. Stored in a configurable vault directory with timestamps and session IDs.

🎚️

Configurable Thresholds

Set custom thresholds for when compression should trigger. Control the aggressiveness of compaction based on your workflow and context needs.

📊

Session Tracking

Automatic state tracking across the session lifecycle. Know exactly how many compactions have occurred, what was preserved, and what was compressed.

Installation

Quick Setup

git clone the repo copy hooks to ~/.claude/ register in settings.json restart Claude Code

The controller is a single JavaScript file with no npm install needed. It reads from and writes to the Claude Code hooks API directory. Configuration lives in the same settings file Claude Code already uses.

Tech Stack

JavaScript Node.js Claude Code Hooks API Zero Dependencies
View full source on GitHub