Session Log Rotation¶
The SQLite database at .codex/session_logs.db stores session metadata. Without maintenance it can grow indefinitely.
An index on (session_id, ts) is created automatically. This index
substantially improves query performance and makes retention pruning much
faster on large log sets.
Retention policy¶
- Keep only the last 30 iterations of entries.
- Remove older records and NDJSON files regularly to satisfy enterprise retention policies.
Use tools/purge_session_logs.py to remove stale NDJSON files and prune
session_events rows in the SQLite database:
python tools/purge_session_logs.py # purge items older than 30 iterations
python tools/purge_session_logs.py --days 60 # custom retention window
python tools/purge_session_logs.py --dry-run # show actions without deleting
Archive then prune¶
- Create a backup before deleting old rows:
- Delete old rows and vacuum the database to reclaim space:
Full reset¶
If the database becomes corrupted or exceptionally large, remove it and let tooling recreate a fresh database:
Archive backups in a secure location according to your organization's policies.