session-hygiene

Prevent sessions.json bloat from accumulating isolated sessions (hooks, crons, subagents). Sets up a cron to archive stale sessions to daily JSONL files and keep sessions.json lean. Use when sessions.json grows large, the gateway becomes slow or unresponsive, or as preventive maintenance on any OpenClaw instance with hooks or crons. Related to openclaw/openclaw#15225.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "session-hygiene" with this command: npx skills add halbotley/session-hygiene

Session Hygiene

OpenClaw's session store (sessions.json) grows unbounded — every hook, cron, and subagent invocation creates a session entry that never gets cleaned up. Heavy setups (webhooks + crons) can hit 200MB+ and 7000+ sessions within weeks, causing gateway slowdowns and unresponsiveness.

This skill sets up automated archive-and-rotate to keep sessions.json lean while preserving session history.

Quick Setup

Create a cron that runs every 6 hours:

cron(action: "add", job: {
  name: "Session Archive & Cleanup",
  schedule: { kind: "cron", expr: "0 */6 * * *", tz: "America/Los_Angeles" },
  sessionTarget: "isolated",
  payload: {
    kind: "agentTurn",
    message: "Archive and clean up stale sessions. Run the script: python3 <skill-dir>/scripts/archive_sessions.py",
    timeoutSeconds: 60
  },
  delivery: { mode: "announce", channel: "slack" }
})

Adjust the timezone and delivery channel to match your setup.

What It Does

  1. Archive: Sessions older than 48 hours get moved to sessions-archive/YYYY-MM-DD.jsonl (one JSON line per session, grouped by date)
  2. Protect: agent:main:main is never removed
  3. Rotate: Archive files older than 30 days are deleted
  4. Report: Logs how many sessions were archived, how many remain, and file sizes

Manual Run

For an immediate cleanup (e.g., if sessions.json is already bloated):

python3 <skill-dir>/scripts/archive_sessions.py

Or for a one-time aggressive purge of sessions older than N hours:

python3 <skill-dir>/scripts/archive_sessions.py --max-age-hours 1

Tuning

ParameterDefaultNotes
--max-age-hours48How old a session must be before archiving
--archive-retention-days30How long to keep archive JSONL files
--sessions-pathAuto-detectedPath to sessions.json
--dry-runoffPreview what would be archived without changing anything

Sizing Estimates

Sessions/day48h retentionsessions.json size
50~100 sessions~3MB
100~200 sessions~6MB
200~400 sessions~12MB

Without this skill, the same setup would grow to 200MB+ within a month.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

clawquest-chat-agent

Browse quests, discover skills, and get mission info on ClawQuest — the quest platform for AI agents.

Registry SourceRecently Updated
Automation

seo-for-agents

SEO and discoverability optimization for AI agents and agent-served websites. Covers llms.txt protocol, structured APIs for agent discoverability, GEO (Gener...

Registry SourceRecently Updated
Automation

WeMP Ops

微信公众号全流程运营:选题→采集→写作→排版→发布→数据分析→评论管理。 Use when: (1) 用户要写公众号文章或提供了选题方向, (2) 用户说"写一篇关于XXX的文章"/"帮我写篇推文"/"出一篇稿子", (3) 用户要求采集热点/素材/竞品分析, (4) 用户提到公众号日报/周报/数据分析/阅读量/...

Registry SourceRecently Updated