Replace base64 image blocks in session JSONL with concise, context-aware text descriptions. Images consuming 15,000–25,000+ tokens become ~100 token descriptions — a 99%+ reduction. OpenClaw's built-in pruning explicitly skips images. This is the only tool that solves this.
When triggered, present an interactive menu using inline buttons (Telegram/Discord).
Run a dry-run first to show the user what's available:
bash
python3 <skill_dir>/scripts/shrink.py --agent <agentId> --dry-run --json
Parse the JSON output and present:
text
🔍 Context Scan Complete
📊 Found {images_found} images in this session
• {images_deduped} duplicates detected
• Est. savings: ~{tokens_saved:,} tokens ({savings_percent}%)
• Est. cost: ~${estimated_cost_usd:.3f}
Then offer buttons:
If no images found: "✅ No unprocessed images found. Session is already optimized!"
On "Shrink Now", run live and keep the user informed with progress updates.
For large runs (10+ images), send a progress message and update it as images complete:
text
🖼️ Shrinking Wayne (36 images)...
✅ 1/36 — Quicknode dashboard (23K tokens saved)
✅ 2/36 — ♻️ Duplicate (reused)
✅ 3/36 — Wagyu portfolio (21K tokens saved)
...running total: 68K saved
bash
python3 <skill_dir>/scripts/shrink.py --agent <agentId>
Report the full summary stats when complete.
After shrinking completes, inform the user that changes are saved to disk but agents still hold old context in memory. Offer to apply immediately:
text
⚠️ Changes saved to disk. Agents are still using old context in memory.
Present buttons:
openclaw gateway restart (~5 sec downtime, all agents reload clean)If user chooses "Apply Now", run:
bash
openclaw gateway restart
Then confirm: "✅ Gateway restarted. All agents now running on shrunk sessions."
Important: Warn that "Apply Now" causes ~5 seconds of downtime for ALL agents, not just the shrunk one.
Show current settings and let the user adjust:
Present buttons:
--all-sessions/shrink all#When user says "shrink all", "shrink all sessions", or "shrink everything":
bash
python3 <skill_dir>/scripts/shrink.py --agent <agentId> --all-sessions --dry-run --json
Present totals across all sessions, then confirm before running live.
bash
# Basic: current session dry-run
python3 scripts/shrink.py --agent main --dry-run
# Live shrink with all defaults
python3 scripts/shrink.py --agent main
# All sessions for an agent
python3 scripts/shrink.py --agent main --all-sessions
# Specific session file
python3 scripts/shrink.py --session-file path/to/session.jsonl
# Budget-conscious: limit images and use cheaper model
python3 scripts/shrink.py --agent main --max-images 5 --model claude-haiku-4-5
# JSON output for programmatic use
python3 scripts/shrink.py --agent main --all-sessions --json
FlagDefaultDescription--session-file—Path to specific JSONL file--agent <id>—Target agent's sessions directory--all-sessionsoffProcess all JSONL files for the agent--dry-runoffPreview without modifying--modelautoVision model (auto-detects from auth type)--max-images NallLimit to first N images--min-tokens N500Skip images below token threshold--context-depth N5Preceding messages for context-aware descriptions--no-backupoffSkip .bak backup creation--jsonoffJSON output (suppresses pretty-print)--no-verboseoffSuppress per-image details
[🖼️ Image deflated:)--redact pii|keys|all strips sensitive data during extraction for compliance