English | 简体中文
Recover missing Codex Desktop or Codex CLI conversations from local metadata in minutes. No API-key changes, no cloud scraping, no guesswork: diagnose first, dry-run by default, back up before every repair.
Copy this prompt into Codex:
My Codex sessions disappeared. Use this skill https://github.com/wimi321/codex-session-recovery-skill to recover my Codex sessions.
Codex can use the skill to inspect your local ~/.codex state, explain what it
finds, dry-run the safest repair, apply it with backups, and refresh the legacy
session index if needed.
- One prompt to start: ask Codex to use the skill and recover the sessions.
- Readable diagnosis:
diagnoseshows counts, provider hints, stale index state, and the likely next command. - Safe defaults: repair commands are dry-run unless you add
--apply. - Automatic backups: applied repairs write timestamped backups under
~/.codex/recovery-backups/. - Credential-safe: the tool never writes
auth.json, API keys, OAuth tokens, browser cookies, or provider secrets.
When Codex history vanishes, the data is often not gone. It may be hidden by local metadata that no longer matches the current app state:
- Provider/profile mismatch, such as old
openaisessions under a current local provider likecliproxyapi. - Reverse provider repairs, where most historical rows suggest one target but the newest Desktop thread shows the app is currently using another provider.
- Sidebar filters scoped to a stale workspace or collapsed group.
- A stale legacy
session_index.jsonl. - Real conversations marked as empty by a drifted
has_user_eventflag. - SQLite rows and rollout JSONL metadata drifting out of sync.
This repository packages that recovery knowledge into a Codex skill plus a deterministic Python script that diagnoses first, backs up before repair, and keeps credential material untouched.
| Symptom | Likely cause | Supported repair |
|---|---|---|
| Sidebar is empty after restart | UI state or provider filter | diagnose, then repair-ui-state or repair-provider |
Old sessions exist in ~/.codex/sessions but not in Desktop |
model_provider mismatch |
repair-provider |
| SQLite shows visible threads but app lists only current sessions | profile/provider mismatch | repair-provider --to auto |
| SQLite rows exist but visible user thread count is zero | has_user_event drift |
repair-user-events, then rebuild-index |
| Legacy picker misses sessions | stale session_index.jsonl |
rebuild-index |
| Unsure what happened | unknown local state issue | diagnose plus references/incident-patterns.md |
This tool is for local Codex state. It does not recover ChatGPT web history, cloud account history, deleted files, or data that no longer exists on disk.
The recovery script is intentionally conservative:
- Never writes
~/.codex/auth.json. - Does not change API keys, OAuth tokens, browser cookies, or provider secrets.
- Does not upload local session data anywhere.
- Repairs are dry-run by default.
--applycreates timestamped backups in~/.codex/recovery-backups/.- Rollout repairs parse JSON and modify only the first
session_metaline after validating the session id. - Provider repair updates both SQLite and rollout metadata so the fix survives app restarts.
- User-event repair only updates
threads.has_user_eventafter findingfirst_user_messageor real user-authored rollout text.
Clone the repository:
git clone https://github.com/wimi321/codex-session-recovery-skill.git
cd codex-session-recovery-skillRun a diagnosis:
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py diagnoseIf the diagnosis shows old interactive sessions under the wrong provider, run a dry-run provider repair:
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py repair-provider --from openai --to autoIf diagnose says the current provider cannot be resolved from config.toml,
check the Latest visible Desktop thread block. A freshly opened blank Desktop
thread is often the best provider hint. Use that provider as --to only after a
dry-run confirms the direction:
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py repair-provider --from cliproxyapi --to openai --source any --include-emptyApply only when the dry-run scope is correct:
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py repair-provider --from openai --to auto --applyIf diagnose shows visible rows but zero visible user threads, dry-run and
apply the user-event flag repair, then rebuild the legacy index:
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py repair-user-events
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py repair-user-events --apply
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py rebuild-index --applyThen restart or refresh Codex Desktop and run diagnose again.
Link the skill into your local Codex skills directory:
mkdir -p ~/.codex/skills
ln -s "$PWD/skills/codex-session-recovery" ~/.codex/skills/codex-session-recoveryThen ask Codex:
Use $codex-session-recovery to diagnose why my Codex Desktop sessions disappeared.
The skill teaches Codex when to use the script, how to interpret the output, and which safety boundaries must never be crossed.
Read-only inspection of local Codex state:
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py diagnoseReports:
- Codex home path.
- Active profile and resolved provider from
config.toml. state_5.sqlitethread counts by source/provider/archive state.- The latest visible Desktop thread provider, which is used as a provider hint
when
config.tomlhas no active profile. - Provider mismatch candidates.
- User-event flag drift candidates, where a real conversation is marked as
has_user_event = 0. - Sidebar state keys.
session_index.jsonlentry count.- Suggested next command.
Repairs sessions hidden by provider metadata mismatch:
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py repair-provider --from openai --to auto
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py repair-provider --from openai --to auto --applyUseful options:
--to autoresolves the current provider from the active Codex profile.- If
config.tomlhas no active profile,--to autofalls back to the latest visible Desktop thread provider and prints the source of that inference. --source vscodetargets interactive Desktop sessions. This is the default.--source anybroadens the scope after you verify the dry-run output.--include-archivedincludes archived sessions.--include-emptyincludes threads without user events.--codex-home <path>targets a non-default Codex home.
Repairs real conversations that are present in SQLite but marked as empty:
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py repair-user-events
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py repair-user-events --applyThis backs up state_5.sqlite and changes only threads.has_user_event for
rows where the script finds either user-authored first_user_message text or
user-authored rollout JSONL text. Synthetic <environment_context> messages do
not count as user evidence. After applying, run rebuild-index --apply if
session_index.jsonl still misses recovered entries.
Resets stale sidebar filters and collapsed groups:
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py repair-ui-state
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py repair-ui-state --applyThis backs up .codex-global-state.json, sets the sidebar to all workspaces,
uses the recent view, and clears collapsed sidebar groups.
Regenerates the legacy session_index.jsonl from visible database rows:
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py rebuild-index
python3 skills/codex-session-recovery/scripts/codex_session_recovery.py rebuild-index --applyThe common failure pattern:
~/.codex/config.tomlnow points at a custom or local provider.- Old interactive sessions still have
model_provider = openai. - Codex Desktop filters the sidebar to the current provider.
- Editing only SQLite is not durable, because rollout JSONL metadata can be scanned again on restart.
repair-provider updates both durable locations:
threads.model_providerin~/.codex/state_5.sqlite.payload.model_provideron the firstsession_metaline in each matching rollout JSONL file.
Before writing, it confirms the rollout file exists, the first line is
session_meta, the session id matches the database row, and the current rollout
provider equals the expected --from value.
Another real failure mode is state_5.sqlite retaining the old conversation
rows and rollout paths while threads.has_user_event is 0. Codex Desktop can
then treat the rows as blank threads and hide them from normal history views,
even when title, first_user_message, and the rollout JSONL clearly show real
conversation content.
repair-user-events looks only for conservative evidence:
- User-authored
threads.first_user_messagetext, or - A rollout JSONL user message with real user-authored text.
It ignores synthetic <environment_context> payloads, backs up the SQLite
database, and updates only has_user_event for the matching rows. It does not
rewrite rollout files.
Codex Session Recovery diagnosis
=======================================
Codex home: /Users/example/.codex
Safety: auth.json/API keys/OAuth tokens are not read or written
Active profile: cliproxyapi
Current provider: cliproxyapi
threads total: 555
visible threads: 554
visible user threads: 554
provider mismatch candidates: 94
rollout provider mismatches: 94
If the dry-run output matches the sessions you want to recover, add --apply.
Do not choose the target provider only by counting historical rows. In a later
real recovery, a first repair moved old openai rows to cliproxyapi because
that was the dominant provider bucket. The sidebar still did not recover. The
decisive clue was a newly opened Desktop thread with model_provider = openai;
that was the provider the current app was filtering for.
The improved workflow is:
- Run
diagnose --source any --include-empty. - Compare the provider counts with the
Latest visible Desktop threadhint. - Dry-run the direction that moves hidden rows toward the latest Desktop provider.
- Apply only after every rollout action is safe.
- Run
rebuild-index --applyif a legacy picker still shows stale results.
.
├── README.md
├── README.zh-CN.md
├── CHANGELOG.md
├── CONTRIBUTING.md
├── SECURITY.md
├── .github/workflows/validate.yml
├── skills/codex-session-recovery/
│ ├── SKILL.md
│ ├── agents/openai.yaml
│ ├── references/incident-patterns.md
│ └── scripts/codex_session_recovery.py
└── tests/test_codex_session_recovery.py
Run validation locally:
python3 -m py_compile skills/codex-session-recovery/scripts/codex_session_recovery.py
python3 -m unittest discover -s testsIf you have Codex's skill-creator validator installed:
python3 ~/.codex/skills/.system/skill-creator/scripts/quick_validate.py skills/codex-session-recovery- Add more incident patterns as the community reports them.
- Add optional JSON output for scripted diagnostics.
- Add restoration guidance for backup directories.
- Expand multilingual documentation as contributors volunteer translations.
Issues and pull requests are welcome. Please read CONTRIBUTING.md and SECURITY.md before changing recovery behavior. The safety bar is deliberately high because this project touches local conversation history.
MIT. See LICENSE.
This is a community recovery tool for local Codex metadata. Review dry-run output before applying repairs, and keep backups until you have verified that your history is visible again.