Vault Optimizer Skill
Overview
This skill provides a lightweight, token‑efficient system to monitor OpenClaw token usage, prune caches, truncate daily memory files, and optionally schedule periodic clean‑ups. It includes a ready‑to‑run script (scripts/vault-optimizer.js) and reference documentation for thresholds and scheduling.
When to Use
- •User asks to improve the vault system or reduce token usage.
- •Need to perform a one‑off cleanup (cache, memory, histovault).
- •Want to schedule automatic maintenance via OpenClaw cron jobs.
How It Works
- •Token Monitor – Uses
openclaw sessions list --jsonto calculate current token percentage. - •Cache Cleanup – Clears expired entries in
context‑cache.json. - •Memory Truncation – Keeps only the most recent N lines of today’s memory file (configurable).
- •HistoVault Prune – Calls the built‑in histovault prune routine (if present).
- •Reporting – Outputs a concise status report and recommendations.
Running the Optimizer
bash
# One‑off run (default normal mode) node scripts/vault-optimizer.js health # Aggressive cleanup (forces more aggressive memory truncation) node scripts/vault-optimizer.js health aggressive
Scheduling Automatic Clean‑ups
Create a cron job that runs the optimizer every 6 hours (example):
json
{
"name": "vault‑cleanup",
"schedule": { "kind": "cron", "expr": "0 */6 * * *", "tz": "Europe/Oslo" },
"payload": { "kind": "systemEvent", "text": "run-vault-cleanup" },
"sessionTarget": "main",
"enabled": true
}
Then add the job via:
bash
openclaw cron add --job-file path/to/job.json
The run-vault-cleanup system event can be handled by a lightweight background agent that simply runs:
bash
node scripts/vault-optimizer.js health
Customisation
- •Thresholds – Edit
references/token‑thresholds.mdto adjust warning/critical percentages. - •Memory Retention – Change
memoryKeepLinesandmemoryAggressiveLinesin the script if you want to keep more or fewer lines. - •Cache Limits – Modify
cacheMaxEntriesandcacheMaxAgeMsfor stricter cache pruning.
References
- •
references/token-thresholds.md– Details on token usage thresholds and recommendations. - •
references/scheduling.md– Guidance on creating OpenClaw cron jobs for periodic vault maintenance.
Quick Checklist
- • Verify
openclawCLI is in PATH. - • Run a test:
node scripts/vault-optimizer.js health. - • (Optional) Add a cron job for automated cleanup.
- • Review the output and adjust thresholds if needed.