Audit → recommend → apply cycle for workspace file token optimization. Run scripts/token_count.py to measure, identify compression opportunities by safety tier, then apply only approved changes with backup.
Files analyzed by this skill (all relative to the workspace root):
FilePurposeTypical SizeAGENTS.mdAgent capability declarationsMediumSOUL.mdPersona and behavioral directivesSmall–MediumUSER.mdUser profile and preferencesSmall–MediumTOOLS.mdTool configurationsMedium–LargeIDENTITY.mdAgent identity/roleSmallHEARTBEAT.mdPeriodic check logicSmall–MediumMEMORY.mdMemory indexGrows over timeCustom context filesAny user-added workspace .md filesVariable
Changes that cannot affect agent behavior:
## Section\n\n## Next)--- separators between every item)[TODO: ...], [OPTIONAL], unused scaffolding)Changes that reduce information density:
Changes that could break agent behavior:
Identify workspace root (default: /home/aif/.openclaw/workspace/ or current working directory's .openclaw/workspace/).
Run token count script: bash
python3 skills/prompt-diet/scripts/token_count.py /home/aif/.openclaw/workspace/ --detail
Review output: per-file token count, % of total, per-section breakdown.
Note files where token count is unexpectedly high or has grown since last audit.
Report summary to user before proceeding.
For each file with compression opportunities, produce a recommendation table:
text
File: MEMORY.md (847 tokens, 34% of total)
┌─────────────────────────────────────────────────┬────────┬──────────┐
│ Opportunity │ Tier │ Savings │
├─────────────────────────────────────────────────┼────────┼──────────┤
│ 3 entries reference completed 2026-03 project │ 🟡 │ ~120 tok │
│ 2 near-duplicate feedback entries │ 🟡 │ ~60 tok │
│ 4 blank lines between entries │ 🟢 │ ~4 tok │
└─────────────────────────────────────────────────┴────────┴──────────┘
Ask the user: "Apply 🟢 safe changes automatically? Show me which 🟡 review items to approve?"
Do not apply any changes without explicit user confirmation.
Only after user approval:
Create backup before any edits:
<filename>.pre-diet (e.g., MEMORY.md.pre-diet)prompt-diet-backup/ directory with timestampApply changes using Edit tool, one file at a time.
Show diff summary: lines removed, tokens saved per file.
Report before/after: text
Before: 2,481 tokens across 7 files
After: 1,934 tokens across 7 files
Saved: 547 tokens (22%)
Offer to clean up backup files after user confirms the result looks good.
MEMORY.md grows continuously and is the highest-yield target. Check for:
memory/ daily log files (cross-reference).For each candidate removal, show the full entry text and ask: "Archive to daily log, merge, or keep?"
Never silently remove MEMORY.md entries — always show the user what will be deleted.
This skill does NOT auto-register a cron job. To set up periodic audits yourself:
Weekly audit cron (example):
bash
# Add via: /schedule OR CronCreate tool
# Schedule: 0 9 * * 1 (every Monday 9am)
# Command: /prompt-diet audit-only
HEARTBEAT.md addition template (copy-paste into your HEARTBEAT.md):
markdown
## Prompt Diet Check (Weekly)
- Run token audit on workspace files
- Flag if any file has grown >20% since last check
- Remind user if MEMORY.md exceeds 200 lines
Manual one-off audit:
bash
python3 /home/aif/.openclaw/workspace/skills/prompt-diet/scripts/token_count.py \
/home/aif/.openclaw/workspace/ --format json | python3 -m json.tool
This skill does not touch:
Token counts are estimates (tiktoken cl100k_base encoding approximates Claude tokenization; actual Claude token counts may differ by ±5–10%).
token_count.py — Standalone token counter. Works with or without tiktoken installed.compression-rules.md — Detailed per-file compression rules and examples.