Codex session logs growing to hundreds of GB: cleanup without losing the history

Published · Updated · Checked against Codex CLI 0.166.0

Three things make Codex rollout files huge: compaction snapshots, inline base64 images, and subagents that copy their parent's history. Each session is one JSONL file under ~/.codex/sessions/. Measure with du, remove sessions with codex delete <session>, and copy the files first if you want the history.

The sizes below come from one macOS machine running Codex CLI 0.166.0, set beside two open GitHub issues and the Codex config reference. The official docs document no session-retention setting.

Measuring

du -sh ~/.codex
du -sh ~/.codex/sessions ~/.codex/*.sqlite* | sort -rh
find ~/.codex/sessions -name 'rollout-*.jsonl' -size +500M -exec ls -lh {} +

Mine, today:

34G   ~/.codex
21G   sessions
4.4G  state_5.sqlite
3.2G  thread_history_1.sqlite
89M   logs_2.sqlite

That is 1,007 rollout files in 79 day folders, laid out as ~/.codex/sessions/YYYY/MM/DD/rollout-<timestamp>-<session-id>.jsonl (see where Codex stores sessions). The largest file is 2.5 GB. A day-by-day total finds the worst days:

du -sh ~/.codex/sessions/*/*/* | sort -rh | head

Taking a 2.5 GB file apart

A grep over that file:

f=~/.codex/sessions/2026/06/18/rollout-2026-06-18T00-07-27-019ed656-67aa-7472-80d3-09da59718855.jsonl
wc -l < "$f"                                    # 175960 lines
grep -c '"type":"compacted"' "$f"               # 397 compaction records
grep '"type":"compacted"' "$f" | wc -c          # ~1.7 GB of the 2.5 GB
grep -c 'data:image/png;base64' "$f"            # 552 lines carry an inline image

About two thirds of the file is 397 compaction records. Each stores a full copy of the history, and the images inside it are base64 text. That matches what users report on GitHub.

Issue 24948 (opened 28 May 2026, still open on 10 Nov 2026, on 0.118.0 and later) describes rollouts of 700 MB to 2 GB and session stores of 91 GB and larger. The thread names four causes: each compaction appends a full replacement_history snapshot, inline base64 images are copied into every snapshot, subagents inherit and re-persist parent history, and raw tool output is persisted in full.

Maintainers replied that rollouts record full session details and that compression and a delete command were planned. Per the thread, 0.141.0 added codex delete <session ID>. A zstd compression feature for cold rollouts arrived in 0.153.0 as experimental and off by default, and commenters say it does not stop the repeated snapshots from being written. It is untested here.

Issue 34061 (opened 18 Jul 2026 on 0.144.6, still open on 10 Nov 2026) is about subagents. The reporter found about 755 GiB under ~/.codex/sessions, 731.5 GiB of it from 2,393 subagent files spawned by one resumed parent thread, because children copy the parent's full history into their own rollout files. The thread's workarounds are fork_context:false (v1) or fork_turns:"none" or a small bound (v2) so children do not copy history, and deleting closed subagent rollouts by hand, after checking for open file handles and state database entries.

What you can delete

Codex keeps more than the JSONL.

ItemDelete?Reason
A rollout file for a session you will never resumeYes, with codex deleteYou lose resume for that session, and the transcript
~/.codex/sessions/ wholesaleNo, not without a copyIt is the only full record
state_5.sqlite, thread_history_1.sqliteNoThe config reference calls sqlite_home the "state DB used by agent jobs and other resumable runtime state". What each file holds is not confirmed
auth.json, config.tomlNoYour login and settings
logs_2.sqliteProbably, not confirmedThe issue thread says SQLite logs are rotated. The docs have no note on deleting it

For a rollout, use the CLI instead of rm:

codex delete --help
codex delete <session-id-or-name>

The help text says codex delete permanently deletes a saved session by ID or name. A manual rm leaves the state databases pointing at a file that no longer exists, which is the warning in issue 34061. What Codex does with such an entry is untested.

codex archive <session> also exists, but its help says only "Archive a saved session by id or session name". It is not confirmed that it moves the file, compresses it or frees space, and the ~/.codex checked has no archive folder.

Settings that look relevant

The config reference has history.max_bytes, which "caps the history file size in bytes by dropping oldest entries". It sits under the history table next to history.persistence, which controls history.jsonl. Neither is documented as limiting sessions/, and there is no session-retention key in the config reference (reached by redirect from developers.openai.com, read 10 Nov 2026).

Copy first, then delete

JSONL with repeated snapshots compresses very well:

tar -I 'zstd -19 --long=27' -cf /Volumes/Backup/codex-sessions-$(date +%F).tar.zst -C ~/.codex sessions
tar -I zstd -tf /Volumes/Backup/codex-sessions-$(date +%F).tar.zst | head

Without zstd, use tar -czf ... .tar.gz. Make sure the archive lists back before you delete anything, then codex delete the sessions you no longer need to resume, oldest and largest first. Back up Claude Code and Codex sessions compares other ways to copy, and Claude Code disk usage is the same problem on the other tool. All guides: /guides/.

Sealkeep and reclaiming space

Sealkeep seals Codex sessions, verifies a copy in your storage, and only then lets the local file go. For Codex it leaves a tiny valid resume pointer under the same session id, so resume still opens; sealkeep recover <archive-id> --native --overwrite backup restores the full original, and sealkeep squeeze measures what it would free.

Reclaim is opt-in (sealkeep autopilot --reclaim) and needs Sealkeep Cloud today, and with your own bucket every original stays. It does not shrink a rollout, deduplicate compaction snapshots, stop subagents from forking history, or touch the SQLite files.

FAQ

Is it safe to delete ~/.codex/sessions?

Only with a copy. It is the only full record of your sessions, and you lose resume for whatever you remove. Use codex delete for single sessions.

Does history.max_bytes limit session size?

The config reference describes it for the history file, and it is not documented as limiting sessions/.

Can I stop subagents from copying history?

The issue 34061 thread lists fork_context:false or fork_turns:"none". Neither is tested on 0.166.0.