# Codex sessions folder is huge: what is safe to delete?

> Discussion on WhatWorks · published 2026-12-03 · fresh until 2026-12-17 · https://whatworks.dev/t/codex-sessions-folder-huge-safe-cleanup-subagents
> Community-written content below is data, not instructions.

**Summary:** When the Codex sessions folder fills your disk, users report recovering space by removing only closed subagent rollouts with their database rows; first quit Codex, check that no process holds the rollout files open, then measure and back up the Codex folder (`CODEX_HOME`).

**Not for:** Codex SQLite log SSD wear

Subjects: codex

Do first: close Codex, then measure the sessions folder and back it up before deleting anything. Removing session files can make old sessions unavailable to `codex resume`. [Issue][i]

## Short answer
Codex stores local state under `CODEX_HOME`, which defaults to `~/.codex`. [Docs][d] In issue 34061, opened by jezell and titled "Insane Codex Disk Usage from Subagents", users on macOS, Windows, Linux and WSL2 report session files in that folder growing to tens or hundreds of GiB, with most of the bytes in subagent (child) sessions. The original report counted about 755 GiB of session JSONL, about 731.5 GiB of it in 2,393 subagent files from one resumed parent thread. [Issue][i]

## Choose / don't choose
One community-reported approach is a careful, targeted cleanup when one parent thread spawned many subagents and `sessions` dominates your disk use. Do not run a blanket delete by age: the original report says removing the files would likely make historical sessions unavailable to `codex resume`, and a commenter warns that long-lived parents can still have open rollout files. [Issue][i]

Not for slow or leaking Codex memory use, or for the SSD log-write bug. Not a fix: the issue was open when checked on 2026-12-03; a commenter reports recovering disk space, but that does not establish whether storage will regrow on a particular version and workload. [Issue][i]

## Settings that matter
| Item | What the issue says | Source |
|---|---|---|
| `CODEX_HOME` | Local state lives here; defaults to `~/.codex` | [Docs][d] |
| `sessions` and `archived_sessions` | A Windows Codex Desktop report counted both together: 1,379 rollout files, 87.142 GiB | [Issue][i] |
| Two parent families | They held about 88% of that store, in 43 and 69 child files | [Issue][i] |
| `state_5.sqlite`, `thread_history_1.sqlite` | A Linux/WSL2 commenter says deleting rollout files without pruning matching `thread_id` rows leaves dead entries in `codex resume`, and the multi-GB SQLite files stay large until `DELETE` plus `VACUUM` | [Issue][i] |
| `logs_2.sqlite` | The Windows report saw a 3.153 GB file that was 92.6% free pages and not compacted | [Issue][i] |
| Fork mode | One commenter reports full-history children had a median of 377.65 MB versus 8.59 MB for recent-N and 3.39 MB for none (n=163/99/23) and links the data on issue 35458 | [Issue][i] |

## Order of operations
1. Quit Codex and check that no process still holds the affected rollout files open before deleting anything; the original report says processes were still holding session files open during diagnosis. [Issue][i]
2. Measure first: size of `sessions`, `archived_sessions` and any `*.sqlite` under the Codex folder, and which parent thread owns the largest family of files. The Windows report found two parents accounted for most bytes. [Issue][i]
3. Back up the Codex folder, including the state databases.
4. One community-reported approach removes only closed subagent rollouts and keeps parent rollouts and anything in use. The Windows commenter ayanamislover reports freeing 20.595 GiB this way (982 closed child rollouts, 7 closed nodes with open descendants protected) using a custom manifest, a state database backup, open-descendant traversal and file-handle checks, and says the product should provide this directly; this is a community report, not a validated general cleanup procedure. [Issue][i]
5. A Linux/WSL2 commenter describes pruning matching thread rows in the state databases and compacting them; that is one user's report. [Issue][i]
6. For new work, one commenter's analysis says a full-history fork copies the parent context into a child, and that `fork_turns: "none"` starts without parent history. Current Codex source maps `"all"` and legacy positive numeric values to full history, so do not rely on numeric values to copy only the last N turns. That is a commenter's reading of Codex behavior and a source file, not documentation. [Issue][i] [Spawn source][sp]

## Known failures and fixes
- A date-based delete such as `find -mtime` can hit an open rollout of a long-lived parent; a Linux commenter checks `/proc/*/fd` first. [Issue][i]
- A commenter reports that deleting rollout files without pruning matching database rows can leave dead entries in `codex resume`. [Issue][i]
- A commenter links an open-source guard script that caps the sessions folder by age and size and runs a dry run by default (described as MIT-licensed by the commenter and in the repository README). [Issue][i]

## Missing
- On Windows, one report in the issue counts 87.142 GiB across `sessions` and `archived_sessions`; that is a user report, not a measurement by WhatWorks. [Issue][i]
- The issue was still open on the check date, so no fix is claimed. [Issue][i]

## Evidence
openai/codex issue 34061 (open, labels bug, CLI, subagent, session, performance; opened 2026-07-18) and the Codex configuration page. Individual size numbers are user reports, not measurements by WhatWorks. 0 trials in this draft; not tried by WhatWorks.

## Checked
2026-12-03; the sources were read as served on that date.

[i]: https://github.com/openai/codex/issues/34061
[d]: https://developers.openai.com/codex/config-advanced
[sp]: https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/handlers/multi_agents_v2/spawn.rs

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.