Codex local cleanup
Clean stale Codex Desktop project/thread metadata under ~/.codex with backup-first safety checks.
npx -y skills add cku3987/codex-local-cleanup-skill --skill codex-local-cleanupAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Clean local Codex Desktop metadata under $CODEX_HOME or ~/.codex by safely identifying mobile-visible stale projects, non-active project threads outside saved project roots, archived threads, deleted workspace cwd entries, session JSONL files, thread indexes, global state, config trust entries, and SQLite rows; always back up first, keep saved projects/projectless chats/current thread unless explicitly requested, and verify with read-only checks before reporting.
SKILL.md
8.8 KB, as published. Nobody here has run it
Codex Local Cleanup
Use this skill when the user wants to clean local Codex Desktop remnants in ~/.codex, such as deleted project traces, stale archived threads, old project trust entries, or mobile-visible sidebar clutter.
Safety Rules
- Treat
~/.codexas live application state. Do not modify it until the target set is explicit and backed up. - Never delete or rewrite
auth.json,installation_id,skills/,plugins/,automations/,.sandbox-secrets/, or user source projects. - Never clean the current active thread, even if its cwd is projectless or outside saved projects.
- Do not remove general chat threads unless the user explicitly asks for them.
- Prefer narrow cleanup scopes:
- non-projectless project threads outside saved project roots
- stale archived threads outside saved project roots
- deleted cwd threads
- dead
[projects.'...']trust blocks inconfig.toml
- If a title or preview contains secrets, do not repeat the secret in chat output.
- Before deleting files or DB rows, verify resolved paths stay under
~/.codex/sessionsor~/.codex/archived_sessions.
Data Sources
Use local Codex files only:
.codex-global-state.json: saved project roots, project order, pinned projects, prompt history, thread permissions,projectless-thread-ids,thread-projectless-output-directories,thread-workspace-root-hints,queued-follow-ups, and nestedelectron-persisted-atom-stateUI caches.state_*.sqlite: thread metadata, cwd, archived flag, rollout path,source,thread_source, and agent/subagent fields.logs_*.sqlite: diagnostic logs.session_index.jsonl: thread index.sessions/**/rollout-*.jsonl: active/non-archived conversation files.archived_sessions/rollout-*.jsonl: archived conversation files.config.toml: trusted project roots.
If both top-level .codex/state_*.sqlite and legacy .codex/sqlite/state_*.sqlite exist, compare migration count and modified time first. Prefer the current active DB for normal cleanup. If mobile still shows entries that are absent from the active DB, inspect legacy .codex/sqlite/state_*.sqlite and .codex/sqlite/logs_*.sqlite as an additional mobile-visible stale source before reporting that cleanup is complete.
Classification
Saved project roots come from .codex-global-state.json key electron-saved-workspace-roots.
Maintain by default:
- Threads whose
cwdequals or is under a saved project root. - The current thread.
- Saved project roots listed in
electron-saved-workspace-roots,project-order,pinned-project-ids, orelectron-workspace-root-labels. If Desktop shows a renamed project but mobile shows the raw folder name, treat that as a label/display-sync issue, not stale metadata. - Projectless/general chat threads unless the user explicitly asks to remove them.
- Threads listed in
projectless-thread-ids,thread-projectless-output-directories, orthread-workspace-root-hintsunless the user explicitly asks to remove projectless/general chat state. - Subagent threads whose
thread_sourceissubagent, unless their parent thread is also being removed and the user explicitly included spawned agent state. - Archived threads under saved project roots unless the user asks to prune those archives too.
Cleanup candidates:
- Non-projectless, non-subagent threads whose
cwdis outside saved project roots, when the user asks to keep only current saved/active projects. - Threads with
cwdpaths that do not exist. - Archived threads whose
cwdis outside saved project roots, excluding projectless/general chat markers unless the user asked to prune those too. - Legacy
.codex/sqlite/state_*.sqliterows that match the same cleanup criteria when mobile still shows entries already removed from the active top-level DB. config.toml[projects.'...']blocks for paths that do not exist.config.toml[projects.'...']blocks outside saved project roots, when cleaning non-active projects. Preserve current projectless workspace trust entries unless explicitly asked to remove general chat state.
For Windows paths, normalize \\?\ prefixes, slash direction, trailing slashes, and case before comparing paths. Do not rely on os.path.commonpath alone if path forms are mixed; compare normalized strings with root == cwd or cwd.startswith(root + "\\").
Workflow
- Read
.codex-global-state.jsonandstate_*.sqlitein read-only mode. - Print a concise candidate summary: count, cwd, archived count, whether each path exists, and whether it is under a saved project root.
- Confirm the cleanup scope from the user's instruction. If the user says "active/saved projects only", target non-projectless, non-subagent threads outside
electron-saved-workspace-rootswhile preserving projectless chats, generated Codex workspaces, and the current thread. - Create a timestamped backup under the current workspace
work/directory:- target list JSON
- consistent SQLite backups using
sqlite3.Connection.backup - raw copies of
.codex-global-state.json,.bak,session_index.jsonl, andconfig.toml - target rollout JSONL files
- pre-cleanup size manifest for target rollout files, metadata files, and modified SQLite DB files
- Remove only validated target rollout files.
- Remove matching
session_index.jsonllines. - Remove matching prompt-history, thread-permission, unread-thread, thread-client-id, projectless, workspace-hint, and follow-up keys from
.codex-global-state.jsonand.bak. - Delete target rows from active
state_*.sqlitetables, and legacy.codex/sqlite/state_*.sqlitetables when included, in dependency order:thread_dynamic_toolsthread_spawn_edgesagent_job_itemsthreads
- Delete matching active and included legacy
logs_*.sqliterows bythread_id. Avoid broad text deletes that would erase the current cleanup thread's diagnostic logs unless the user explicitly asks. - For
config.toml, remove only the selected[projects.'...']blocks and their body lines. - Run SQLite checkpoint/VACUUM after writes when practical.
- Record post-cleanup sizes for modified files and DBs.
- Verify before reporting success.
Verification
Run checks that directly prove the result:
PRAGMA integrity_checkfor modified SQLite DBs.- Target thread IDs no longer exist in
state_*.sqlite. - Target rollout files no longer exist.
- Target IDs no longer appear in
session_index.jsonl. - Target IDs no longer appear in
.codex-global-state.jsonor.bak, except when the current conversation naturally mentions them and that scope was intentionally preserved. Check nestedelectron-persisted-atom-statekeys such as heartbeat permissions, unread thread IDs, and thread client IDs. - Archived-outside-active count is zero when cleaning outside-project archives.
- Outside-active non-projectless thread count is zero when cleaning mobile-visible non-active projects.
config.tomloutside-active non-projectless trust block count is zero when cleaning non-active projects.- Dead
config.tomlproject blocks are zero when cleaning missing trust entries. codex_app.list_threadssearches for removed titles or paths return no removed target threads when the app tool is available.
Size Accounting
Report cleanup size conservatively:
- Directly reclaimed bytes: sum of deleted rollout JSONL files and other deleted files that no longer exist after cleanup.
- SQLite reclaimed bytes: report DB file size delta before/after only when measured. If rows were deleted but the DB file did not shrink because pages/WAL are reused, report the deleted row counts separately instead of claiming reclaimed bytes.
- Backup size: total bytes written under the backup directory.
- Net disk change: direct reclaimed bytes minus backup size, when both are known. Make clear that backups intentionally increase disk usage until the user deletes them.
- Human-readable units: include bytes and KiB/MiB for non-trivial values.
Reporting
Report in Korean unless the user asks otherwise. Include:
- cleanup scope used
- number of threads removed
- files/DBs touched
- backup directory
- directly reclaimed size, backup size, and DB row/file-size notes
- verification results
- any known residual traces, especially current-thread diagnostic logs that were intentionally preserved
Keep the final answer concise and avoid exposing secrets from historical titles or previews.