PaulRBerg / PaulRBerg/dot-codex
Add a script/skill to prune dead projects from Codex CLI state
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Problem
Codex CLI tracks workspace/project paths in a few places that grow over time and never get pruned when the underlying folder is deleted (worktrees, throwaway scratch dirs, removed repos, etc.):
~/.codex/.codex-global-state.json:active-workspace-roots— array of pathselectron-saved-workspace-roots— array of pathsproject-order— array of paths
~/.codex/sessions/<YYYY>/<MM>/<DD>/rollout-*.jsonl— each rollout's first line is asession_metaevent with acwdfield pointing at the project the session was run from.~/.codex/archived_sessions/rollout-*.jsonl— same structure assessions/.
There's no built-in way to garbage-collect any of these against on-disk reality.
Solution
A script (or skill) that:
- Loads
~/.codex/.codex-global-state.jsonand walks each of the three arrays (active-workspace-roots,electron-saved-workspace-roots,project-order). - For each path, checks whether it still exists on disk (
test -d). - For paths that no longer exist: drops them from the arrays.
- (Optional, behind a flag like
--prune-sessions) walks~/.codex/sessions/**/rollout-*.jsonland~/.codex/archived_sessions/rollout-*.jsonl, reads the first JSONL line to extractpayload.cwd, and deletes rollout files whosecwdno longer exists on disk. - Dry-run by default; require
--applyto mutate. - Backs up
~/.codex/.codex-global-state.jsonbefore writing (there's already a.bakconvention — append.bakwith a timestamp or roll the existing one). - Prints a summary: dead entries per array, rollout files removed, total bytes reclaimed.
Nice-to-haves:
--keep-sessions(default) vs--prune-sessions— keeping transcripts is the safer default since rollouts are useful history.--only <field>to target a single state-array (e.g. only fixproject-order).- Honor
$CODEX_HOMEinstead of hardcoding~/.codex.
Either a standalone bash/zsh script in this repo or an agent skill under skills/ would work — same shape as the analogous request on the Claude Code side (PaulRBerg/dot-claude#98).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect the repository for existing scripts or skills, then use the issue's ~/.codex/.codex-global-state.json and sessions paths as the implementation targets. Start by confirming the state-array and rollout formats, including CODEX_HOME behavior. Done means a dry-run cleanup reports dead entries, --apply safely backs up and updates state, and session pruning remains opt-in.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, zsh
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100