Prompt Slimmer
Audit and optimize OpenClaw workspace files to reduce system prompt token overhead without losing information.
Why This Matters
Every workspace file (SOUL.md, MEMORY.md, etc.) is injected into the system prompt on every API call. A 50K-char workspace means ~12K tokens sent with every single message — even a simple "hi". At Opus pricing ($15/1M input tokens), that's $0.18 per message just for workspace overhead.
Quick Start
Run the audit:
CODEBLOCK0
The Method: Frequency-Based Layering
Layer 1: Always-On (workspace files)
Content needed in
every session: core identity, active relationships, behavioral rules, critical safety constraints.
Layer 2: Searchable (memory/archive/)
Content needed
sometimes: completed projects, historical records, detailed technical specs, one-time learnings. Retrieved via
memory_search when relevant.
Layer 3: Skill-Embedded
Content needed
only for specific tasks: workflow steps, code templates, platform-specific guides. Lives in SKILL.md files, loaded only when the skill triggers.
Audit Procedure
Step 0: Ghost File Scan (Often the Biggest Win!)
OpenClaw injects all .md files in the workspace root into the system prompt — not just the standard files. Scan for "ghost files": old reports, task materials, research notes, or temp files sitting in the workspace root.
CODEBLOCK1
Any .md file NOT in the standard list is a ghost file candidate. Move completed task files, old research, and temp notes to memory/archive/ or a subdirectory (subdirectories are not injected).
Real example: One instance had 15K in standard files but 31K in two ghost files (an old promotion review + research report) — removing them saved 63% instantly.
Step 1: Measure Standard Files
CODEBLOCK2
Step 2: Section-Level Analysis
For each file, extract ## headings and measure each section's size. Then classify:
| Category | Criteria | Action |
|---|
| 🟢 Keep | Referenced every session, identity-critical | Keep as-is |
| 🟡 Slim |
Useful but verbose, can be compressed | Rewrite concisely |
| 🔴 Archive | Completed/paused projects, historical records | Move to
memory/archive/ |
| ⚫ Deduplicate | Same info in multiple files | Keep in one place, remove others |
Step 3: Cross-File Deduplication Check
Common duplication patterns:
- - IDENTITY.md ↔ MEMORY.md (appearance, voice info)
- SOUL.md ↔ MEMORY.md (behavioral rules)
- HEARTBEAT.md ↔ AGENTS.md (task scheduling rules)
- MEMORY.md ↔ Skill files (project details duplicated in both)
Rule: Information lives in the most specific location. If a skill covers it, remove from MEMORY.md.
Step 4: Execute Slim-Down
- 1. Create archive file:
memory/archive/projects.md (or topic-specific files) - Move archived sections: Cut from workspace file → paste to archive
- Replace with pointer:
Details: see memory/archive/projects.md or just a 1-line summary - Verify memory_search: Confirm archived content is findable via search
- Measure result: Compare before/after char counts
Step 5: Verify Integrity
After slimming, verify:
- - [ ]
memory_search can find archived content - [ ] No critical behavioral rules were accidentally removed
- [ ] Core identity (name, relationships, key rules) still present
- [ ] Safety constraints still in workspace files (not just archive)
- [ ] Pointers/references are correct paths
File-Specific Heuristics
MEMORY.md (Usually the biggest win)
Typical bloat sources:
- - Paused/completed project details → archive, keep 1-line status
- Detailed timelines/changelogs → archive
- Team roster tables → archive
- Cron job indexes →
cron list can fetch this live - Platform account details → slim to name + ID only
- Milestone lists → archive (historical)
- Cross-referenced content → remove if covered by skill or other file
Target: MEMORY.md should be < 5,000 chars for a well-maintained instance.
HEARTBEAT.md
Typical bloat sources:
- - Code templates (osascript, shell snippets) → agent already knows these
- Verbose priority descriptions → compress to 1-2 lines per priority
- Paused project references → 1 line max
- Repeated emphasis ("核心!", "每次 HB 必做!") → once is enough
Target: HEARTBEAT.md should be < 3,000 chars.
SOUL.md
Be careful here. SOUL.md is identity-critical. Don't optimize away personality.
- - Hierarchy diagrams → can be compressed
- Behavioral rules → review for overlap with AGENTS.md
- Generally leave SOUL.md alone unless it's > 10,000 chars.
TOOLS.md
Usually already lean. Check for:
- - Deprecated tool entries → remove
- Detailed port tables for rarely-used services → slim or archive
AGENTS.md
Usually already lean. Check for:
- - Redundancy with system prompt (OpenClaw injects its own rules)
- Over-detailed workflow descriptions → reference skill instead
Expected Results
| Workspace Size | Before | After | Typical Savings |
|---|
| Light (<20K) | 20K | 15K | 25% |
| Medium (20-50K) |
35K | 18K | 50% |
| Heavy (50K+) | 60K | 22K | 63% |
Cost Impact
At Opus pricing ($15/1M input, $1.50/1M cached):
| Savings | Chars Saved | Tokens Saved | $/message saved | $/day (100 msg) |
|---|
| 25% | 5K | ~2K | $0.03 | $3 |
| 50% |
25K | ~10K | $0.15 | $15 |
| 63% | 38K | ~15K | $0.23 | $23 |
With prompt caching, savings are ~90% less but still meaningful for cache-miss turns.
What NOT to Slim
- - Safety constraints (never archive security rules)
- Core identity (name, key relationships, personality)
- Active behavioral rules that prevent known failure modes
- Credentials management rules (how to handle secrets)
- Cross-instance coordination rules (if running multiple agents)
Prompt Slimmer
审计并优化 OpenClaw 工作区文件,以减少系统提示的令牌开销,同时不丢失信息。
为何重要
每个工作区文件(SOUL.md、MEMORY.md 等)都会在每次 API 调用时注入到系统提示中。一个 50K 字符的工作区意味着每次发送消息(即使是简单的hi)都会发送约 12K 令牌。按 Opus 定价($15/1M 输入令牌),每条消息仅工作区开销就达 $0.18。
快速开始
运行审计:
- 1. 测量所有工作区文件(字符数 + 行数)
- 分析每个部分的使用频率
- 识别跨文件冗余
- 生成精简计划(含前后对比估算)
- 执行(需用户批准)并验证
方法:基于频率的分层
第 1 层:始终启用(工作区文件)
每次会话都需要的内容:核心身份、活跃关系、行为规则、关键安全约束。
第 2 层:可搜索(memory/archive/)
有时需要的内容:已完成项目、历史记录、详细技术规格、一次性学习成果。通过 memory_search 在相关时检索。
第 3 层:技能嵌入
仅特定任务需要的内容:工作流程步骤、代码模板、平台特定指南。存放在 SKILL.md 文件中,仅在技能触发时加载。
审计流程
第 0 步:幽灵文件扫描(通常收益最大!)
OpenClaw 会将工作区根目录下的所有 .md 文件注入系统提示——不仅仅是标准文件。扫描幽灵文件:旧报告、任务材料、研究笔记或工作区根目录中的临时文件。
bash
cd
echo === 工作区根目录中的所有 .md 文件 ===
for f in *.md; do
[ -f $f ] && echo $f: $(wc -c < $f) 字符
done
echo === 标准文件 ===
echo SOUL.md AGENTS.md TOOLS.md IDENTITY.md USER.md HEARTBEAT.md MEMORY.md BOOTSTRAP.md GARDEN.md
任何不在标准列表中的 .md 文件都是幽灵文件候选。将已完成的任务文件、旧研究和临时笔记移动到 memory/archive/ 或子目录(子目录不会被注入)。
真实案例:某个实例的标准文件有 15K,但两个幽灵文件(一份旧晋升评审 + 研究报告)却有 31K——移除后立即节省 63%。
第 1 步:测量标准文件
bash
cd
for f in SOUL.md AGENTS.md TOOLS.md IDENTITY.md USER.md HEARTBEAT.md MEMORY.md; do
[ -f $f ] && echo $f: $(wc -c < $f) 字符, $(wc -l < $f) 行
done
第 2 步:部分级别分析
对每个文件,提取 ## 标题并测量每个部分的大小。然后分类:
| 类别 | 标准 | 操作 |
|---|
| 🟢 保留 | 每次会话都引用,身份关键 | 保持原样 |
| 🟡 精简 |
有用但冗长,可压缩 | 重写为简洁版本 |
| 🔴 归档 | 已完成/暂停的项目、历史记录 | 移至 memory/archive/ |
| ⚫ 去重 | 多个文件中相同信息 | 保留一处,移除其他 |
第 3 步:跨文件去重检查
常见重复模式:
- - IDENTITY.md ↔ MEMORY.md(外貌、声音信息)
- SOUL.md ↔ MEMORY.md(行为规则)
- HEARTBEAT.md ↔ AGENTS.md(任务调度规则)
- MEMORY.md ↔ 技能文件(项目详情在两者中重复)
规则:信息存放在最具体的位置。如果某个技能已涵盖,则从 MEMORY.md 中移除。
第 4 步:执行精简
- 1. 创建归档文件:memory/archive/projects.md(或按主题分类的文件)
- 移动归档部分:从工作区文件剪切 → 粘贴到归档文件
- 替换为指针:详情:见 memory/archive/projects.md 或仅保留 1 行摘要
- 验证 memory_search:确认归档内容可通过搜索找到
- 测量结果:比较前后字符数
第 5 步:验证完整性
精简后,验证:
- - [ ] memory_search 能找到归档内容
- [ ] 未意外移除关键行为规则
- [ ] 核心身份(名称、关系、关键规则)仍然存在
- [ ] 安全约束仍在工作区文件中(不仅限于归档)
- [ ] 指针/引用路径正确
文件特定启发式规则
MEMORY.md(通常收益最大)
典型臃肿来源:
- - 暂停/完成的项目详情 → 归档,保留 1 行状态
- 详细时间线/变更日志 → 归档
- 团队花名册表格 → 归档
- 定时任务索引 → cron list 可实时获取
- 平台账户详情 → 精简为仅名称 + ID
- 里程碑列表 → 归档(历史记录)
- 交叉引用内容 → 如果被技能或其他文件覆盖则移除
目标:维护良好的实例中 MEMORY.md 应 < 5,000 字符。
HEARTBEAT.md
典型臃肿来源:
- - 代码模板(osascript、shell 片段)→ 代理已知道这些
- 冗长的优先级描述 → 每个优先级压缩到 1-2 行
- 暂停项目引用 → 最多 1 行
- 重复强调(核心!、每次 HB 必做!)→ 一次足够
目标:HEARTBEAT.md 应 < 3,000 字符。
SOUL.md
此处需谨慎。 SOUL.md 是身份关键文件。不要优化掉个性。
- - 层级图 → 可压缩
- 行为规则 → 检查与 AGENTS.md 的重叠
- 通常保持 SOUL.md 不变,除非超过 10,000 字符。
TOOLS.md
通常已经很精简。检查:
- - 已弃用的工具条目 → 移除
- 不常用服务的详细端口表 → 精简或归档
AGENTS.md
通常已经很精简。检查:
- - 与系统提示的冗余(OpenClaw 会注入自己的规则)
- 过于详细的工作流程描述 → 引用技能代替
预期结果
| 工作区大小 | 精简前 | 精简后 | 典型节省 |
|---|
| 轻量(<20K) | 20K | 15K | 25% |
| 中等(20-50K) |
35K | 18K | 50% |
| 重量级(50K+) | 60K | 22K | 63% |
成本影响
按 Opus 定价($15/1M 输入,$1.50/1M 缓存):
| 节省比例 | 节省字符 | 节省令牌 | 每条消息节省 | 每天节省(100 条消息) |
|---|
| 25% | 5K | ~2K | $0.03 | $3 |
| 50% |
25K | ~10K | $0.15 | $15 |
| 63% | 38K | ~15K | $0.23 | $23 |
使用提示缓存后,节省约减少 90%,但对缓存未命中轮次仍有意义。
不要精简的内容
- - 安全约束(永远不要归档安全规则)
- 核心身份(名称、关键关系、个性)
- 防止已知失败模式的活跃行为规则
- 凭证管理规则(如何处理密钥)
- 跨实例协调规则(如果运行多个代理)