Install
openclaw skills install context-slimSee exactly what's eating your context window. Analyzes prompts, conversations, and system instructions to show where every token goes. Actionable compressio...
openclaw skills install context-slimSee exactly what's eating your context window. Analyzes prompts, conversations, and system instructions to show where every token goes. Actionable compression suggestions. All local.
Stop guessing why your AI forgot something. See exactly what's eating your context window.
ContextSlim analyzes your prompts, conversations, and system instructions to show you where every token goes. Get actionable compression suggestions and visual breakdowns — all without sending anything to external APIs.
You're talking to an AI and suddenly it forgets critical information. Or your carefully crafted system prompt keeps getting cut off. Why? Because context windows aren't infinite, and most people have no idea how much space they're actually using.
Token counting is confusing. Different providers use different models. You don't want to install heavyweight tokenizer libraries just to get a ballpark estimate. And even if you could count tokens, you still don't know where they're being wasted.
context_slim.py)Estimates token usage using word-based heuristics. No external dependencies, no API calls, no tokenizer libraries. Accurate within 10-15% for most English text.
context_compress.py)Analyzes your text and tells you exactly what you can cut, tighten, or simplify.
context_report.py)Generates beautiful HTML reports with CSS-based bar charts (zero JavaScript).
# Analyze a text file
python3 context_slim.py my_prompt.txt
# Get compression suggestions
python3 context_compress.py my_prompt.txt
# Generate full HTML report with suggestions
python3 context_report.py my_prompt.txt --compress --output report.html
# Analyze for a specific provider
python3 context_slim.py --provider anthropic --model claude-3-opus prompt.txt
# Get high-confidence suggestions only
python3 context_compress.py --min-confidence high prompt.txt
# Read from stdin
cat system_prompt.txt | python3 context_slim.py
# JSON output for scripting
python3 context_slim.py --output json prompt.txt > analysis.json
ContextSlim understands conversation JSON format:
[
{"role": "system", "content": "You are a helpful assistant..."},
{"role": "user", "content": "Tell me about..."},
{"role": "assistant", "content": "Sure! Here's..."}
]
python3 context_slim.py conversation.json
Before you deploy that 10,000-word system prompt, see how much space it actually takes. Find what you can cut without losing functionality.
AI stopped following your instructions? See if your prompt is getting truncated. ContextSlim shows you exactly where the cutoff happens.
Tokens = money. Compress your prompts, reduce costs. See exactly how many tokens each compression saves.
Switching between GPT-4 (128k) and Claude (200k)? See how your prompts fit in each context window.
Running an AI agent with tons of tools and memory? Profile which components are eating the most tokens.
Enforce context budgets across your team. "System prompts must be under 5k tokens" — now you can actually measure it.
ContextSlim uses word-based heuristics instead of external tokenizers:
Plus adjustments for:
Why not use real tokenizers?
They require heavyweight dependencies (transformers, tiktoken) and still vary between models. Word-based estimation is "good enough" for profiling and costs zero dependencies.
ContextSlim scans for:
Each suggestion includes:
Copy config_example.py to config.py and customize:
# Set default provider
PROVIDER = 'anthropic'
MODEL = 'claude-3-opus'
# Adjust truncation risk thresholds
TRUNCATION_THRESHOLDS = {
'none': 50,
'low': 70,
'medium': 85,
'high': 95,
'critical': 100
}
# Control compression suggestions
MIN_CONFIDENCE = 'medium'
MAX_SUGGESTIONS_PER_CATEGORY = 5
See config_example.py for full options.
$ python3 context_slim.py system_prompt.txt --provider openai --model gpt-4
=== ContextSlim Analysis ===
Provider: openai (limit: 128,000 tokens)
Total tokens: 8,432
Utilization: 6.59%
Truncation risk: NONE
Section breakdown:
[file] 8,432 tokens (11,234 words)
$ python3 context_compress.py system_prompt.txt --min-confidence high
=== ContextSlim Compression Analysis ===
Found 7 suggestions
Potential savings: 127 tokens
1. [REDUNDANCY] Replace "in order to" with "to"
Confidence: high | Saves: ~3 tokens
Original: ...in order to provide accurate responses...
Suggested: ...to provide accurate responses...
2. [VERBOSITY] Simplify verbose phrase
Confidence: high | Saves: ~5 tokens
Original: ...has the ability to process...
Suggested: ...can process...
$ python3 context_report.py conversation.json --compress --output report.html
✅ Report generated: report.html
Open report.html in a browser to see:
| File | Purpose |
|---|---|
context_slim.py | Main analysis engine (CLI + library) |
context_compress.py | Compression suggestion engine |
context_report.py | HTML report generator |
config_example.py | Configuration template |
README.md | This file |
LIMITATIONS.md | Honest limitations |
LICENSE | MIT License |
Use ContextSlim in your own scripts:
from context_slim import ContextAnalyzer, TokenEstimator
from context_compress import CompressionAnalyzer
from context_report import ReportGenerator
# Analyze text
analyzer = ContextAnalyzer(provider='anthropic', model='claude-3-opus')
profile = analyzer.analyze_text("Your prompt here...")
print(f"Tokens: {profile.total_tokens}")
print(f"Risk: {profile.truncation_risk}")
# Get compression suggestions
compressor = CompressionAnalyzer(provider='anthropic')
suggestions = compressor.analyze("Your prompt here...")
print(f"Could save {compressor.estimate_total_savings(suggestions)} tokens")
# Generate HTML report
html = ReportGenerator.generate_profile_report(profile, suggestions)
with open('report.html', 'w') as f:
f.write(html)
Q: How accurate is the token estimation?
A: Within 10-15% for English text. Good enough for profiling, not perfect. If you need exact counts, use the provider's official tokenizer.
Q: Does it work for non-English text?
A: Estimation accuracy drops for non-English. Word-to-token ratios vary by language. You can adjust ratios in config.py.
Q: Does it send my data anywhere?
A: No. Everything runs locally. Zero network calls, zero external APIs.
Q: Can I use it for code?
A: Yes, but code has different token patterns than prose. Estimates may be less accurate for heavily formatted code.
Q: What about multimodal contexts (images, audio)?
A: Text-only for now. See LIMITATIONS.md.
MIT — See LICENSE file.
Shadow Rose
Built for AI users who want to understand and optimize their context windows without needing a PhD in tokenization.
This software is provided "AS IS", without warranty of any kind, express or implied.
USE AT YOUR OWN RISK.
By downloading, installing, or using this software, you acknowledge that you have read this disclaimer and agree to use the software entirely at your own risk.
DATA DISCLAIMER: This software processes and stores data locally on your system. The author(s) are not responsible for data loss, corruption, or unauthorized access resulting from software bugs, system failures, or user error. Always maintain independent backups of important data. This software does not transmit data externally unless explicitly configured by the user.
| 🐛 Bug Reports | TheShadowyRose@proton.me |
| ☕ Ko-fi | ko-fi.com/theshadowrose |
| 🛒 Gumroad | shadowyrose.gumroad.com |
| @TheShadowyRose | |
| 🐙 GitHub | github.com/TheShadowRose |
| 🧠 PromptBase | promptbase.com/profile/shadowrose |
Built with OpenClaw — thank you for making this possible.
🛠️ Need something custom? Custom OpenClaw agents & skills starting at $500. If you can describe it, I can build it. → Hire me on Fiverr