Skip to main content

cc-compact

Two Claude Code CLI hooks that preserve task state, in-progress todos, and user preferences across auto-compaction, without bloating the context window.

How it works

  • PreCompact runs when the CLI is about to auto-compact. It reads the session transcript, extracts the last user message + in-flight turns + the latest TodoWrite snapshot, and writes a Markdown memory file to <project>/.claude/compact-memory/<session_id>.md.
  • UserPromptSubmit runs on every user prompt after the first compaction. It injects a short pointer telling the agent the memory file is available and may be read on demand.
  • Preferences are agent-authored — the hook preserves a ## Preferences section on every run, but does not populate it automatically. Append with the Edit tool when the user states a lasting preference.

Install

From PyPI:

pip install cc-compact
cd /path/to/your/project
cc-compact install

The installer automatically creates or updates .claude/settings.json with the required hook entries, preserving any existing configuration. To skip this and manage settings.json manually, pass --no-settings.

Upgrading

cc-compact install creates symbolic links into the installed package by default. After upgrading the package, your hooks in every project are automatically up-to-date — no need to re-run install per project:

pipx upgrade cc-compact   # or: pip install -U cc-compact

If you prefer to copy files (e.g., for portability across machines without the package installed), use --copy:

cc-compact install --copy   # needs --force to redeploy after upgrades

Windows falls back to --copy automatically (symlinks require admin rights).

Manual (without pip)

If you prefer not to pip install, copy cc_compact/ into your project's .claude/hooks/ directly. The deployed layout is:

<project>/.claude/hooks/
├── pre_compact.py
├── user_prompt.py
└── lib/
    ├── core.py
    ├── hook_runner.py
    ├── memory.py
    └── transcript.py

Verify

Run the manual trace script:

python3 tests/trace_run.py tests/fixtures/transcript_with_todos.jsonl

Run tests

pip install -e ".[dev]"
pytest --cov=cc_compact

Debug

Every hook run appends to <project>/.claude/compact-memory/<session_id>.trace.jsonl. tail -f this file to watch the hooks work in real time.

Metadata

Release files for cc-compact 0.1.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cc-compact 0.1.11
File Size Uploaded
cc_compact-0.1.11.tar.gz 26.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cc-compact 0.1.11
File Interpreter ABI Platform
cc_compact-0.1.11-py3-none-any.whl Python 3 none any Details

Total release size: 42.2 kB

Release files / cc_compact-0.1.11.tar.gz

Download URL cc_compact-0.1.11.tar.gz
Size 26.2 kB
Tags Source
SHA-256 checksum
How to use checksums
93089cc45ac1ba35d030c004cfab027302e390ed95181c2b10cd3aebbd2ef65a
BLAKE2b-256 checksum
How to use checksums
00ee20d9c79781ec91109635a13849f526b7da5268aff38a9e018b6cdbd6a26b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / cc_compact-0.1.11-py3-none-any.whl

Download URL cc_compact-0.1.11-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5441102cf90690f81b3ef9d5418f387484587d6775fd4859056794e6dea605d1
BLAKE2b-256 checksum
How to use checksums
9cf4752b792383dafdfa1d748168e8a0e2b323679fbd3f3901007aa0f78ffe6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

0.1.11 This release

2 release files

0.1.10

2 release files

0.1.9

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page