agentleFS
KCNyuKCNyu/clawock/skills/openclaw-tune/SKILL.md

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.

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
  1. Very specific:

    Use this skill to keep kcn's openclaw setup lean.

    line 8
  2. Very specific:

    After openclaw update (defaults may have shifted.

    line 13
  3. Distinctive:

    When response feels slow / token costs creeping up

    line 14
  4. Very specific:

    When agents/main/sessions/ looks suspiciously large

    line 15
  5. Very specific:

    Verify before touching live state: if openclaw gateway is running, only touch files it doesn't actively hold (use lsof)

    line 20
  6. Very specific:

    Real holdings, real data: never propose changes that hardcode portfolio numbers — portfolio.json is the only source of truth

    line 21
  7. Distinctive:

    Check the size of each:

    line 71
  8. Distinctive:

    If recall rate < 5% and total > 3000, prune noise:

    line 139
  9. Very specific:

    Keep all entries with 交易记录|买入|卖出|加仓|减仓|清仓|持仓|盈利|亏损

    line 142
  10. Very specific:

    Run these checks after openclaw update succeeds:

    line 146
  11. Distinctive:

    If OpenClaw introduced a new default model, verify the configured provider with a real smoke call before proposing any change.

    line 162

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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-tune or 优化下 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

  1. Don't delete, archive first: move stale files to /root/scratch/openclaw-cleanup-<date>/ so they can be recovered for a day
  2. Verify before touching live state: if openclaw gateway is running, only touch files it doesn't actively hold (use lsof)
  3. Real holdings, real data: never propose changes that hardcode portfolio numbers — portfolio.json is the only source of truth
  4. Report what was done with sizes/counts; never silent fixes

Checklist

1. Disk bloat

Big offenders found historically:

PathWhat to look forAction
~/.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/*.jsonCrash dumps from past unhandled rejectionsArchive 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 deleteDelete only if not held
~/.openclaw/media/Generated images, voice clipsCheck size; archive if > 100MB and not referenced
~/.openclaw/agents/main/sessions/*.trajectory.jsonlAudit trajectory logs — large but useful for debuggingLeave 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/null

2. 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}.md

Historical 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:

PatternWhere it livesFix
"Promoted From Short-Term Memory" in MEMORY.mdDreaming auto-promotes summaries; they pile upFlag 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.mdSame rules 3xKeep 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.mdUser uses 1:1 weixinDrop unless multi-user channels are added
Verbose heartbeat instructions in AGENTS.mdopenclaw injects HEARTBEAT_CONTEXT_PROMPT itselfKeep one short line about HEARTBEAT_OK token
50+ line preamble repeating "real data, no cache"Said 5 times across filesOne铁律 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-spare same key as minimax): 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-check npm view openclaw versions changelog 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.json dynamically)
  • Pattern to use: script outputs data block → agent layers analysis on top (情绪面/技术面/操作建议)
  • For intraday: use --wechat flag 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-corpus entries with recallCount=0 AND no trade keywords
  • memory/*.md is not a diary class: dated diaries were retired in #1038, while *-pre-open.md is 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 above

If 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 archived

Output 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-gateway automatically — 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 via openclaw cron list --json, config/cron-schedules.json, workspace canonical MD files, short-term recall state, and disk usage of ~/.openclaw/
  • Writes: trimmed *.md workspace files (with bak), cron fields only through openclaw cron edit / ops/host/sync_us_cron_dst.py plus the tracked contract and regenerated docs/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)

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.