See:
- https://github.com/openai/codex/issues/28224
- https://www.reddit.com/r/OpenAI/comments/1ucf4px/openai_codex_has_a_bug_that_could_kill_your_ssd/
Fix:
It is perfectly safe to disable or delete the ~/.codex/logs_2.sqlite file. This file is used exclusively for local logging and diagnostic data. It does not contain any of your conversation history, user preferences, API keys, or project state.
Codex has a known logging bug that continuously writes massive amounts of data (up to hundreds of gigabytes per year) to this database. Because of this, it is actively recommended to manage or disable it. [1]
You can safely remove the file or the entire
~/.codex directory if you want to clear up space. Codex will simply recreate the directories/files as needed (though the excessive logging will resume).To prevent the continuous disk writes without breaking the logging functionality, you can create a symlink to redirect the file into your system's
/tmp/ folder. Data in /tmp/ is stored in RAM and is wiped when you restart your computer. # Ensure the codex directory exists
mkdir -p ~/.codex
# Move the current file out of the way or delete it
rm ~/.codex/logs_2.sqlite
# Create a symlink to /tmp
ln -s /tmp/logs_2.sqlite ~/.codex/logs_2.sqlite
3. Clear the associated WAL and SHM files
If your disk is suddenly filling up, check for logs_2.sqlite-wal and logs_2.sqlite-shm files. These SQLite temporary and Write-Ahead Log (WAL) files can grow to tens of gigabytes. You can safely delete these whenever the Codex application or CLI is fully closed.
dev/null (the system black hole). This discards the logs instantly.rm ~/.codex/logs_2.sqlite
ln -s /dev/null ~/.codex/logs_2.sqlite However, the above does not work. Codex cannot start and refers to missing the database. So have to use the /tmp redirect. cat << 'EOF' > ~/Library/LaunchAgents/com.user.clear_codex_ram.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://apple.com">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.clear_codex_ram</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>-c</string>
<string>/usr/bin/killall -STOP Codex 2>/dev/null; /bin/echo -n "" > /tmp/codex_logs_2.sqlite; /usr/bin/killall -CONT Codex 2>/dev/null</string>
</array>
<key>StartInterval</key>
<integer>7200</integer>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOF
7200 value represents 7,200 seconds, which tells macOS to run this exactly every 2 hours. It safely pauses Codex for a millisecond, truncates the file to 0 bytes, and resumes Codex).launchctl load ~/Library/LaunchAgents/com.user.clear_codex_ram.plist launchctl unload ~/Library/LaunchAgents/com.user.clear_codex_ram.plist
rm ~/Library/LaunchAgents/com.user.clear_codex_ram.plist
No comments:
Post a Comment