Automated disk space recovery for OpenClaw deployments. Covers 12 cleanup categories that OpenClaw does not handle natively (as of 2026.3.13).
session.maintenance config (pruneAfter, maxEntries, rotateBytes)sandbox.prune config (idleHours, maxAgeDays)contextPruning config (cache-ttl mode)#CategoryTypical GrowthTrigger1Memory SQLite .tmp-* orphansHundreds of MB from failed reindexAlways2Memory SQLite VACUUMFragmentation after heavy use--aggressive3Docker images/volumes/build cacheGB from sandbox rebuildsAlways4Gateway logs ( /tmp/openclaw/*.log)Grows daily>3 days old5/tmp OpenClaw temp filesPatrol/board/cron artifacts>24h old6Workspace .prebind.* backupsHundreds of MB per backup>7 days old7Delivery queue old entriesGrows with message volume>7 days old8systemd journalGB on default VPS configs>500MB9npm/yarn/pnpm/bun/prisma/node-gyp cacheGB from skill/plugin installs>100MB10Rotated syslogs + btmpSSH brute-force logs on public VPSAlways11Git workspace .gitAuto-commit growth (board-move etc.)>200MB12QMD/migration artifactsStale after backend switchAuto-detected
Run directly:
bash
# Preview what would be cleaned (safe, no deletions)
bash scripts/disk-cleanup.sh --dry-run
# Normal cleanup
bash scripts/disk-cleanup.sh
# Deep cleanup: includes SQLite VACUUM + aggressive git gc
bash scripts/disk-cleanup.sh --aggressive
# Cron mode: only outputs summary line
bash scripts/disk-cleanup.sh --quiet
Weekly Sunday 04:00 CET (recommended):
text
Use the cron tool:
schedule: { kind: "cron", expr: "0 3 * * 0", tz: "Europe/Luxembourg" }
payload: { kind: "agentTurn", message: "Run disk cleanup: bash scripts/disk-cleanup.sh --aggressive --quiet. Report results." }
sessionTarget: "isolated"
Or integrate into an existing infra-health-check script by adding a disk usage threshold trigger:
bash
DISK_PCT=$(df / --output=pcent | tail -1 | tr -d ' %')
if [ "$DISK_PCT" -ge 85 ]; then
bash /path/to/disk-cleanup.sh --quiet
fi
if [ "$DISK_PCT" -ge 90 ]; then
bash /path/to/disk-cleanup.sh --aggressive --quiet
fi
VariableDefaultDescriptionOPENCLAW_HOME``~/.openclawOpenClaw state directoryOPENCLAW_WORKSPACE``$(pwd)Agent workspace root
0 — Success (cleaned or nothing to clean)1 — Error during cleanupLast line is machine-parseable:
text
CLEAN|0|0B|44% # Nothing cleaned
CLEANED|5|1.2GB|67% # 5 actions, freed 1.2GB, now at 67%
--dry-run previews all actions without deleting--aggressive and only when fragmentation ≥5%--auto by default; --aggressive only with flag