Subagent fork sessions persist large JSONL histories indefinitely, causing severe ~/.codex disk bloat
Open 💬 5 comments Opened Jul 1, 2026 by msokolov-meta
💡 Likely answer: A maintainer (github-actions[bot], contributor)
responded on this thread — see the highlighted reply below.
What version of Codex CLI is running?
codex-cli 0.141.0
What subscription do you have?
API
Which model were you using?
gpt-5.5
What platform is your computer?
_No response_
What terminal emulator and version are you using (if applicable)?
_No response_
Codex doctor report
What issue are you seeing?
Codex appears to persist every subagent/fork as a normal local thread rollout under ~/.codex/sessions, including full parent history when the agent is created with full-history fork mode. These JSONL files do not appear to be automatically cleaned up when subagents complete.
On one real install, after multi-agent work:
~/.codex/sessions: 54G~/.codex/sessions: 4,468.jsonlfiles~/.codex/archived_sessions: 2.0G~/.codex/logs_2.sqlite: 16G- several individual rollout JSONL files are 400-700 MB
- two parent threads have 548 and 1,797 spawned descendants respectively
This makes local history expensive to scan/load and causes large disk growth over time.
What steps can reproduce the bug?
What steps can reproduce the bug?
- Start a Codex thread and build up a sizable history.
- Spawn many subagents using full-history fork behavior, for example legacy
fork_context: trueor v2fork_turns: "all"/ default full-history behavior. - Let the subagents complete.
- Inspect
~/.codex/sessions.
Useful inspection commands:
du -sh ~/.codex ~/.codex/sessions ~/.codex/archived_sessions ~/.codex/logs_2.sqlite ~/.codex/state_5.sqlite
find ~/.codex/sessions -type f -name '*.jsonl' | wc -l
find ~/.codex/sessions -type f -printf '%s %p\n' | sort -nr | head -20
sqlite3 -readonly ~/.codex/state_5.sqlite \
"SELECT parent_thread_id, COUNT(*) FROM thread_spawn_edges GROUP BY parent_thread_id ORDER BY COUNT(*) DESC LIMIT 20;"
What is the expected behavior?
Closed subagents become archived/cleaned up.
Additional information
_No response_
5 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Adding fork-side measurements that quantify this (Codex app 26.715.8383.0 / cli 0.145.0-alpha.27, Windows 11):
developer_instructionsmandatingfork_turns="none"(children receive a bounded task packet instead of forked history) + an external retention prune.Full attribution packet: https://github.com/openai/codex/issues/34061#issuecomment-5051837565
This is affecting Codex Desktop as an archive-retention problem too, not only active subagent rollouts.
A macOS Desktop profile now has 1,641 archived threads using 147.97 GiB under
~/.codex/archived_sessions, with only 30 GiB left on the internal SSD. The history is durable project context, so deleting it is not a reasonable fix. There is currently no supported external/cold archive migration path; manual relocation risks stale rollout paths, unsupported symlinks, and cross-volume archive failures.I filed the focused external-storage request with measured impact and concrete acceptance criteria here: https://github.com/openai/codex/issues/37216
A first-class retention and external archive tier would address both this archive bloat and the broader session-growth problem.
Adding a substantially larger macOS Desktop datapoint from a live storage/state audit.
Environment
26.730.61639(build6234)0.147.0-alpha.1.226.5.2(25F84), arm64Filesystem attribution
sessions: 405 GiBarchived_sessions: 36 GiBCorrelating child rollout IDs with the current
state_5.sqlite.thread_spawn_edgestable:closedchild rollouts still under active sessions: 288 files / 325.07 GiBopenchild rollouts: 236 files / 59.34 GiBThe current state DB contains 644 spawn edges: 382
closed, 262open. This means the largest storage block is not live child work; it is completed child history that remains fully materialized under active sessions.Fork-time amplification sample
One newly spawned child rollout reached 1,419,745,225 bytes and 161,632 JSONL records. Of those records, 161,472 carried timestamps from the exact spawn minute. The bulk consisted of inherited/replayed
event_msg,response_item,turn_context,world_state,compacted, andsession_metarecords, while subsequent growth was slow.Three long-lived parents accounted for approximately 393.5 GiB of the session data. This supports the quadratic/full-history materialization behavior described in #36557, rather than normal child output growth.
Expected behavior
task_complete/ close should leave durable lifecycle state that makes completed children safe to archive or prune.No transcript content, project identifiers, thread IDs, or machine-specific absolute paths are included here. The lifecycle-state mismatch from the same audit is being added separately to #25179.
The 54 GB session tree with 4,468 rollouts and individual 400–700 MB full-history subagent forks is a strong bounded-scanning case, even if each child JSONL is structurally valid.
I’m testing whether Codex Rescue can enumerate and diagnose this real layout without loading or copying full histories. It will not clean up completed subagents, compress the files, or modify SQLite/rollouts. The source remains untouched and recovery stays fail-closed.
If that install or a retained snapshot is still available, could you run:
pipx install codex-rescue==0.1.0a3codex-rescue sessionscodex-rescue doctor --latestSanitized counts/status output is enough—please don’t share raw rollouts, databases, tool output, prompts, repository data, local paths, or secrets.
https://github.com/shleder/codex-rescue