Feature request: native cleanup tool for outdated automation runs
What problem would this solve?
Codex automations can create many completed runs and, for worktree-backed project automations, many associated worktrees over time. The current documented guidance is to archive automation runs no longer needed, but there does not appear to be a first-class, metadata-backed tool/API that can safely apply a retention policy to completed automation runs.
Today, a cleanup automation has to approximate this by listing recent Codex threads and calling set_thread_archived on known thread IDs. That is brittle because it requires inferring automation ownership and eligibility from thread titles/previews/status rather than structured automation metadata.
Requested feature
Please add a native Codex tool/API for cleaning outdated automation-created runs/tasks.
It should support:
- Listing automation-created runs with structured fields such as
automation_id,created_at,updated_at,status,pinned,archived, ownership/source, and associated worktree state. - Dry-run mode that returns exactly which runs would be archived/deleted and why others were skipped.
- Applying a retention policy, for example archive completed automation runs older than 24 hours or 7 days.
- Default exclusions for active/running runs, pinned runs, user-owned conversational threads, non-automation threads, the current cleanup run, and ambiguous matches.
- Structured results with archived/skipped/error counts and per-run reasons.
- Ideally per-automation retention settings, so high-frequency automations can clean themselves safely.
Current workaround
A recurring cleanup automation can use list_threads and set_thread_archived, but it must be conservative and skip anything whose age, completion state, or automation ownership is unclear. This avoids accidental archival but leaves stale automation runs behind and makes cleanup logic fragile.
Why this matters
The Codex app already documents that frequent automations can create many worktrees over time and recommends archiving runs that are no longer needed. A dedicated cleanup tool would make that recommendation practical and safe for recurring automations without relying on title/preview inference.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗