name
context-compress
description
Compresses conversation context to reduce token usage while preserving code, paths, and instructions. Use when: compress context, reduce token usage, save tokens, context too long, optimize conversation, shrink context, summarize conversation.
version
1.0.0
metadata
Compresses and optimizes conversation context to reduce token usage while preserving critical information like code blocks, file paths, error messages, and user instructions.
/context-compress [--level light|medium|aggressive] [--pin "search term"] [--dry-run]
--level (default: medium) — Controls compression aggressiveness
light — Remove redundancy only (duplicate lines, repeated greetings)
medium — Summarize discussion, keep all code and errors verbatim
aggressive — Summarize everything except pinned segments and the latest turn
--pin "term" — Marks segments containing the search term as pinned (never compressed); repeatable
--dry-run — Shows token savings without applying compression
--encoding (default: cl100k_base) — tiktoken encoding for token counting
# Default medium compression
/context-compress
# Aggressive compression, pin a critical function
/context-compress --level aggressive --pin " handleAuth" --pin " migration SQL"
# Preview savings without compressing
/context-compress --dry-run
# Light pass — only remove redundancy
/context-compress --level light
The skill invokes scripts/compress.py with the conversation context piped via stdin. The script:
Parses the input into segments (code blocks, messages, tool results, etc.)
Classifies each segment by type: code, path, error, instruction, discussion, tool_result
Pins segments matching any --pin terms (protected from compression)
Compresses each segment using tier-appropriate strategies
Reports before/after token counts and compression ratio
Compressed output goes to stdout. Statistics JSON goes to stderr.
When to Use / When NOT to Use
Use when
Do NOT use when
Conversation context exceeds token budget
Input is under 500 tokens (auto-skipped)
Long debugging sessions with repetitive output
Code-only files with no conversation
Preserving key code while trimming discussion
You need lossless compression
Reducing costs on token-billed APIs
Input contains only pinned content
Conversations under 500 tokens: skip compression, report "nothing to compress"
Already-compressed segments (marked with <!-- compressed --> sentinel): skip on subsequent passes for idempotency
Binary/base64 blobs in tool results: preserve if under 200 tokens, replace with placeholder if over
Pinned terms matching zero segments: warn user, proceed with compression
Without tiktoken installed, token counts use whitespace splitting (less accurate)
Argument
Type
Default
Description
--level
enum
medium
light, medium, or aggressive
--pin
string[]
[]
Substrings to pin (repeatable)
--dry-run
flag
false
Report stats only, no output transformation
--encoding
string
cl100k_base
tiktoken encoding for token counting