通过拆分 TOOLS.md、执行原子规则并按需加载场景来优化 OpenClaw MD 文件,使启动文件保持在 3KB 以下。
Version: 2.0 | Updated: 2026-05-22 Skill Name: md-bootstrap-optimizer Tags: bootstrap, memory-management, openclaw, file-architecture, lean-context Install:
npx clawhub@latest install md-bootstrap-optimizer
A design guide and audit tool for keeping OpenClaw's bootstrap file system lean and maintainable as it grows. Prevents rules from scattering, keeps context usage low, and makes every file's purpose clear.
Core problem it solves: As OpenClaw agents accumulate rules, MEMORY.md and TOOLS.md bloat, critical rules get truncated, and context is wasted on rules that aren't relevant to the current session.
Every file in the bootstrap layer belongs to exactly one of three layers:
LayerWhen LoadedRulesCore (Permanent)Every session, full loadAtomic principles only — things that are always trueExecution (On-demand)Triggered by scene or task typeDetailed procedures for specific situationsArchiveNever auto-loadedHistorical, reference-only — no rule participation
Files here load on every session start. Keep them small and permanent.
text
MEMORY.md — Atomic rules (Why), not facts (What)
AGENTS.md — Core operating procedures
CLAUDE.md / SOUL.md / IDENTITY.md — Identity anchors
Atomic rules only: Store principles that never expire, not event logs or temporary facts.
Good: "When the user says 'confirm', check if decisions.md needs updating before acting" Bad: "The user owns 1 million in assets" (fact, not rule)
Files here load only when their trigger fires. Keep them comprehensive.
text
SCHEDULING.md — Loaded when scheduling tasks
INSTRUCTIONS.md — Loaded when handling instructions
TOOLS.md — Mother file (index only), children loaded on demand
PROJECT.md — Loaded for specific projects
Mother-Child split for TOOLS.md: The mother file is an index (< 3KB). Child files contain the details. The child loads only when called.
text
TOOLS.md (mother, index only)
├── TOOLS_skills.md — Detailed skill inventory
├── TOOLS_feishu.md — Channel/protocol details
└── TOOLS_custom.md — Your custom tool docs
These files exist on disk but never participate in bootstrap. Use them for historical context, but don't count on them for current behavior.
text
AGENTS_full.md — Full ruleset (verbose version)
DREAMS.md — Past session insights
HEARTBEAT.md — Maintenance logs
MEMORY.md stores only permanently true principles. When something in MEMORY.md becomes a fact rather than a principle, move it to a project file or daily log.
When any bootstrap file exceeds ~3KB, split it:
Every rule lives in exactly one file. Cross-references between files are OK for navigation, but rule ownership is singular.
Detailed procedures belong in scene-specific files, not in always-loaded core files. The session loads what's needed, not everything.
Run this monthly or whenever bootstrap feels slow:
bash
# Check bootstrap file sizes
ls -lh ~/.openclaw/workspace/*.md | awk '{print $5, $9}'
# Check total bootstrap size
cat ~/.openclaw/workspace/*.md | wc -c
# Flag files over 3KB
for f in ~/.openclaw/workspace/*.md; do
size=$(wc -c < "$f")
if [ "$size" -gt 3000 ]; then
echo "OVER 3KB: $f ($size bytes)"
fi
done
MetricWarningActionBootstrap total> 15KBReview for bloatAny single file> 3KBPlan splitMEMORY.md growthAnyCheck if facts vs rules
FileTarget MaxReasonMEMORY.md< 3KBLoaded every sessionAGENTS.md< 5KBCore rules, always loadedTOOLS.md (mother)< 3KBIndex onlyExecution layer filesNo limitLoaded on demand
Don't pile everything into MEMORY.md
Symptoms: Version drift, critical rules truncated, facts mixed with principles
Don't load detailed procedures in bootstrap
Symptoms: Context wasted, slow session start, rules irrelevant to current task
Don't cross-reference without ownership
Symptoms: "Where does this rule actually live?" — nobody knows
Don't keep facts in bootstrap files
Facts belong in project files or daily logs. Bootstrap is for rules, not state.
bash
# Install via ClawHub
npx clawhub@latest install md-bootstrap-optimizer
# Or manual: copy to your skills directory
cp -r md-bootstrap-optimizer ~/.openclaw/skills/
This skill describes a general architecture. Adapt the layer definitions and thresholds to your workflow:
3KB thresholds based on your context budget