PaulRBerg / PaulRBerg/dot-codex

Add a script/skill to prune dead projects from Codex CLI state

Open
#2 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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.):

  1. ~/.codex/.codex-global-state.json:
    • active-workspace-roots — array of paths
    • electron-saved-workspace-roots — array of paths
    • project-order — array of paths
  2. ~/.codex/sessions/<YYYY>/<MM>/<DD>/rollout-*.jsonl — each rollout's first line is a session_meta event with a cwd field pointing at the project the session was run from.
  3. ~/.codex/archived_sessions/rollout-*.jsonl — same structure as sessions/.

There's no built-in way to garbage-collect any of these against on-disk reality.

Solution

A script (or skill) that:

  1. Loads ~/.codex/.codex-global-state.json and walks each of the three arrays (active-workspace-roots, electron-saved-workspace-roots, project-order).
  2. For each path, checks whether it still exists on disk (test -d).
  3. For paths that no longer exist: drops them from the arrays.
  4. (Optional, behind a flag like --prune-sessions) walks ~/.codex/sessions/**/rollout-*.jsonl and ~/.codex/archived_sessions/rollout-*.jsonl, reads the first JSONL line to extract payload.cwd, and deletes rollout files whose cwd no longer exists on disk.
  5. Dry-run by default; require --apply to mutate.
  6. Backs up ~/.codex/.codex-global-state.json before writing (there's already a .bak convention — append .bak with a timestamp or roll the existing one).
  7. 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 fix project-order).
  • Honor $CODEX_HOME instead 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.