SafeDisk AI

AI agent storage incident

OpenClaw Codex logs_2.sqlite Taking Disk Space

If an OpenClaw-managed Codex home grows through logs_2.sqlite, logs_2.sqlite-wal, or trace rows, treat it as trace retention first. Measure the database, preserve enough evidence, and avoid deleting session state or auth data while a gateway or app-server process is still using the files.

Free AI storage decision

Get an AI storage cleanup decision before you pay.

Leave your email now; the scan summary or one-line error can follow after the first reply. We offer the $29 Deep Cleanup only if the agent cache or session state still needs review.

Start SafeDisk Lite scan
Start free scan Send cleanup request

What Is Usually Happening

OpenClaw can run Codex with a managed CODEX_HOME. In long-lived agent or gateway setups, trace storage may grow separately from user-visible sessions. A large logs_2.sqlite can be diagnostic evidence, but it can also become routine storage pressure if there is no retention policy.

Read-only first pass

Measure trace storage without reading private log contents.

These commands report sizes and counts. They do not print prompts, file contents, or log rows.

base="$HOME/.openclaw/agents/main/agent/codex-home"

du -sh "$base" "$base"/logs_2.sqlite* 2>/dev/null
find "$HOME/.openclaw" -name 'logs_2.sqlite*' -print0 2>/dev/null \
  | xargs -0 du -h 2>/dev/null | sort -h

sqlite3 "$base/logs_2.sqlite" 'select count(*) from logs;' 2>/dev/null
sqlite3 "$base/logs_2.sqlite" \
  'select level, count(*) from logs group by level order by count(*) desc;' 2>/dev/null
sqlite3 "$base/logs_2.sqlite" \
  'select target, count(*) from logs group by target order by count(*) desc limit 20;' 2>/dev/null

lsof -nP "$base"/logs_2.sqlite* 2>/dev/null

Safe Recovery Order

  1. Stop starting new OpenClaw or Codex work while the filesystem is close to full.
  2. Capture the read-only size, row count, target distribution, and current writer process.
  3. Stop the OpenClaw gateway or managed Codex app-server cleanly before moving SQLite files.
  4. Move logs_2.sqlite* into a timestamped backup folder instead of deleting immediately.
  5. Restart OpenClaw, verify turns still work, then compress or remove the backup after you no longer need evidence.
  6. Add a retention job or alert so the same trace DB does not silently regrow.
Move, do not blind-delete

Use this only after the gateway/app-server is stopped.

This preserves a rollback path and keeps session JSONL/state files outside the cleanup target.

base="$HOME/.openclaw/agents/main/agent/codex-home"
backup="$HOME/.Trash/SafeDisk-OpenClaw-Codex-logs-$(date +%Y%m%d-%H%M%S)"

mkdir -p "$backup"
for file in "$base"/logs_2.sqlite "$base"/logs_2.sqlite-wal "$base"/logs_2.sqlite-shm; do
  [ -e "$file" ] || continue
  mv "$file" "$backup"/
done

du -sh "$backup" 2>/dev/null
echo "Restart OpenClaw, verify one turn, then decide whether to compress or delete this backup."

Do Not Delete First

Deep Cleanup

Need an AI CLI cleanup order?

Submit the form first; the AI CLI or agent storage symptom can follow. We check whether free guidance is enough before asking for the $29 Deep Cleanup.