---
name: openclaw-cleanup
description: "Scan dan hapus file sampah/config cache/session history di direktori .openclaw. Aman — selalu dry-run dulu sebelum delete. Jalanin dengan /run openclaw-cleanup."
---

# OpenClaw Cleanup 🧹

Bersihkan file sampah, cache, backup lama, dan history yang nggak terpakai di `~/.openclaw/`.

**PRINSIP**: Dry-run dulu, BOSS konfirmasi, baru hapus. Nggak pernah langsung delete.

## Usage

```
/run openclaw-cleanup              # dry-run (default)
/run openclaw-cleanup --delete     # hapus setelah dry-run confirms
/run openclaw-cleanup --delete --older-than 7  # hapus file > 7 hari
```

## Target yang Dihapus

### ✅ Safe to Delete (low risk)
- `openclaw.json.bak*` — config backup lama (>1 hari)
- `openclaw.json.last-good` — duplikat config
- `gateway-supervisor-restart-handoff.json` — handoff sekali pakai
- `update-check.json` — cache update checker
- `cache/*` — semua file cache (bisa regenerate)
- `agents/main/sessions/*/reset/` — session reset artifacts
- `agents/main/sessions/skills-prompts/` — cached skill prompts
- `delivery-queue/failed/*.json` — failed deliveries (>1 hari)
- `session-delivery-queue/failed/*.json` — failed deliveries (>1 hari)
- `logs/stability/*.json` — stability logs lama (>7 hari)
- `logs/config-audit.jsonl` — audit log (di-truncate, bukan dihapus)

### ⚠️ Needs Caution (medium risk, excluded by default)
- `agents/main/sessions/*.trajectory.jsonl` — session trajectories (besar! 66M+)
  - Hanya hapus jika >30 hari BOSS explicitly approve
- `tasks/runs.sqlite*` — task run history
- `flows/registry.sqlite*` — flow registry
- `plugin-state/state.sqlite*` — plugin state
- `subagents/runs.json` — subagent run records

### ❌ NEVER Delete
- `openclaw.json` — config utama
- `credentials/` — credentials
- `identity/` — agent identity
- `agents/main/agent/` — agent state
- `cron/` — cron jobs
- `workspace/` — workspace BOSS
- `memory/` — memory
- `media/outbound/` — media yang dikirim
- `telegram/` — telegram config
- `devices/` — paired devices
- `completions/` — shell completions
- `concepts/` — concept docs
- `plugin-skills/` — installed plugin skills

## Tools Used

- `exec` — untuk find, du, rm, truncate

## Script

Lihat `scripts/cleanup.sh` di skill directory ini.

## Safety

1. ** selalu dry-run dulu**
2. Preview size + jumlah file
3. BOSS harus ketik `ya` sebelum delete
4. Exclude list diutamakan (lebih aman skip daripada delete)
5. Truncate untuk log files (bukan delete)
