Imported from jonnathan-ls/ai-context-kit (
skills/token-compressor/SKILL.md). Install upstream withnpx skills add jonnathan-ls/ai-context-kit --skill token-compressor. Copyright stays with the author.
Token Compressor
This skill reduces token overhead by compressing bulky inputs (logs, stack traces, long docs) while preserving evidence.
When to Use
- The user pastes long logs.
- Tool output is huge.
- A file is too large to read fully.
Compression Rules (Deterministic)
Apply these tactics in order:
-
Keep evidence lines
- Always keep lines matching:
error,exception,traceback,fail,warning,fatal.
- Always keep lines matching:
-
Keep structure
- Keep the first N lines (header/context) and last M lines (final error).
-
Deduplicate noise
- Collapse repeated consecutive lines.
- Collapse repeated blocks (same line repeated many times).
-
Summarize the rest
- Replace large omitted blocks with a short note:
(… 3,421 lines omitted …).
- Replace large omitted blocks with a short note:
Tooling
If available, use the bundled compressor script:
python3 ~/.ai-context/skills/token-compressor/scripts/compress_text.py --help
Output Format
## Compressed Context
- Source: …
- Original: X lines
- Kept: Y lines
- Notes: …
```text
…compressed excerpt…
## Anti-Patterns
- Removing the exact error line.
- Keeping only a summary with no evidence.
- Dumping the entire log into the reasoning window.