Customize Claude Code's compaction experience with automatic conversation export and context injection
Project description
claude-compact
Customize Claude Code's compaction experience by automatically exporting full conversations before compaction and injecting context pointers afterward.
The Problem
When Claude Code compacts your conversation (at ~95% context), the built-in summary often loses critical details:
- File paths and code changes
- Error messages and debugging steps
- Architectural decisions and their rationale
- Tool call inputs and outputs
The Solution
claude-compact installs hooks that:
- Before compaction: Export the full conversation to a readable markdown file
- After compaction: Tell Claude where to find the exported file
Claude can then read the full conversation history when needed, preserving all context.
Installation
pip install claude-compact
Quick Start
# Install the hooks
claude-compact install
# Check status
claude-compact status
# That's it! Now when Claude Code compacts, your conversations are preserved.
Commands
Installation
claude-compact install # Install hooks into Claude Code
claude-compact uninstall # Remove hooks, config, and exports
claude-compact status # Check installation status
Configuration
claude-compact config show # Show all settings
claude-compact config set KEY VALUE # Set a configuration value
claude-compact config reset # Reset to defaults
Available settings:
| Setting | Default | Description |
|---|---|---|
export_dir |
~/.claude/hooks/exports |
Where to save exports |
export_format |
markdown |
Format: markdown, json, html |
detailed |
true |
Include tool calls in export |
trigger |
both |
Hook trigger: auto, manual, or both |
cleanup_enabled |
true |
Auto-cleanup old exports |
cleanup_mode |
age |
Cleanup by age or count |
cleanup_max_age_days |
30 |
Delete exports older than N days |
cleanup_max_count |
50 |
Keep only N most recent exports |
prompt_template |
(see below) | Message injected after compaction |
Exports Management
claude-compact exports list # List all exports
claude-compact exports list -n 10 # List last 10 exports
claude-compact exports clean # Clean based on config
claude-compact exports clean -d 7 # Delete exports older than 7 days
claude-compact exports clean -k 20 # Keep only 20 most recent
claude-compact exports open 1 # Open most recent export in editor
Prompt Customization
Customize the message Claude sees after compaction:
claude-compact prompt show # Show current template
claude-compact prompt set # Edit template (opens editor)
claude-compact prompt reset # Reset to default
Default template:
IMPORTANT: This conversation was compacted. The FULL conversation before compaction is saved at:
{export_path}
If you need details from earlier in the conversation (file paths, error messages, code changes, tool calls, decisions made, etc.), use the Read tool to read that file.
Available variables:
{export_path}- Full path to the exported file{session_id}- Session ID{timestamp}- Export timestamp
How It Works
File Locations
- Hooks:
~/.claude/hooks/claude-compact-*.py - Config:
~/.claude/hooks/claude-compact-config.json - Exports:
~/.claude/hooks/exports/(configurable) - Claude settings:
~/.claude/settings.json
Troubleshooting
Hooks not running?
- Check installation:
claude-compact status - Verify settings.json has the hooks:
cat ~/.claude/settings.json | grep claude-compact - Try reinstalling:
claude-compact uninstall && claude-compact install
Export not created?
- Ensure
claude-conversation-extractoris installed:pip install claude-conversation-extractor - Check if you can run it manually:
claude-extract --list
Claude doesn't see the context?
The injected context is invisible to you but visible to Claude. Ask Claude: "Do you see any context about an exported conversation?"
Uninstalling
# Remove hooks, config, and exports
claude-compact uninstall
# Remove the package
pip uninstall claude-compact
The uninstall command removes:
- Hook scripts (
~/.claude/hooks/claude-compact-*.py) - Config file (
~/.claude/hooks/claude-compact-config.json) - Exports folder (
~/.claude/hooks/exports/)
License
MIT
Contributing
Contributions welcome! Please open an issue or PR.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file claude_compact-0.1.8.tar.gz.
File metadata
- Download URL: claude_compact-0.1.8.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5e0d60e3213c47afe17a895180a20c2d397c9f7c115f0e55277f39837f4d2cc
|
|
| MD5 |
66e83dfd3f9a13a5daa7b3c8694606a8
|
|
| BLAKE2b-256 |
ed34a5b47d1c8c8446edc4412a389edaba636e5d5374c6cc267d15fb5a20742f
|
File details
Details for the file claude_compact-0.1.8-py3-none-any.whl.
File metadata
- Download URL: claude_compact-0.1.8-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7dea9c2d5f77f739f8b54679266c195307eada4883549330c2f0e2f255acedd
|
|
| MD5 |
7196f859406dc77e0940f64cc497488f
|
|
| BLAKE2b-256 |
9e59bd5c40790ad0739c5b23568d241efd652a9970ba46e8b00b00d39d542e78
|