openclaw-tune
Skill17 starsChanged 3 months agoMITView on GitHub
OpenClaw **system-level** maintenance — cleans sessions/.bak rotation, disk bloat under ~/.openclaw/, validates model fallback chain, audits cron health, prunes short-term-recall noise. Run after `openclaw update` or every 1-2 weeks. Different from **workspace document tune-up** (single-responsibility canonical .md files, token waste scan) which follows the repository AGENTS.md worktree/PR workflow — triggered when user says "优化下 openclaw 的文档/skill/canonical". This skill is for `openclaw` daemon/CLI maintenance, NOT for workspace docs.
In this repository16 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- site/llms.txtllms.txt
- daily-deep-briefSkill
- earnings-reviewSkill
- entry-gateSkill
- githubSkill
- hk-stock-analysisSkill
- openclaw-upgradeSkill
- portfolio-risk-reviewSkill
- portfolio-swarm-reviewSkill
- scraplingSkill
- serenity-skillSkill
- tavilySkill
- TradingSkill
- us-stock-analysisSkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 4 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Use this skill to keep kcn's openclaw setup lean.
- Very specific: line 13
After openclaw update (defaults may have shifted.
- Distinctive: line 14
When response feels slow / token costs creeping up
- Very specific: line 15
When agents/main/sessions/ looks suspiciously large
- Very specific: line 20
Verify before touching live state: if openclaw gateway is running, only touch files it doesn't actively hold (use lsof)
- Very specific: line 21
Real holdings, real data: never propose changes that hardcode portfolio numbers — portfolio.json is the only source of truth
- Distinctive: line 71
Check the size of each:
- Distinctive: line 139
If recall rate < 5% and total > 3000, prune noise:
- Very specific: line 142
Keep all entries with 交易记录|买入|卖出|加仓|减仓|清仓|持仓|盈利|亏损
- Very specific: line 146
Run these checks after openclaw update succeeds:
- Distinctive: line 162
If OpenClaw introduced a new default model, verify the configured provider with a real smoke call before proposing any change.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
OpenClaw Tune-Up
Use this skill to keep kcn's openclaw setup lean. Run it after every openclaw update, or as a periodic chore every 1-2 weeks.
When to invoke
- User says
/openclaw-tuneor优化下 openclaw - After
openclaw update(defaults may have shifted; configs may need migration) - When response feels slow / token costs creeping up
- When
agents/main/sessions/looks suspiciously large
Operating principles
- Don't delete, archive first: move stale files to
/root/scratch/openclaw-cleanup-<date>/so they can be recovered for a day - Verify before touching live state: if openclaw gateway is running, only touch files it doesn't actively hold (use
lsof) - Real holdings, real data: never propose changes that hardcode portfolio numbers —
portfolio.jsonis the only source of truth - Report what was done with sizes/counts; never silent fixes
Checklist
1. Disk bloat
Big offenders found historically:
| Path | What to look for | Action |
~/.openclaw/agents/main/sessions/*.bak-* | Transcript backups, no rotation. One active session can accumulate 100+ files (7MB each = 700MB) | Keep latest 3 per session, archive rest |
~/.openclaw/agents/main/sessions/*.bak-* (orphan) | .bak file with no matching .jsonl (session deleted but backup stayed) | Archive all |
~/.openclaw/openclaw.json.clobbered.* | Config corruption snapshots (e.g. 2026-04-25 had 78) | Archive all (the .last-good retains canonical state) |
~/.openclaw/logs/stability/*.json | Crash dumps from past unhandled rejections | Archive if older than 30 days |
~/.openclaw/memory/main.sqlite.tmp-* | Orphaned SQLite migration tmp file from interrupted write. Verify lsof returns empty, mtime > 7d, then delete | Delete only if not held |
~/.openclaw/media/ | Generated images, voice clips | Check size; archive if > 100MB and not referenced |
~/.openclaw/agents/main/sessions/*.trajectory.jsonl | Audit trajectory logs — large but useful for debugging | Leave unless > 500MB total |
Sample script:
ARCHIVE=/root/scratch/openclaw-cleanup-$(date +%Y%m%d_%H%M%S)
mkdir -p "$ARCHIVE"
# Orphan .bak (no matching .jsonl)
SESS=~/.openclaw/agents/main/sessions
for bak in $SESS/*.bak-*; do
[ -f "$bak" ] || continue
base=$(echo "$bak" | sed 's/\.jsonl\.bak-.*//')
[ -f "$base.jsonl" ] || mv "$bak" "$ARCHIVE/"
done
# Rotate .bak: keep latest 3 per session (by trailing timestamp)
ls $SESS/*.bak-* 2>/dev/null | sed 's/\.jsonl\.bak-.*//' | sort -u | while read pfx; do
files=$(ls -1 ${pfx}.jsonl.bak-* 2>/dev/null)
count=$(echo "$files" | wc -l)
[ "$count" -gt 3 ] && \
echo "$files" | sort -t'-' -k3,3n | head -n -3 | xargs -I{} mv {} "$ARCHIVE/"
done
# Clobbered configs + old crash dumps
mv ~/.openclaw/openclaw.json.clobbered.* "$ARCHIVE/" 2>/dev/null
mv ~/.openclaw/logs/stability/openclaw-stability-*.json "$ARCHIVE/" 2>/dev/null2. Prompt bloat (token cost)
Bootstrap injection depends on the session profile: direct chat gets seven files including MEMORY.md and HEARTBEAT.md; isolated cron gets AGENTS/SOUL/TOOLS/IDENTITY/USER and does not read main-session MEMORY.md. Check src/clawock/context/manifest.json and the actual systemPromptReport, not an assumed file order.
Check the size of each:
wc -c ~/.openclaw/workspace/{AGENTS,SOUL,USER,IDENTITY,MEMORY,TOOLS}.mdHistorical size heuristics (not acceptance gates; do not remove concrete incident lessons or narrow cron context to meet them):
- AGENTS.md: < 3 KB (core rules only; no philosophical fluff, no group-chat lore, no heartbeat docs — openclaw injects heartbeat prompt itself)
- MEMORY.md: < 5 KB (durable preferences + data rules + key lessons; not historical trade records — structured ledgers and published briefs carry those; dated diaries were retired in #1038)
- SOUL.md / IDENTITY.md / USER.md: < 2 KB each
- TOOLS.md: < 4 KB (script reference + fallback chain summary only)
Common bloat patterns:
| Pattern | Where it lives | Fix |
| "Promoted From Short-Term Memory" in MEMORY.md | Dreaming auto-promotes summaries; they pile up | Flag dated market excerpts/front matter/HTML for review; preserve concrete incident lessons. Position exit alone does not make a lesson obsolete |
| Duplicate fallback chains in MEMORY.md + TOOLS.md + INVESTMENT_SOP.md | Same rules 3x | Keep provider chains in docs/reference/tool-operations.md with the current implementation; TOOLS.md routes there, MEMORY.md keeps incident lessons |
| Group chat / Discord behavior in AGENTS.md | User uses 1:1 weixin | Drop unless multi-user channels are added |
| Verbose heartbeat instructions in AGENTS.md | openclaw injects HEARTBEAT_CONTEXT_PROMPT itself | Keep one short line about HEARTBEAT_OK token |
| 50+ line preamble repeating "real data, no cache" | Said 5 times across files | One铁律 block in MEMORY.md, reference elsewhere |
3. Model fallback chain (token cost)
In ~/.openclaw/openclaw.json, check agents.defaults.model:
python3 -c "
import json
cfg = json.load(open('/root/.openclaw/openclaw.json'))
m = cfg['agents']['defaults']['model']
print('primary:', m['primary'])
print('fallbacks:')
for f in m['fallbacks']: print(' ', f)
"Red flags:
- Unexpected provider order: compare the live chain with the operator-configured order and the cron payload contract. Report drift; do not reorder or duplicate providers as a maintenance optimization.
- "Spare" provider with same API key (
minimax-sparesame key asminimax): acts as a retry, not real redundancy. Fine if user knows that. Bad if they think it's a quota pool. - Stale model IDs after openclaw update: e.g., changelog deprecated
gpt-5.3-codex. Cross-checknpm view openclaw versionschangelog for deprecation notices.
4. Cron jobs
openclaw cron list --json — check each enabled job against
config/cron-schedules.json(schedule + payload profile + delivery);system crontab
watchdog 和 EDT/EST 切换也由同一 contract 管:
- Does it reference an installed command or named
ops/*entry that still exists? - Does it reference dead APIs? (e.g. "优先东方财富" but Eastmoney is 502 from this server)
- Does it hardcode tickers? (should read from
portfolio.jsondynamically) - Pattern to use: script outputs data block → agent layers analysis on top (情绪面/技术面/操作建议)
- For intraday: use
--wechatflag for mobile-friendly compact output
5. Short-term-recall noise
~/.openclaw/workspace/memory/.dreams/short-term-recall.json:
python3 -c "
import json
data = json.loads(open('/root/.openclaw/workspace/memory/.dreams/short-term-recall.json','rb').read().decode('utf-8','replace'))
e = data['entries']
recalled = sum(1 for v in e.values() if v.get('recallCount',0) > 0)
print(f'total: {len(e)} ever recalled: {recalled} ({recalled*100//len(e)}%)')
"If recall rate < 5% and total > 3000, prune noise:
- Drop
session-corpusentries withrecallCount=0AND no trade keywords memory/*.mdis not a diary class: dated diaries were retired in #1038, while*-pre-open.mdis a published brief. Do not promote its prices, front matter or HTML as durable wisdom; source path and trading keywords alone do not establish value.- Keep all entries with
交易记录|买入|卖出|加仓|减仓|清仓|持仓|盈利|亏损
6. After openclaw update
Run these checks after openclaw update succeeds:
# 1. Defaults shifted? Compare default agent model
diff <(openclaw config get agents.defaults.model) <(cat /tmp/last-known-model.json) 2>/dev/null
# 2. Changelog skim for breaking changes
PKG=$(find /root/.local/share/pnpm/global/5/.pnpm -name "openclaw" -path "*node_modules/openclaw" -type d | sort | tail -1)
head -50 "$PKG/CHANGELOG.md"
# 3. Deprecated model IDs check
grep -i "deprecated\|suppress.*model\|stop advertising" "$PKG/CHANGELOG.md" | head -5
# 4. Re-run the disk + prompt + fallback chain checks aboveIf OpenClaw introduced a new default model, verify the configured provider with a real smoke call before proposing any change; do not infer upgrades from an old model example.
7. Verification before reporting done
# Confirm openclaw still healthy
curl -sf http://127.0.0.1:18789/health && echo " ✓ gateway up"
# Confirm scripts still run
cd /root/.openclaw/workspace && clawock analyze-hk --no-fetch --no-news --wechat | head -5
# Show cleanup summary
du -sh /root/scratch/openclaw-cleanup-*/ # what was archivedOutput format
End with a structured report:
## Tune-Up Report YYYY-MM-DD
### 清理(已归档到 /root/scratch/openclaw-cleanup-YYYYMMDD/)
- Session .bak rotation: N 个 → ~X MB
- ...
### Prompt 瘦身
- AGENTS.md: <old> → <new> 行 (-N%)
- ...
### 配置审计
- 模型 fallback 链:<state>
- Cron job 一致性:<state>
- ...
### 建议
- [可选] 重启 gateway: <yes/no, reason>
- [待办] <items needing user attention>
### 跳过项
- <什么没动以及为什么>Don't
- ❌ Don't restart
openclaw-gatewayautomatically — ask user first - ❌ Don't touch
agents.defaults.model.primary— that's user's intentional choice - ❌ Don't delete anything before archiving to /tmp
- ❌ Don't delete
*.trajectory.jsonl— those are sometimes useful for debugging - ❌ Don't strip MEMORY.md entries that contain
交易记录— those are real history kcn refers to - ❌ Don't propose hardcoding portfolio numbers in any doc/skill — always reference
portfolio.json
Inputs / Outputs
- Reads:
~/.openclaw/openclaw.json, live cron state viaopenclaw cron list --json,config/cron-schedules.json, workspace canonical MD files, short-term recall state, and disk usage of~/.openclaw/ - Writes: trimmed
*.mdworkspace files (with bak), cron fields only throughopenclaw cron edit/ops/host/sync_us_cron_dst.pyplus the tracked contract and regenerateddocs/operations/cron-schedules.md, no portfolio changes during system maintenance; everything else archived to/root/scratch/openclaw-cleanup-<date>/ - Side effects: may suggest gateway restart at the end (user-confirmed)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

