01 / Find storage usage
Where does Codex store caches, sessions and worktrees?
Configuration and local state for the CLI and IDE extensions default to ~/.codex; the desktop app may also store interface caches and logs under ~/Library. Check SSH, container and cloud task data in the environment where tasks actually run; do not count it directly as local disk usage.
The table uses default paths. ~ means your home directory. If you set CODEX_HOME, replace ~/.codex in the table with its actual location. Not every version has every directory, and no “typical size” applies to all Macs. Measure with the commands in the next section.
| Path | Contents | Size reference | Effect of deletion |
|---|---|---|---|
~/Library/Caches/Codex/Default/Cache~/Library/Caches/Codex/Default/Code Cache | Resource and script caches in some desktop versions; not the CLI session directory. | No universal typical size; measure on this Mac. | Safe · With conditionsAfter fully quitting related apps, clean confirmed regenerable caches; the first opening may reload them. |
~/Library/Application Support/Codex/Default/GPUCache~/Library/Application Support/Codex/Default/DawnGraphiteCache~/Library/Application Support/Codex/Default/DawnWebGPUCache | Graphics rendering caches in some desktop versions; directories may differ between versions. | Measure actual directories; do not count all Application Support as caches. | Safe · With conditionsHandle only the listed cache subdirectories; do not empty all Codex application data. |
~/.codex/log~/Library/Logs/com.openai.codex | CLI or desktop diagnostic logs. CLI can change the location with log_dir; some versions also have a logs directory. | Depends on runtime and log level; skip if absent. | Safe · Old logsQuit related processes before removing unnecessary old logs; retain records needed for troubleshooting. |
~/.codex/shell_snapshots | Shell environment snapshots, not Git worktrees or recovery backups of project code. | Depends on session count; measure actual usage. | Safe · Old snapshotsHandle only old files from ended sessions. Quit CLI, desktop and extensions using the directory; do not empty it during tasks. |
~/.codex/packages/standalone~/.local/bin/codex | Standalone installer packages and the default command entry; adjustable with CODEX_HOME and CODEX_INSTALL_DIR. | Varies by version and architecture; the entry may be a link and does not show total package size. | Wrong deletion requires reinstallActive packages are not disposable caches. Incorrect deletion may stop the CLI from launching and require repair or reinstallation. Identify the source in section 5 first. |
Directory returned by npm root -gCodex cask managed by Homebrew | CLI and dependencies installed with npm / Homebrew, separate from session records in ~/.codex. | Depends on the manager and installation method; other Node versions may have another copy. | Reinstall after uninstallingMaintain or uninstall through the original package manager. Total npm and Homebrew caches serve multiple tools and cannot all be counted as Codex. |
~/.codex/plugins/cache | Plugin downloads and local copies, possibly containing files required at runtime. | Depends on plugin count and versions. | May need another downloadPrefer uninstalling unused plugins through plugin management. Downloads may be needed again; unbacked-up custom changes cannot be restored by downloading. |
~/.codex/sessions~/.codex/archived_sessions | Local session records and archived session records. | Accumulates with conversations, tool output and time; no reliable average. | Loses conversation historyDeletion may prevent continuing or restoring old sessions. Archived sessions still take space and are not ordinary logs. |
~/.codex/history.jsonl~/.codex/memories~/.codex/memories_v2 | History files and version-dependent local memories; no substitute for complete session directories. | Depends on retention settings and use; measure separately. | Loses history / memoriesDeletion loses the corresponding history or memories. Emptying history.jsonl does not empty sessions. Prefer managing memories in settings. |
~/.codex/worktrees | Codex-managed Git working copies, possibly containing source, dependencies, builds and uncommitted files. | Depends on project size and copy count; may exceed interface caches. | May lose code / filesCheck changes, branches, untracked and ignored files, then manage worktrees in the app. Do not move the entire directory to the Trash. |
~/.codex/config.toml~/.codex/auth.jsonproject/.codexproject/AGENTS.mdLocation specified by sqlite_home / CODEX_SQLITE_HOME | Configuration, credentials, project instructions and SQLite state. Databases default to CODEX_HOME; credentials may also be in the system keychain. | Identify the purpose first; size does not determine whether deletion is safe. | Keep configuration / stateKeep these. Do not clean .sqlite, -wal and -shm separately or reset all of ~/.codex as a cache. |
~/Documents/Codex~/Library/Application Support/Codex/artifact-sessions | Task working files, outputs and document session data in some desktop versions; other locations are possible. | Depends on tasks and actual files; not pure cache capacity. | May lose task outputsMay be generated documents, images or editing state. Open and inspect, export and back up before deciding to delete. |
Parent directory totals already include subdirectories; do not add them twice. The app’s built-in CLI, a standalone CLI in your terminal and other ChatGPT caches are different items. OpenAI in a path does not make all its contents cleanable Codex data.
02 / Three inspection steps
Measure caches, packages and history separately first
Save files, stop agents and automated tasks, quit CLI sessions and IDE extensions using these data, then fully quit the desktop app with ⌘Q. The following macOS Terminal commands only read paths and sizes. They do not delete files or require sudo.
Step 1: record total usage and available space on the volume
Save the output as your baseline. du -sh measures directories; df -k measures the volume containing each path. If a custom directory is on an external disk, its corresponding Filesystem will appear.
codex_data_dir="${CODEX_HOME:-$HOME/.codex}"
for p in \
"$codex_data_dir" \
"$HOME/Library/Caches/Codex" \
"$HOME/Library/Caches/com.openai.codex" \
"$HOME/Library/Application Support/Codex" \
"$HOME/Library/Logs/com.openai.codex" \
"$HOME/.cache/codex-runtimes" \
"$HOME/Documents/Codex"
do
if [ -d "$p" ]; then
printf '\n%s\n' "$p"
du -sh "$p"
df -k "$p"
else
printf 'Not found, skipping: %s\n' "$p"
fi
doneStep 2: expand the largest top-level directories
-d 1 expands one level only. Distinguish sessions, worktrees, packages and desktop caches. Do not add the final parent total to its children again.
codex_data_dir="${CODEX_HOME:-$HOME/.codex}"
for p in \
"$codex_data_dir" \
"$HOME/Library/Caches/Codex" \
"$HOME/Library/Application Support/Codex"
do
if [ -d "$p" ]; then du -h -d 1 "$p"; fi
doneStep 3: check whether sessions, working copies or packages dominate
If session records are large, removing a few interface caches will not remove them. If worktrees is large, inspect project contents. If packages/standalone is large, identify the active CLI installation first.
codex_data_dir="${CODEX_HOME:-$HOME/.codex}"
for name in sessions archived_sessions worktrees log logs \
shell_snapshots plugins/cache packages/standalone memories memories_v2
do
if [ -d "$codex_data_dir/$name" ]; then
du -sh "$codex_data_dir/$name"
fi
done
if [ -f "$codex_data_dir/history.jsonl" ]; then
du -sh "$codex_data_dir/history.jsonl"
fiEach command block reads the current terminal’s CODEX_HOME without changing it. A desktop app opened from a launcher may use a different environment. log_dir, sqlite_home and CODEX_SQLITE_HOME may also point elsewhere. Confirm your actual configuration, then run du -sh and df -k on those paths separately. The sqlite_home configuration setting takes precedence over the environment variable.
Skip directories that do not exist. Permission errors mean incomplete measurement, not zero usage; do not escalate privileges to delete files just to measure them. Keep path quotes, especially around Application Support, which contains a space.
03 / Clean according to the cost
Three safety levels: where should you start?
Confirmed caches and old logs you no longer need
Quit all related processes before handling desktop caches and old diagnostic files explicitly listed in the table. Keep logs needed for troubleshooting and temporary files in use. “Safe” does not include the entire application data directory.
Unused CLI installations and plugin copies
Identify their source, then maintain them through the corresponding installer or plugin manager. Deleting active packages can prevent the CLI from starting, and custom plugin changes will not restore themselves. Reuse may require a network connection and reinstallation.
Sessions, archives, memories, working copies and task outputs
sessions, archived_sessions and worktrees are not log caches. Keep configuration, login credentials and SQLite state too. Back up needed records and files to another disk first.
Clean level A only: confirm each item in Finder
- Stop tasks and quit the desktop app, CLI and related IDE extensions. Ensure no background session continues working.
- In Finder, press ⇧⌘G and paste one specific cache or log path from the table. Do not select all of
~/.codexor all ofApplication Support/Codex. - Check the directory’s purpose and file dates. Move only confirmed unnecessary items to the Trash. Keep logs needed for troubleshooting and state files you do not recognize.
- Review this cleanup’s items in the Trash. Permanently delete them only when you are sure they are no longer needed, then remeasure as described next. Moving files to the Trash alone has not reclaimed space.
Codex SQLite state may hold persistent information such as task indexes. Database files, -wal and -shm must remain consistent; do not delete just one to shrink them. If a database grows abnormally, back it up, check the version and use maintenance supported by that version. Do not copy arbitrary online SQL or empty state files directly.
04 / Verify cleanup results
How can you tell whether disk space really came back?
Check both how much the target directories shrank and how much available space increased on the corresponding volume. Keep Codex closed, pause large downloads, builds and copies, and rerun the commands from step 1. Remeasure custom locations using exactly the same paths as before.
codex_data_dir="${CODEX_HOME:-$HOME/.codex}"
for p in \
"$codex_data_dir" \
"$HOME/Library/Caches/Codex" \
"$HOME/Library/Caches/com.openai.codex" \
"$HOME/Library/Application Support/Codex" \
"$HOME/Library/Logs/com.openai.codex" \
"$HOME/.cache/codex-runtimes" \
"$HOME/Documents/Codex"
do
if [ -d "$p" ]; then
printf '\n%s\n' "$p"
du -sh "$p"
df -k "$p"
else
printf 'Not found, skipping: %s\n' "$p"
fi
doneCompare Available for the same Filesystem. df -k counts 1,024-byte blocks; divide the increase by 1,048,576 for approximate additional GiB. Several paths may be on one volume; do not add repeated available-space values.
Directories shrank but free space did not increase? Check in order
Files are still in the Trash, or backups remain on the same disk
Moving files to the desktop, renaming a directory or adding
.bakdoes not free space. Move files you need to an external disk and verify they are complete. Permanently delete only this cleanup’s items you have confirmed are unnecessary.The desktop app is closed, but the CLI or extensions are still running
Clients may share a directory. If a process still holds a deleted file open, its disk blocks may not have been reclaimed. Save your work and quit related programs normally; restart the Mac if needed, then measure again. The advanced read-only check below cannot rule out all processes when run as a regular user with empty output.
lsof +L1Archives, worktree recovery snapshots or APFS snapshots still hold data
Archiving a chat does not reduce local session records to zero. Managed worktrees may also save recovery snapshots before cleanup. This differs from Time Machine’s APFS local snapshots; both affect how you judge the amount deleted.
tmutil listlocalsnapshots /This command does not delete snapshots or cover every APFS snapshot. The system manages purgeable space, so Finder and
dffigures may differ. Do not bulk-delete recovery points just to increase the number immediately.You measured the wrong directory, or data were generated again
Check whether desktop and terminal use the same
CODEX_HOMEand whether data are on another volume. Reopening the app, installing plugins, restoring worktrees or continuing tasks may download resources and write records again.Records were deleted, but internal database space awaits reuse
A database file may not shrink immediately after records are deleted. Do not force reclamation by deleting the database or its WAL file, and do not treat a chat disappearing from the interface as proof that disk space was freed.
The selected directories use less space, and the same volume has more available space under the same conditions. Then reopen Codex and check login, needed sessions, CLI and project files. Record the app’s processed amount, directory reduction and additional disk space separately; the three figures need not match exactly.
05 / Remember the CLI
How should you handle CLI programs, package caches and working copies?
First identify which Codex your terminal runs
Codex CLI can be installed with the standalone installer, npm or Homebrew, and the desktop app may bundle another copy. The commands below list entry points visible to the current terminal, the active version and standalone package usage. Not finding codex only means it is absent from the current PATH, not that it is uninstalled everywhere.
codex_data_dir="${CODEX_HOME:-$HOME/.codex}"
if command -v codex >/dev/null 2>&1; then
type -a codex
codex --version
codex_command_path="$(command -v codex)"
if [ -f "$codex_command_path" ] || [ -L "$codex_command_path" ]; then
ls -l "$codex_command_path"
fi
else
printf 'No codex command in the current terminal PATH\n'
fi
if [ -d "$codex_data_dir/packages/standalone" ]; then
du -sh "$codex_data_dir/packages/standalone"
fiOn macOS, the standalone installer’s default entry point is ~/.local/bin/codex, with packages under $CODEX_HOME/packages/standalone. CODEX_INSTALL_DIR can change the entry location. Check the command link’s target first. Do not delete the whole packages directory as download leftovers or manually remove the CLI from inside the app bundle.
npm and Homebrew: maintain the original installation method
Run only the check block matching your installation method. npm queries the current Node environment; switching Node with nvm or fnm may reveal another global installation.
if command -v npm >/dev/null 2>&1; then
npm list -g @openai/codex --depth=0
npm root -g
npm config get cache
else
printf 'npm not found in the current terminal\n'
fiif command -v brew >/dev/null 2>&1; then
brew list --cask codex
brew --cache
else
printf 'Homebrew not found in the current terminal\n'
fiIf the list is empty or reports no installation, check for another source first. npm config get cache and brew --cache return shared package-manager caches. Do not count the whole directory as Codex usage or delete it in bulk just to clean Codex.
When a CLI copy is no longer needed, uninstall it with the manager that installed it. If you still need it, maintain it using its corresponding update method. Uninstalling programs, cleaning installation leftovers and deleting sessions are three different actions. You do not need to empty ~/.codex to uninstall the CLI.
Large worktrees: protect code before handling working copies
A worktree may contain full source code, its own node_modules and build outputs. Run the checks below inside the specific worktree you intend to handle, and open needed files to inspect them. Do not delete the entire worktrees root.
git worktree list
git status --short --untracked-files=all
git status --short --ignoredA clean working directory does not mean commits have been pushed. Untracked or Git-ignored files may also be important outputs. Merge, hand off or independently back up work first, then use the app’s worktree management for managed copies. The app may save recovery snapshots first; do not assume all ignored files are preserved or that cleanup immediately releases the entire worktree size.
Assess project dependencies, build outputs and local models according to their project and tools. In particular, manage local models used with --oss in the model tool; they are not Codex interface caches.
06 / Open fewer directories
Prefer an automatic scan? Find Codex storage with AgentClean
AgentClean supports scanning local Codex cleanup items. Review results and cautions before choosing what to handle. You decide whether to keep items involving plugins, document sessions and task outputs.
Start with supported desktop caches, old logs, update leftovers and some CLI temporary data. Session records, worktrees, main state databases and standalone CLI packages are outside the cleanup rules checked for this page. Coverage of custom data directories, npm and Homebrew also depends on actual scan results.
Stay tuned
AgentClean is currently available only for Mac. Other platforms aren’t available yet. Visit this site on a Mac to download.
Scanned size is not necessarily reclaimable space. You can also verify after cleanup with the du / df method on this page.
07 / Frequently asked questions
What else should you check before cleaning Codex?
Do Codex CLI and desktop use the same data?
They and IDE extensions may share the same CODEX_HOME, defaulting to ~/.codex. The desktop app also has caches and logs under Library. Terminal environment variables describe only that terminal; they do not prove desktop, SSH hosts or containers use the same path. Confirm actual data locations for each client and quit related processes before cleanup.
Can I delete the whole ~/.codex directory?
This is not recommended. It may contain sessions, archives, configuration, login credentials, memories, SQLite state, working copies and standalone CLI packages. Deleting it all can lose history or files and prevent the CLI from running. Measure each category as described here and handle only confirmed caches and old logs you no longer need.
Does uninstalling Codex CLI also delete chat records?
The CLI program and local session directory are separate. Uninstalling with the original installation method should not be treated as clearing CODEX_HOME; deleting sessions does not uninstall the CLI either. Identify the standalone installer, npm or Homebrew source and read the uninstall prompts. The app’s bundled CLI may remain, and important records need a separate backup.
Will archiving chats automatically reclaim space?
Not necessarily. Archived session records may remain in archived_sessions. Desktop may clean associated managed worktrees after saving recovery snapshots, but that does not remove all session records and recovery data. Remeasure directory sizes and available space on their volume separately.
How do history.jsonl and sessions differ?
history.jsonl is a history file controlled by history configuration; sessions and archived_sessions hold local session records. Limiting or deleting history.jsonl does not limit all session storage or guarantee removal of every conversation. history.max_bytes only applies to that history file. Do not delete needed or continuing sessions as logs.
Why did available Mac storage not increase after deletion?
Confirm files are out of the Trash and backups are not on the same disk. Check for processes holding files open, worktree recovery or APFS snapshots retaining data, and regenerated caches. Compare du for the same paths and df for the same Filesystem. App processing totals, directory reduction and additional disk space may differ.
What if a directory is missing or CODEX_HOME has changed?
Skip missing directories; they may apply only to a specific version or usage mode. Commands prefer CODEX_HOME from the current terminal. If desktop, log_dir, sqlite_home or CODEX_SQLITE_HOME points elsewhere, measure the actual paths and their volumes separately. Permission errors do not mean zero usage and do not justify deleting with sudo.
Can AgentClean scan Codex desktop and CLI data?
It scans Codex desktop caches, logs and some CLI directories covered by its rules, for you to review and select. Session directories, worktrees, main state databases and standalone CLI packages are outside the rules checked here. Do not assume custom CODEX_HOME, npm or Homebrew data are all recognized. Actual items, retention conditions and cautions depend on the current version’s scan results.