Compress Claude Code chat sessions to preserve key information while reducing size.
curl -sSL https://raw.githubusercontent.com/unclecode/claude-compress/main/install.sh | bashOr with gh cli:
gh repo clone unclecode/claude-compress && cd claude-compress && ./install.shRun the same install command to update to the latest version:
curl -sSL https://raw.githubusercontent.com/unclecode/claude-compress/main/install.sh | bashANTHROPIC_API_KEYenvironment variable set- Python 3.8+ (uses only built-in modules, no pip dependencies)
/ccomp
/ccomp 50%
/ccomp focus on API implementation, ignore debugging steps
/ccomp 40% keep file paths and commands, remove explanations
ccomp # Default 30% compression
ccomp --target 50 # 50% compression
ccomp --focus "keep API calls" # With focus guidelines
ccomp --target 40 --focus "ignore logs" # Combined
ccomp --help # Show all optionsThis will:
- Detect your current chat session
- Extract all messages
- Compress long messages to ~30% of original size
- Save output to current directory as
chat_compressed_<timestamp>.txt
# Copy script
mkdir -p ~/.claude/scripts
cp compress_chat.py ~/.claude/scripts/
chmod +x ~/.claude/scripts/ccomp_chat.py
# Copy command
mkdir -p ~/.claude/commands
cp compress.md ~/.claude/commands/Run the script directly with custom options:
python3 ~/.claude/scripts/ccomp_chat.py --cwd "$(pwd)" \
--target 30 \ # Target compression % (default: 30)
--min-length 1000 \ # Only compress lines >= this length (default: 1000)
--min-output 500 \ # Exclude lines < this from output (default: 500)
--batch-size 5 \ # API batch size (default: 5)
--workers 2 \ # Concurrent workers (default: 2)
--focus "keep API calls, ignore logs" # Focus guidelines (optional)- Detects current project from working directory
- Finds most recent session in
~/.claude/projects/<project>/ - Extracts messages (user, assistant, tool results)
- Compresses long messages using Claude Haiku API
- Preserves all file paths, commands, numbers, and technical details
- Outputs single-line compressed messages with
|separators