
Inference Optimizer
- 11 installs
- 82 repo stars
- Updated August 2, 2026
- aaaaqwq/claude-code-skills
inference-optimizer is an OpenClaw skill that audits token usage, purges stale sessions, and optimizes inference speed.
About
inference-optimizer is an OpenClaw skill that audits token usage and reduces inference cost and latency. On /optimize or /audit it runs an audit script that reports workspace sizes, session counts and next steps, and on approval it purges stale sessions and daily memory stubs. It exists because loaded workspace files and accumulated session history slow the model without an obvious cause. A developer uses it to keep an agent's context lean and fast.
- Audits OpenClaw token usage and workspace/session footprint
- Purges stale session files and daily memory stubs to speed up inference
- Runs via /optimize and /audit commands with a purge step on approval
Inference Optimizer by the numbers
- 11 all-time installs (skills.sh)
- Ranked #2,174 of 3,280 Productivity & Planning skills by installs in the Skillselion catalog
- Data as of Aug 3, 2026 (Skillselion catalog sync)
inference-optimizer capabilities & compatibility
- Capabilities
- token optimization · session cleanup
- Use cases
- token optimization
- Pricing
- Free
What inference-optimizer says it does
Audit OpenClaw token usage, purge stale sessions, and optimize inference speed.
Instead of guessing where tokens go, you get workspace sizes, session counts, and actionable next steps.
npx skills add https://github.com/aaaaqwq/claude-code-skills --skill inference-optimizerAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 11 |
|---|---|
| repo stars | ★ 82 |
| Last updated | August 2, 2026 |
| Repository | aaaaqwq/claude-code-skills ↗ |
What it does
Use it to audit agent token usage and purge stale sessions so inference stays fast and cheap.
Who is it for?
Keeping an OpenClaw agent's context lean by auditing token usage and purging stale sessions.
Skip if: Non-OpenClaw runtimes or model-level inference tuning beyond workspace/session cleanup.
When should I use this skill?
The user sends /optimize or /audit, asks to purge sessions, or wants a token/workspace audit.
What you get
A token/workspace audit and a purge of stale sessions that restore inference speed.
- A token/workspace audit report
- Purged stale sessions and stub files
Files
Inference Optimizer
Optimize OpenClaw for maximum inference speed and minimum token usage. When user sends /optimize or /audit, exec the audit script and return raw output. When user approves purge, exec the purge script.
Triggers
/optimize— run audit/audit— same as /optimize- "purge sessions", "purge stale", "clean up sessions" — after audit, if user approves
Workflow
1. Audit: Exec bash <skill_dir>/scripts/openclaw-audit.sh, return raw output. Do NOT ask what to optimize. Do NOT list options. 2. Purge: If user approves purge after audit, exec bash <skill_dir>/scripts/purge-stale-sessions.sh, return raw output. 3. Full optimization: For Task 1–5 (workspace rewrite, heartbeat, deploy), read optimization-agent.md and follow its flow.
Path Resolution
Scripts live at ~/clawd/skills/public/inference-optimizer/scripts/ (or wherever the skill is installed). Use that path when exec-ing.
Allowlist
Purge script needs: find, find *, find **, rm, rm *, rm **, bash, bash *, bash **. Add to exec-approvals.json for the agent if purge is blocked.
.DS_Store
*.log
MIT License
Copyright (c) 2026
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
agent: optimization-openclaw
mission: Optimize OpenClaw bot for maximum inference speed and minimum token usage by auditing workspace files, shrinking prompts, maximizing cache hits, pruning stale sessions, and cutting tool overhead.
context
- Config:
~/.openclaw/openclaw.json(runtime) - Workspace:
~/clawd/(or~/.openclaw/workspace-*/) — contains SOUL.md, AGENTS.md, TOOLS.md, MEMORY.md, USER.md, HEARTBEAT.md, memory/YYYY-MM-DD.md - Sessions:
~/.openclaw/agents/main/sessions/*.jsonlor~/.clawdbot/agents.main/sessions/*.jsonl
goals (priority order)
1. Shrink tokens loaded on every request (system prompt, workspace files, tool schemas) 2. Maximize cache hit rate (stable prompt prefix, cacheRetention, heartbeat) 3. Reduce cold session overhead (prune stale session files, compaction) 4. Cut unnecessary tool/skill overhead (disable unused, native off) 5. Keep bot behavior and memory search fully intact
what this covers end-to-end
| Layer | Optimization | Expected gain |
|---|---|---|
| Workspace files | Rewrite to bullets, archive daily memory | 500-3000 tokens/request |
| Session files | Purge stale .jsonl > 24h | Faster session loads, less memory overhead |
| Heartbeat | 55-min ping keeps cache warm | Eliminates cold-start cost on cache-eligible prompts |
| Config | cacheRetention: long, temperature: 0.2, compaction | 50-90% reduction on repeated prompt prefixes |
| Skills/native | native: off, nativeSkills: off | Removes detection overhead per turn |
| Cron cleanup | Daily session purge script | Prevents session bloat accumulating over weeks |
constraints
- Do NOT remove API keys, auth profiles, gateway token, channel config, approvals, or plugin entries
- Do NOT change model IDs or provider URLs
- Maintain valid JSON throughout
- Show each Task's output as a clearly labelled section
- For file rewrites, show the new content in full in a code block
---
Task 1 — Audit workspace files
For each file in workspace (SOUL.md, AGENTS.md, TOOLS.md, MEMORY.md, USER.md, HEARTBEAT.md, memory/YYYY-MM-DD.md):
- Estimate current token count (characters / 4)
- Identify: (a) content that belongs in a skill instead of always-loaded context, (b) outdated/redundant content, (c) verbose sections that can be rewritten in 50% fewer words
- Output a table:
| Filename | Est. tokens now | Est. tokens after | Savings | Action |
|---|
---
Task 2 — Rewrite workspace files
For each file identified in Task 1 with savings > 100 tokens:
- Rewrite to declarative bullet points only
- Target: SOUL.md ≤ 500 chars, AGENTS.md ≤ 1000 chars, TOOLS.md trim unused entries, MEMORY.md keep durable facts only, daily memory files: archive anything older than 3 days
- Show full rewritten content for each file in a code block
---
Task 3 — Stale session cleanup
Use the skill's scripts/purge-stale-sessions.sh or generate a similar script that:
- Deletes session
.jsonlfiles older than 24 hours - Optionally archives before deleting
- Is safe to run as a daily cron job
- Prints count of files deleted
---
Task 4 — Generate heartbeat config snippet
Generate the JSON snippet to add a heartbeat to openclaw.json that:
- Fires every 55 minutes (just inside the 1-hour cache window)
- Uses a minimal prompt (e.g. "ok") with the cheapest available model
- Keeps the cache warm so models don't cold-start on user messages
---
Task 5 — Generate deploy script
Generate a deploy script that:
- Backs up current
~/.openclaw/openclaw.jsonwith timestamp - Copies updated config to runtime path
- Runs
openclaw doctor - Restarts gateway with
openclaw gateway restart - Tails gateway logs to confirm clean startup
---
execution notes
- Run Task 1 first; use its output to drive Task 2.
- Task 3–5 produce artifacts; verify generated scripts before execution.
- Session path may be
~/.openclaw/agents/main/sessions/or~/.clawdbot/agents.main/sessions/depending on install; check at runtime. - Heartbeat config keys must match the OpenClaw version's schema; validate before deploy.
---
companion: openclaw-audit.sh
Run before optimization to establish baseline. Path: scripts/openclaw-audit.sh (in this skill).
Usage: /optimize or /audit in chat → agent execs the audit script and returns raw output. After audit, if user approves purge, agent execs scripts/purge-stale-sessions.sh.
inference-optimizer
An OpenClaw skill that audits token usage, purges stale sessions, and optimizes inference speed.

!banner
Ask your bot to run a baseline audit, purge old session files, or get optimization recommendations. Instead of guessing where tokens go, you get workspace sizes, session counts, and actionable next steps.
> /optimize
> purge stale sessions
> audit workspace tokensWhy
Every OpenClaw instance loads workspace files, session history, and tool schemas on every request. Stale sessions pile up. Daily memory stubs accumulate. The model gets slower and more expensive without obvious cause.
This skill fixes that. Run /optimize to get a token audit. Approve a purge to clear stale sessions and stub files. No manual SSH, no guessing.
Install
ClawHub (recommended):
clawhub install https://github.com/vitalyis/inference-optimizerManual:
git clone https://github.com/vitalyis/inference-optimizer.git ~/clawd/skills/public/inference-optimizer
bash ~/clawd/skills/public/inference-optimizer/scripts/setup.shSetup
After install, run the setup script to wire /optimize and purge into your workspace:
bash ~/clawd/skills/public/inference-optimizer/scripts/setup.shThis copies instructions into AGENTS.md and TOOLS.md, ensures scripts are executable, and prints allowlist snippets if needed.
Commands
| Command | What it does |
|---|---|
/optimize | Run token audit (workspace files, sessions, config) and return raw output |
/audit | Same as /optimize |
| purge sessions | After audit, if user approves, run purge script to remove stale sessions and stub memory |
Verify
Confirm installation and script enablement:
bash ~/clawd/skills/public/inference-optimizer/scripts/verify.shExpected output:
optimization-agent.mdfoundopenclaw-audit.shexecutablepurge-stale-sessions.shexecutable- Workspace paths resolvable
- AGENTS.md has
/optimize(or manual step required)
How It Works
SKILL.md (triggers + workflow)
↓
optimization-agent.md ← agent reads for full Task 1–5 flow
scripts/
├── openclaw-audit.sh ← baseline token audit
├── purge-stale-sessions.sh ← removes stale sessions + stub memory
├── setup.sh ← wires commands into workspace
└── verify.sh ← confirms install
↓
/optimize in chat → exec audit script → return output
purge approved → exec purge script → return outputPaths
Scripts auto-detect session and workspace paths:
- Sessions:
~/.openclaw/agents/main/sessionsor~/.clawdbot/agents.main/sessions - Workspace:
~/clawdor~/.openclaw/workspace-whatsapp - Memory:
~/clawd/memoryor~/.openclaw/workspace-whatsapp/memory
Limitations
- Run on the same host as OpenClaw (VPS or local)
- Exec allowlist must include
find,find *,find **,rm,rm *,rm **,bash,bash *,bash **for purge - Workspace layout must match OpenClaw defaults
License
MIT
#!/usr/bin/env bash
# openclaw-audit.sh — baseline token audit before optimization
# Part of inference-optimizer skill. Run on VPS before optimization.
WORKSPACE="${OPENCLAW_WORKSPACE:-$HOME/clawd}"
SESSIONS="${OPENCLAW_SESSIONS:-$HOME/.openclaw/agents/main/sessions}"
[[ -d "$SESSIONS" ]] || SESSIONS="$HOME/.clawdbot/agents.main/sessions"
CONFIG="${OPENCLAW_CONFIG:-$HOME/.openclaw/openclaw.json}"
echo "=== Workspace file sizes (chars → ~tokens) ==="
for f in SOUL.md AGENTS.md TOOLS.md MEMORY.md USER.md HEARTBEAT.md; do
fp="$WORKSPACE/$f"
if [ -f "$fp" ]; then
chars=$(wc -c < "$fp")
tokens=$((chars / 4))
echo " $f: ${chars} chars ≈ ${tokens} tokens"
else
echo " $f: NOT FOUND"
fi
done
echo ""
echo "=== Daily memory files ==="
find "$WORKSPACE/memory" -name "*.md" 2>/dev/null | while read f; do
chars=$(wc -c < "$f")
tokens=$((chars / 4))
echo " $(basename $f): ${chars} chars ≈ ${tokens} tokens"
done
echo ""
echo "=== Session files (stale overhead) ==="
SESSION_COUNT=$(find "$SESSIONS" -name "*.jsonl" 2>/dev/null | wc -l)
SESSION_SIZE=$(du -sh "$SESSIONS" 2>/dev/null | cut -f1)
OLD_COUNT=$(find "$SESSIONS" -name "*.jsonl" -mtime +1 2>/dev/null | wc -l)
echo " Total sessions: $SESSION_COUNT ($SESSION_SIZE)"
echo " Sessions > 24h old: $OLD_COUNT (safe to purge)"
echo ""
echo "=== Config file ==="
CONFIG_CHARS=$(wc -c < "$CONFIG" 2>/dev/null || echo 0)
echo " openclaw.json: ${CONFIG_CHARS} chars"
echo ""
echo "=== Estimated total system prompt tokens per request ==="
TOTAL_TOKENS=0
for f in SOUL.md AGENTS.md TOOLS.md MEMORY.md USER.md HEARTBEAT.md; do
fp="$WORKSPACE/$f"
[ -f "$fp" ] && TOTAL_TOKENS=$((TOTAL_TOKENS + $(wc -c < "$fp") / 4))
done
echo " Workspace files: ~${TOTAL_TOKENS} tokens"
echo " OpenClaw base system prompt: ~8000-15000 tokens (fixed overhead)"
echo " Tools/skills schema: ~500-2000 tokens (varies by enabled skills)"
echo " -------"
echo " Estimated cold request total: ~$((TOTAL_TOKENS + 10000)) tokens"
#!/usr/bin/env bash
# Purge stale OpenClaw sessions (>24h) and stub memory files (<200 chars).
# Part of inference-optimizer skill. Run on VPS.
set -euo pipefail
SESSIONS="${OPENCLAW_SESSIONS:-$HOME/.openclaw/agents/main/sessions}"
[[ -d "$SESSIONS" ]] || SESSIONS="$HOME/.clawdbot/agents.main/sessions"
MEMORY_DIR="$HOME/.openclaw/workspace-whatsapp/memory"
[[ -d "$MEMORY_DIR" ]] || MEMORY_DIR="$HOME/clawd/memory"
if [[ ! -d "$SESSIONS" ]]; then
echo "Sessions dir not found (run on VPS): $SESSIONS"
exit 0
fi
echo "=== Purge stale sessions ==="
BEFORE=$(find "$SESSIONS" -name "*.jsonl" 2>/dev/null | wc -l)
find "$SESSIONS" -type f -name "*.jsonl" -mtime +1 -delete 2>/dev/null || true
AFTER=$(find "$SESSIONS" -name "*.jsonl" 2>/dev/null | wc -l)
echo " Sessions: $BEFORE -> $AFTER (removed $((BEFORE - AFTER)))"
echo ""
echo "=== Purge stub memory files (<200 chars) ==="
PURGED=0
if [[ -d "$MEMORY_DIR" ]]; then
shopt -s nullglob 2>/dev/null || true
for f in "$MEMORY_DIR"/*.md; do
[[ -f "$f" ]] || continue
if [[ $(wc -c < "$f") -lt 200 ]]; then
rm -f "$f"
echo " removed $(basename "$f")"
((PURGED++)) || true
fi
done
[[ $PURGED -eq 0 ]] && echo " none found" || echo " purged $PURGED files"
else
echo " memory dir not found: $MEMORY_DIR"
fi
echo ""
echo "=== Verify ==="
echo " Sessions: $(find "$SESSIONS" -name "*.jsonl" 2>/dev/null | wc -l)"
echo " Memory files: $(find "$MEMORY_DIR" -maxdepth 1 -name "*.md" 2>/dev/null | wc -l)"
#!/usr/bin/env bash
# Setup inference-optimizer: copy commands into workspace, make scripts executable.
# Run after install. Targets ~/clawd and ~/.openclaw/workspace-whatsapp.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SKILL_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
WORKSPACE_MAIN="${WORKSPACE_MAIN:-$HOME/clawd}"
WORKSPACE_WHATSAPP="${WORKSPACE_WHATSAPP:-$HOME/.openclaw/workspace-whatsapp}"
chmod +x "$SKILL_DIR/scripts/openclaw-audit.sh"
chmod +x "$SKILL_DIR/scripts/purge-stale-sessions.sh"
echo "[OK] Scripts executable"
AUDIT_PATH="$SKILL_DIR/scripts/openclaw-audit.sh"
PURGE_PATH="$SKILL_DIR/scripts/purge-stale-sessions.sh"
SNIPPET_AGENTS="
## Chat commands (exact match, run immediately)
| Command | Action |
| \`/optimize\` or \`/audit\` | Exec \`bash $AUDIT_PATH\`, return raw output. Do NOT ask what to optimize. Do NOT list options. |"
SNIPPET_TOOLS="
## inference-optimizer
| App | Use | Example |
| \`/optimize\` | Run audit script | exec \`bash $AUDIT_PATH\`, return raw output. Do NOT ask what to optimize. |
| purge sessions | After /optimize if user approves | exec \`bash $PURGE_PATH\`, return raw output. |"
for ws in "$WORKSPACE_MAIN" "$WORKSPACE_WHATSAPP"; do
[[ -d "$ws" ]] || continue
if [[ -f "$ws/AGENTS.md" ]]; then
if ! grep -q "/optimize" "$ws/AGENTS.md" 2>/dev/null; then
echo "$SNIPPET_AGENTS" >> "$ws/AGENTS.md"
echo "[OK] Added /optimize to $ws/AGENTS.md"
else
echo "[SKIP] $ws/AGENTS.md already has /optimize"
fi
else
echo "[WARN] $ws/AGENTS.md not found"
fi
if [[ -f "$ws/TOOLS.md" ]]; then
if ! grep -q "inference-optimizer" "$ws/TOOLS.md" 2>/dev/null; then
echo "$SNIPPET_TOOLS" >> "$ws/TOOLS.md"
echo "[OK] Added /optimize to $ws/TOOLS.md"
else
echo "[SKIP] $ws/TOOLS.md already has inference-optimizer"
fi
else
echo "[WARN] $ws/TOOLS.md not found"
fi
done
echo ""
echo "Done. Purge allowlist: ensure find *, find **, rm *, rm ** in exec-approvals.json."
echo "Verify: bash $SKILL_DIR/scripts/verify.sh"
#!/usr/bin/env bash
# Verify inference-optimizer installation and script enablement.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SKILL_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
WORKSPACE_MAIN="${WORKSPACE_MAIN:-$HOME/clawd}"
WORKSPACE_WHATSAPP="${WORKSPACE_WHATSAPP:-$HOME/.openclaw/workspace-whatsapp}"
PASS=0
FAIL=0
check() {
if eval "$1"; then
echo "[OK] $2"
((PASS++)) || true
return 0
else
echo "[FAIL] $2"
((FAIL++)) || true
return 1
fi
}
echo "=== inference-optimizer verify ==="
echo ""
check "[[ -f $SKILL_DIR/optimization-agent.md ]]" "optimization-agent.md exists"
check "[[ -f $SKILL_DIR/scripts/openclaw-audit.sh ]]" "openclaw-audit.sh exists"
check "[[ -x $SKILL_DIR/scripts/openclaw-audit.sh ]]" "openclaw-audit.sh executable"
check "[[ -f $SKILL_DIR/scripts/purge-stale-sessions.sh ]]" "purge-stale-sessions.sh exists"
check "[[ -x $SKILL_DIR/scripts/purge-stale-sessions.sh ]]" "purge-stale-sessions.sh executable"
check "[[ -f $SKILL_DIR/SKILL.md ]]" "SKILL.md exists"
if [[ -f "$WORKSPACE_MAIN/AGENTS.md" ]] && grep -q "/optimize" "$WORKSPACE_MAIN/AGENTS.md" 2>/dev/null; then
echo "[OK] AGENTS.md has /optimize (main workspace)"
((PASS++)) || true
else
echo "[WARN] AGENTS.md missing /optimize — run setup.sh or add manually"
((FAIL++)) || true
fi
if [[ -d "$WORKSPACE_MAIN" ]]; then
if bash "$SKILL_DIR/scripts/openclaw-audit.sh" 2>/dev/null | grep -q "Workspace file sizes"; then
echo "[OK] openclaw-audit.sh runs (paths resolvable)"
((PASS++)) || true
else
echo "[WARN] openclaw-audit.sh may have path issues (run on VPS?)"
((FAIL++)) || true
fi
else
echo "[SKIP] Workspace not found, skipping audit dry-run"
fi
echo ""
echo "---"
echo "Pass: $PASS Fail: $FAIL"
[[ $FAIL -eq 0 ]] && exit 0 || exit 1
Related skills
FAQ
What does the audit report?
Workspace sizes, session counts and actionable next steps for reducing tokens.
When does it purge?
Only after the audit and once the user approves the purge step.