codex-history-recovery
Skill0 starsChanged 5 months agoMITView on GitHub
Diagnose and repair Codex Desktop local history/sidebar state when chats, projects, project labels, project counts, or project history are missing, empty, duplicated, or scrambled. Use for local Codex history recovery involving ~/.codex state, state_5.sqlite, .codex-global-state.json, projectless-thread-ids, thread-workspace-root-hints, sidebar-project-thread-orders, model_provider=headroom, or after Headroom/provider experiments appear to hide Codex history.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- adjcjh777/agent-bus-skillstheir own version, first seen Nov 15, 2026
- Basic-XYZ/baku-skillstheir own version, first seen Jul 27, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- Basic-XYZ/baku-skills★ 2same name
- adjcjh777/agent-bus-skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 7 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Verify live state before changing anything:
- Distinctive: line 22
Read the JSON summary. Continue only when the intended shape is clear:
- Distinctive: line 58
Never apply while Codex Desktop is actively rewriting state unless the user accepts that a restart may be needed.
- Very specific: line 59
If legacyModelProviderRowsWouldChange or missing project assignments reappear immediately after applying, assume Codex Desktop rewrote …
- Very specific: line 60
Do not falsify updated_at / updated_at_ms to make an old Project appear in the renderer.
- Distinctive: line 61
Prefer dry-run first; the script is intentionally safe by default.
- Distinctive: line 62
Do not run destructive Git or app cleanup commands as part of history recovery.
- Very specific: line 63
If project roots look suspicious, read references/sidebar-state.md before applying.
- Distinctive: line 67
Check the current sidebar shape without changing files:
- Distinctive: line 79
Use a non-default Codex home:
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Codex History Recovery
Recommended installation:
npx skills add lifeodyssey/codex-history-recovery-skill --skill codex-history-recovery -g -a codex -yWorkflow
- Verify live state before changing anything:
node scripts/restore-codex-history.mjs- Read the JSON summary. Continue only when the intended shape is clear:
projectThreadOrdersAftershould matchprojectOrderAfter.projectThreadsMatchedshould be close toprojectThreadsAfter.projectThreadsUnmatchedshould be small or explainable.projectlessAftershould stay small. A huge value usually means the old broken "everything is Chats" state.activeModelProviderRowsWouldChangeandlegacyModelProviderRowsWouldChangeshould be0after a successful repair. If either comes back while Codex Desktop is still open, treat it as the app rewriting stale state and use the after-quit watcher instead of repeatedly applying live.projectHydrationRisksexplains Projects that have real threads in metadata/SQLite but may still showNo chatsbecause the renderer only hydrates a recent window. Treatpresent-but-not-hydratedas "data exists, UI did not mount it", not as missing history. Do not rewrite timestamps just to force old Projects into the recent window.
- Apply only after dry-run looks right:
node scripts/restore-codex-history.mjs --apply- Tell the user to fully quit Codex Desktop with
Cmd+Q, wait a few seconds, then reopen. The renderer may cache sidebar state until restart. When live state keeps reverting while Codex is open, run the after-quit watcher and confirm its log says it is waiting for Codex GUI to exit.
What The Script Fixes
- Copies visible legacy rows from
~/.codex/state_5.sqliteinto active~/.codex/sqlite/state_5.sqlitewhen needed. - Normalizes visible
model_provider='headroom'rows in both legacy~/.codex/state_5.sqliteand active~/.codex/sqlite/state_5.sqlite, plus session metadata, back toopenai. - Rebuilds
thread-workspace-root-hintsand object-shapedthread-project-assignments({ projectKind: "local", projectId, path, pendingCoreUpdate: false }) from each visible thread'scwd, walking upward to a real project marker such as.git,package.json, orpyproject.toml;AGENTS.md/CLAUDE.mdalone are not treated as project markers because broad history folders use them too. - Uses thread history text as extra evidence when
cwdis too broad: configured project roots mentioned in the thread can map broad sessions back to real projects. - Canonicalizes generated worktrees and missing old cwd values back to a unique matching project basename when possible; local aliases in
scripts/restore-codex-history.mjsare only a fallback for ambiguous moves. - Imports non-empty, non-subagent legacy rows even when
has_user_event=0, because some image generation/project tasks are represented that way. - Rebuilds
sidebar-project-thread-orders, which current Codex uses to populate each Project. - Removes project-backed threads from
projectless-thread-idsandsidebar-chat-thread-order, while preserving small true projectless chat sets. - Forces the flat project sidebar preference to
mode: "list"so Chats/Recent can show the full recent-thread list instead of only projectless threads. - Filters out empty
New chatplaceholders, emptyCodex Companion Task:placeholders, subagent rows,.claude-memobserver rows, and old helper boilerplate such as action-assessment and worker task prompts. - Keeps generic/app-owned roots like
/,~/Documents,/private/tmp, and.claude-memout of Projects. - Normalizes generated worktree/date-folder cwd values back to the clean project root when possible.
- Reports renderer hydration misses with per-project
top50,top100,top500, andnewestRankcounts so old-but-valid Projects can be distinguished from missing data. - Writes a backup under
~/.codex/backups/history-visible-index-<timestamp>/before applying.
Safety Rules
- Never apply while Codex Desktop is actively rewriting state unless the user accepts that a restart may be needed.
- If
legacyModelProviderRowsWouldChangeor missing project assignments reappear immediately after applying, assume Codex Desktop rewrote stale state while open. Armscripts/wait-for-codex-quit-and-restore.shor the local LaunchAgent, then have the userCmd+Qand reopen. - Do not falsify
updated_at/updated_at_msto make an old Project appear in the renderer. Old Projects with valid rows buttop50: 0are a Desktop hydration limitation, not recovered-history loss. - Prefer dry-run first; the script is intentionally safe by default.
- Do not run destructive Git or app cleanup commands as part of history recovery.
- If project roots look suspicious, read
references/sidebar-state.mdbefore applying.
Useful Commands
Check the current sidebar shape without changing files:
node scripts/restore-codex-history.mjsApply after Codex quits:
sh scripts/wait-for-codex-quit-and-restore.shUse a non-default Codex home:
CODEX_HOME=/path/to/.codex node scripts/restore-codex-history.mjsDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

