Customizable retention period for sessions
What feature would you like to see?
I would like Codex CLI to periodically clean up old conversation history files based on a user-defined retention window. Currently, Codex retains every conversation indefinitely, so the history folder grows larger over time even though many of those conversations are no longer useful.
The proposed feature would allow users to specify a retention period (for example, 30 or 60 days), and Codex would automatically remove conversations older than that window. This would help keep the history directory at a manageable size and prevent storage from being consumed by outdated or irrelevant sessions. It would also be helpful if the retention duration were configurable so users could choose the period that best fits their needs.
Additional information
No response
+1
Also, it would be great if retention could be configured per session, not only globally.
In practice, I have different types of sessions:
- one-off review requests or quick investigations that I’m fine with deleting very quickly (e.g., after 1 hour or a few hours; ideally configurable either at creation time or later, including “ephemeral” sessions that disappear soon),
- and long-running sessions that I don’t want to be removed automatically.
So it would be helpful to have:
- a way to set a short retention/TTL when starting a session (or mark a session as ephemeral),
- and a pin / keep option to prevent certain sessions from being cleaned up.
Finally, I’d like the same capability not only in the CLI but also in the VS Code Extension, so retention/TTL and pinning can be managed consistently from both environments.
If you add this, please do not enable it by default.
Any plans to add this feature anytime soon? @etraut-openai
It would be great if it could be used not only in the CLI but also in apps and extensions.
Please make this opt-in, and never a silent default.
As a data point for how this goes wrong: Claude Code ships exactly this feature with a 30-day default, hard unlink(), no consent prompt, no in-app way to view the setting or see what's about to be swept, and no restore path. The result is multiple open data-loss reports from users who lost months of history without ever knowing the mechanism existed — anthropics/claude-code#59248 and anthropics/claude-code#62476, both labelled data-loss by the maintainers.
Disk pressure is a real problem and worth solving. But the fix for "my history folder is large" should not silently destroy other people's history. Concretely: default off; if enabled, an explicit prompt on first run; a dry-run mode; a visible next-sweep indicator; and delete to a trash/quarantine directory rather than straight to unlink().
I would also like to see this.
Adding an independent Windows Codex Desktop data point for the need for session retention and storage controls.
On Windows 11 x64 with Codex Desktop build 26.803.5235.0, my local Codex directory reached approximately 398.8 GB, of which 396.5 GB was under sessions across 554 rollout-*.jsonl files. The C: drive reached 0 bytes free; the largest rollout was 9.37 GB.
I had to manually delete 273 older rollout files to reclaim approximately 104.7 GB. Codex was still writing during the cleanup and added approximately 11.6 GB in a short interval.
This makes an opt-in retention policy, a size/age report, compression/vacuuming, and a supported Desktop delete/archive workflow important. Any retention feature should preview the files, require confirmation, and provide a restore/backup path rather than silently deleting history.
Would love this as well. Ideally I'd love a global default with the ability to override per project. For example I have some misc script or daily standup type projects I only need maybe a week or two of history on but mission critical apps would prefer a longer retention. I'd love to not have to script something outside the app (or scheduled task within) to cleanup.
Edit: Here's a workaround script where I have a daily archive scheduled task and a weekly cleanup:
bash {path}/codex-thread-cleanup.sh --archive --days 60 --executebash {path}/codex-thread-cleanup.sh --delete --days 90 --execute
+1 on built-in retention. After our ~/.codex hit ~79 GiB on WSL2 (67.83 GiB in sessions/, 5.86 GiB in thread_history_1.sqlite, plus 352,950 leaked .tmp/git-* directories), we built and Team-Red-tested an external ring-buffer guard that might be useful both as an immediate workaround for Linux/WSL2 users and as a checklist of invariants for the native implementation:
Repo: https://github.com/simfor99/codex-hdd-guard (MIT, Python 3.10+ stdlib only, zero dependencies)
Key invariants that mattered in practice:
- Dual age + size cap with a hard safety floor: Delete closed, unpinned rollouts older than
Ndays (default 14d), then evict oldest unpinned rollouts untilsessions/is underMGiB (default 5.0 GiB), but never delete any rollout modified within the last 48 hours. - Fail-closed pin index (
is_pinned = 1): Readthreads.is_pinnedfromstate_5.sqlitebefore touchingsessions/. Ifstate_5.sqliteis locked or unreadable, abort before deleting any session file. - Live file-descriptor check (
/proc/*/fd): Never unlink a rollout or vacuum a DB that is currently held open by a live process. - SQLite reconciliation +
VACUUM: Deletingrollout-*.jsonlfiles must also prune the matchingthread_idrows fromstate_5.sqliteandthread_history_1.sqliteand runVACUUM(after checkingstatvfsfree space >= 1.25x DB size), otherwisecodex resumeshows dead sessions and gigabytes stay trapped in SQLite freelist pages.
🤖 Is there a supported native way to conditionally delete one archived local thread, including its one approved rollout file and explicitly listed history/state/host-owned cleanup, rather than removing a transcript file behind Codex?
The intended workflow is a non-mutating preview, fresh approval of the exact target and every cleanup effect, then deletion only if the approved state still matches. For a bounded first case:
- Require the thread to remain archived, with its latest update timestamps and rollout mtime strictly before a fixed cutoff captured at preview (for example, 30 days before preview, not 30 days since archiving). Approval expires; execution does not advance the cutoff.
- Revalidate archive/activity state, file identity/state and relationship membership in the same native-owned exclusion interval as deletion, before any cleanup. Refuse changed or uncertain state and loaded/live work in any process. Do not stop work to make it eligible.
- Refuse surviving incoming history references, attached children, spawned descendants or additional rollouts. Do not silently expand deletion to related threads or files; unreadable/incomplete relationship metadata must also refuse.
Existing interactive deletion is useful, but the public delete request carries only threadId, and the handler includes spawned-subtree preparation/deletion. I couldn't establish the conditional contract above from those surfaces.
Could you point to the supported call and minimum deleting-client and shared-home writer versions, including mixed CLI/app versions and metadata/fork/descendant publishers? If this is not supported, does it need a native-owned extension? Guidance on a mutation-free preview/connection path and reporting/reconciling partial failures would also help. This is a support/design question, not an external code proposal