Use this skill when the user wants to inspect, search, export, verify, clean up, delete, restore, or purge local Codex sessions stored under a Codex root suc...
--- name: codex-sessions-manager description: Use this skill when the user wants to inspect, search, export, verify, clean up, delete, restore, or purge local Codex sessions stored under a Codex root such as ~/.codex. metadata: source: https://github.com/1939869736luosi/codex-sessions-manager --- # Codex Sessions Manager ## Overview This skill manages local Codex sessions through the `codex-sessions` toolkit. Use it when the user wants to work with local Codex conversation history instead of the current live conversation. This repository provides: - a Node / TypeScript CLI - a local stdio MCP server - this Skill entrypoint The project is not a UI product, TUI, detail page, incremental scanner, or automatic cleanup service. ## Setup Install the CLI before using fallback commands: ```bash npm install -g codex-sessions-manager ``` This provides: ```text codex-sessions codex-sessions-mcp ``` For local development, build the repository first: ```bash cd <path-to-codex-sessions-repo> npm install npm run build ``` The default Codex root is: ```text ~/.codex ``` Use `--root <path-to-codex-root>` when working with another Codex root. ## When To Use Use this skill for requests like: - "List my recent Codex sessions" - "Find sessions for this project" - "Show this session" - "Find side conversations for this session" - "Export this session" - "Preview deleting these sessions" - "Move these sessions to trash" - "Restore this trash entry" - "Purge this trash entry" - "Verify whether this session is fully removed" - "Inspect the Codex root before deleting or restoring" - "Clean stale JSONL indexes" Do not use this skill for: - generic ChatGPT history questions - non-Codex chat clients - editing the current live conversation - automatic cleanup schedules - provider or model repair ## Preferred Order ### 1. Prefer MCP first If the `codex-sessions` MCP server is available in the current agent session, use these tools: - `inspect_root` - `list_sessions` - `list_projects` - `get_session` - `export_session_backup` - `preview_delete_sessions` - `delete_sessions` (requires `confirm=true` to execute; pass `trash=true` for recoverable deletion) - `list_trash` - `restore_sessions` (requires `confirm=true`) - `purge_trash` (requires `confirm=true`) - `cleanup_session_indexes` (requires `confirm=true` to rewrite JSONL indexes) - `cleanup_stale_indexes` (requires `confirm=true` to rewrite JSONL indexes) - `verify_sessions` Use MCP tools first. CLI is the fallback when MCP is unavailable or blocked. For session lookup, narrow in this order: 1. project 2. status 3. updated / created time 4. preview or `get_session` For project-aware listing, pass `project` to `list_sessions` or use `groupBy="project"`. For time filters, pass `updatedAfter`, `updatedBefore`, `createdAfter`, or `createdBefore`. Date-only filters use the local calendar day. Timezone-less datetime strings must be rejected. ### 2. Fall back to CLI Prefer the installed CLI: ```bash codex-sessions doctor --root <path-to-codex-root> codex-sessions doctor --root <path-to-codex-root> --json codex-sessions list --root <path-to-codex-root> --limit 20 codex-sessions list --root <path-to-codex-root> --project TEXT codex-sessions list --root <path-to-codex-root> --group-by project codex-sessions list --root <path-to-codex-root> --updated-after 2026-04-01 --updated-before 2026-04-30 codex-sessions projects --root <path-to-codex-root> codex-sessions show <session-id> --root <path-to-codex-root> codex-sessions export <session-id> --root <path-to-codex-root> --output ./backup.json codex-sessions delete <session-id...> --root <path-to-codex-root> codex-sessions delete <session-id...> --root <path-to-codex-root> --yes codex-sessions delete <session-id...> --root <path-to-codex-root> --trash codex-sessions delete <session-id...> --root <path-to-codex-root> --trash --yes codex-sessions trash-list --root <path-to-codex-root> codex-sessions restore <trash-id-or-session-id> --root <path-to-codex-root> codex-sessions restore <trash-id-or-session-id> --root <path-to-codex-root> --yes codex-sessions purge <trash-id-or-session-id> --root <path-to-codex-root> codex-sessions purge <trash-id-or-session-id> --root <path-to-codex-root> --yes codex-sessions cleanup-index <session-id...> --root <path-to-codex-root> codex-sessions cleanup-index <session-id...> --root <path-to-codex-root> --yes codex-sessions cleanup-stale --root <path-to-codex-root> codex-sessions cleanup-stale --root <path-to-codex-root> --yes codex-sessions verify <session-id...> --root <path-to-codex-root> ``` When working from a cloned repository instead, run commands from the built repository: ```bash cd <path-to-codex-sessions-repo> ``` Commands: ```bash node dist/cli/index.js doctor --root <path-to-codex-root> node dist/cli/index.js doctor --root <path-to-codex-root> --json node dist/cli/index.js list --root <path-to-codex-root> --limit 20 node dist/cli/index.js list --root <path-to-codex-root> --project TEXT node dist/cli/index.js list --root <path-to-codex-root> --group-by project node dist/cli/index.js list --root <path-to-codex-root> --updated-after 2026-04-01 --updated-before 2026-04-30 node dist/cli/index.js projects --root <path-to-codex-root> node dist/cli/index.js show <session-id> --root <path-to-codex-root> node dist/cli/index.js export <session-id> --root <path-to-codex-root> --output ./backup.json node dist/cli/index.js delete <session-id...> --root <path-to-codex-root> node dist/cli/index.js delete <session-id...> --root <path-to-codex-root> --yes node dist/cli/index.js delete <session-id...> --root <path-to-codex-root> --trash node dist/cli/index.js delete <session-id...> --root <path-to-codex-root> --trash --yes node dist/cli/index.js trash-list --root <path-to-codex-root> node dist/cli/index.js restore <trash-id-or-session-id> --root <path-to-codex-root> node dist/cli/index.js restore <trash-id-or-session-id> --root <path-to-codex-root> --yes node dist/cli/index.js purge <trash-id-or-session-id> --root <path-to-codex-root> node dist/cli/index.js purge <trash-id-or-session-id> --root <path-to-codex-root> --yes node dist/cli/index.js cleanup-index <session-id...> --root <path-to-codex-root> node dist/cli/index.js cleanup-index <session-id...> --root <path-to-codex-root> --yes node dist/cli/index.js cleanup-stale --root <path-to-codex-root> node dist/cli/index.js cleanup-stale --root <path-to-codex-root> --yes node dist/cli/index.js verify <session-id...> --root <path-to-codex-root> ``` ## Safety Rules - Run MCP `inspect_root` or CLI `doctor` before delete, restore, purge, or cleanup when Codex storage may have changed. - Treat delete, restore, purge, and cleanup as dangerous write paths. - Always preview before destructive actions unless the user has already clearly confirmed execution. - CLI `delete` without `--yes` is preview-only. - MCP `delete_sessions` without `confirm=true` is preview-only. - Permanent delete remains available for compatibility. - Prefer recoverable deletion with CLI `--trash --yes` or MCP `trash=true, confirm=true`. - `delete --trash` without `--yes` only previews moving sessions to trash. - `restore` and `purge` require `--yes` in CLI mode. - MCP `restore_sessions` and `purge_trash` require `confirm=true`. - Restore refuses live session conflicts and SQLite key conflicts. There is no force overwrite mode. - `purge` removes only the trash entry and must not touch live sessions. - `cleanup-index` and `cleanup-stale` rewrite `session_index.jsonl` and `history.jsonl`. They do not delete raw files or SQLite rows, but they still require `--yes`. - MCP `cleanup_session_indexes` and `cleanup_stale_indexes` require `confirm=true` to rewrite JSONL indexes. - Global-state cleanup is limited to known structured keys. - Unknown global-state references are warnings only. Do not edit or delete unknown keys automatically. - If `verify`, `doctor`, or `inspect_root` reports warnings, tell the user. Do not claim the root is fully clean. - Do not output chat content when reporting doctor, verify, or global-state warnings. ## Side Conversations Codex `/side` creates an ephemeral side conversation with a separate transcript. In local storage, it can appear as a separate child thread linked to a parent thread. When a user asks about side conversations: - Treat the parent thread and side child thread as separate sessions with separate transcripts. - Search, show, export, delete, trash, restore, or verify the child thread by its own session ID. - Do not assume deleting, exporting, or summarizing a parent thread also handles its side child threads. - If the user wants a parent thread and its side conversations handled together, identify the child thread IDs first, preview all selected IDs together, and only then run any confirmed write operation. - Current CLI/MCP behavior does not automatically recurse from parent to side child threads. ## Response Style - For list requests: show session ID, updated time, size, project, status, and readable title. - For project requests: show project name/path, session count, status counts, latest updated time, and total size. - For show requests: summarize the session and include key metadata. - For side-conversation requests: distinguish parent thread ID and child thread ID, and say whether the requested action covers one or both. - For delete requests: explain whether this is preview-only, permanent delete, or recoverable trash delete. - For trash requests: distinguish moved to trash, restored, and purged. - For restore conflicts: explain that the live session already exists and identify conflicting surfaces when available. - For verify requests: report whether files, JSONL rows, SQLite rows, shell snapshots, global-state refs, or warnings remain. - For doctor / inspect requests: report OK, missing, and warning states without printing chat content. - For unknown global-state refs: report key path and count, not full global state content. ## Non-Goals Do not build or imply support for: - UI - TUI - detail pages - incremental project scanning - automatic stale cleanup - automatic trash purge - force overwrite restore - automatic editing of unknown global-state keys - non-Codex chat cleanup
don't have the plugin yet? install it then click "run inline in claude" again.
use this skill to inspect, search, export, verify, clean up, delete, restore, or purge local codex sessions stored under a codex root (default: ~/.codex). run it when the user wants to work with codex conversation history instead of the current live conversation. the skill provides both an MCP server (preferred) and a CLI fallback for session management operations including preview-only modes, recoverable trash deletion, and permanent purge.
codex root directory
~/.codex--root <path-to-codex-root> to all CLI commands or root param to MCP toolsMCP server availability
CODEX_SESSIONS_MCP (optional, indicates MCP server is running)codex-sessions MCP server is configured in the current agent sessionCLI tool installation
codex-sessions-managernpm install -g codex-sessions-managercodex-sessions and codex-sessions-mcpnpm install && npm run build, then use node dist/cli/index.js from repo rootsession identifiers
list_sessions, list_trash, or list_projects callsdate/time filters (CLI and MCP)
updatedAfter, updatedBefore, createdAfter, createdBeforeproject names or paths (optional)
list_sessions --project TEXT or MCP list_sessions(project=TEXT)input: codex root path (default ~/.codex)
action: run MCP inspect_root or CLI doctor before any destructive operation (delete, restore, purge, cleanup).
MCP:
inspect_root(root="~/.codex")
CLI:
codex-sessions doctor --root ~/.codex
codex-sessions doctor --root ~/.codex --json
output: status report (OK, missing, or warning states). list of sessions, projects, trash entries, and global-state references. no chat content in output.
edge case: if warnings appear, report them to user and do not proceed with destructive operations until user confirms understanding.
input: codex root, optional project name, optional time filters, optional grouping, optional limit
action: retrieve session list with metadata (ID, updated time, size, project, status, title).
prefer MCP:
list_sessions(root="~/.codex", limit=20)
list_sessions(root="~/.codex", project="my-project")
list_sessions(root="~/.codex", groupBy="project")
list_sessions(root="~/.codex", updatedAfter="2026-04-01", updatedBefore="2026-04-30")
fall back to CLI:
codex-sessions list --root ~/.codex --limit 20
codex-sessions list --root ~/.codex --project "my-project"
codex-sessions list --root ~/.codex --group-by project
codex-sessions list --root ~/.codex --updated-after 2026-04-01 --updated-before 2026-04-30
output: list of sessions with ID, updated timestamp, size bytes, project name, status, and readable title.
edge case (empty results): if no sessions match, report "no sessions found" with applied filters; suggest user broaden filter or check if codex root is correct.
input: codex root
action: retrieve project summary (name/path, session count, status distribution, latest updated time, total size).
prefer MCP:
list_projects(root="~/.codex")
fall back to CLI:
codex-sessions projects --root ~/.codex
output: project name/path, session count, counts by status, latest updated timestamp, total size bytes.
input: codex root, session ID
action: retrieve full session metadata and summary (do not output full chat transcript).
prefer MCP:
get_session(root="~/.codex", sessionId="SESSION_ID")
fall back to CLI:
codex-sessions show SESSION_ID --root ~/.codex
output: session ID, created/updated timestamps, project, status, size, title, and summary of conversation (no raw chat content).
edge case (not found): if session ID does not exist, report "session not found"; suggest user search with list_sessions first.
input: codex root, session ID, output file path
action: export session as JSON backup.
prefer MCP:
export_session_backup(root="~/.codex", sessionId="SESSION_ID")
fall back to CLI:
codex-sessions export SESSION_ID --root ~/.codex --output ./backup.json
output: JSON file written to disk. include file path and file size in success response.
edge case (network timeout): if export hangs, kill the process after 30 seconds and report "export timed out; try again or use smaller session".
input: codex root, one or more session IDs, trash flag (true for recoverable, false/absent for permanent)
action: show which sessions will be deleted and whether delete is permanent or recoverable; do not execute deletion.
prefer MCP:
preview_delete_sessions(root="~/.codex", sessionIds=["ID1", "ID2"], trash=false)
preview_delete_sessions(root="~/.codex", sessionIds=["ID1", "ID2"], trash=true)
fall back to CLI:
codex-sessions delete ID1 ID2 --root ~/.codex
codex-sessions delete ID1 ID2 --root ~/.codex --trash
output: list of sessions to be deleted, delete type (permanent or trash), and file/row counts affected. do not include chat content.
edge case (multiple sessions): if user selected >10 sessions, confirm count and ask user to review before proceeding to step 7.
input: codex root, one or more session IDs, trash flag, confirmation flag (true to execute)
action: delete sessions permanently or move to trash (recoverable). only execute if confirm=true (MCP) or --yes flag (CLI).
prefer MCP:
delete_sessions(root="~/.codex", sessionIds=["ID1"], trash=false, confirm=true)
delete_sessions(root="~/.codex", sessionIds=["ID1"], trash=true, confirm=true)
fall back to CLI:
codex-sessions delete ID1 --root ~/.codex --yes
codex-sessions delete ID1 --root ~/.codex --trash --yes
output: confirmation of deleted session IDs, type (permanent or trash), and count of files/rows removed.
edge case (trash conflicts): if session already exists in trash, report conflict and skip; do not overwrite existing trash entry.
input: codex root
action: retrieve trash contents (trashed session IDs, timestamps, sizes).
prefer MCP:
list_trash(root="~/.codex")
fall back to CLI:
codex-sessions trash-list --root ~/.codex
output: list of trash entries with session ID, trashed timestamp, size, and project.
edge case (empty trash): if no trash entries, report "trash is empty".
input: codex root, trash ID or original session ID, confirmation flag
action: restore trashed session to live storage. only execute if confirm=true (MCP) or --yes flag (CLI).
prefer MCP:
restore_sessions(root="~/.codex", trashIds=["TRASH_ID"], confirm=true)
fall back to CLI:
codex-sessions restore TRASH_ID --root ~/.codex --yes
output: confirmation of restored session ID, restored timestamp, and file/row counts written.
edge case (live conflict): if a live session with the same ID already exists, restore refuses the operation and reports "live session already exists"; no force overwrite mode available.
edge case (SQLite key conflict): if SQLite row with same key exists, restore refuses operation; report conflict and suggest user verify or inspect root first.
input: codex root, trash ID, confirmation flag
action: permanently delete trash entry (cannot be recovered). only execute if confirm=true (MCP) or --yes flag (CLI). does not touch live sessions.
prefer MCP:
purge_trash(root="~/.codex", trashIds=["TRASH_ID"], confirm=true)
fall back to CLI:
codex-sessions purge TRASH_ID --root ~/.codex --yes
output: confirmation of purged trash ID and file counts removed.
edge case (not in trash): if trash ID not found, report "trash entry not found"; suggest user list trash first.
input: codex root, one or more session IDs, confirmation flag
action: rewrite session_index.jsonl for selected sessions. does not delete raw files or SQLite rows. only execute if confirm=true (MCP) or --yes flag (CLI).
prefer MCP:
cleanup_session_indexes(root="~/.codex", sessionIds=["ID1"], confirm=true)
fall back to CLI:
codex-sessions cleanup-index ID1 --root ~/.codex --yes
output: confirmation of sessions reindexed, files rewritten, and warnings resolved.
edge case (stale index): if index is already clean, report "no stale entries found" and skip rewrite.
input: codex root, confirmation flag
action: scan and rewrite session_index.jsonl and history.jsonl to remove stale entries. only execute if confirm=true (MCP) or --yes flag (CLI).
prefer MCP:
cleanup_stale_indexes(root="~/.codex", confirm=true)
fall back to CLI:
codex-sessions cleanup-stale --root ~/.codex --yes
output: count of stale entries removed, files rewritten, and warnings resolved.
edge case (no stale entries): if no stale entries found, report "no cleanup needed".
input: codex root, one or more session IDs
action: check whether session is completely removed from files, JSONL rows, SQLite rows, shell snapshots, and global-state references. report any remaining artifacts.
prefer MCP:
verify_sessions(root="~/.codex", sessionIds=["ID1"])
fall back to CLI:
codex-sessions verify ID1 --root ~/.codex
output: verification status (fully removed, partial artifacts, or warnings). list any remaining files, JSONL rows, SQLite rows, shell snapshots, or global-state references by key path.
edge case (unknown global-state refs): if unknown global-state keys exist, report key path and count only (not full content). treat as warnings; do not edit or delete automatically.
if MCP server is available in agent session:
inspect_root, list_sessions, get_session, delete_sessions with confirm=true, etc.).else (MCP unavailable or blocked):
codex-sessions list, codex-sessions delete ... --yes, etc.).node dist/cli/index.js from cloned repo instead.if user wants to delete sessions:
trash=true in MCP, --trash --yes in CLI) over permanent delete.if user wants to restore from trash:
confirm=true (MCP) or --yes (CLI).if user wants to purge trash:
confirm=true (MCP) or --yes (CLI).if user asks about side conversations:
if user wants to filter sessions by time:
if verify, doctor, or inspect_root reports warnings:
if session not found:
if trash entry conflicts with live session (same ID):
if cleanup-index or cleanup-stale finds no stale entries:
list operations: JSON array or formatted table with columns: session ID, updated timestamp (ISO 8601), size bytes, project name, status, readable title. example:
ID: abc123 | Updated: 2026-04-15T14:22:00Z | Size: 45KB | Project: my-project | Status: active | Title: "Debug session"
project operations: JSON array or formatted table with columns: project name/path, session count, status distribution (e.g., "10 active, 2 archived"), latest updated timestamp, total size bytes.
show operations: structured object with: session ID, created timestamp, updated timestamp, project, status, size bytes, readable title, conversation summary (no raw chat content).
export operations: JSON file written to specified output path. file contains full session transcript. response includes output file path and file size bytes.
preview delete / verify operations: plain text or JSON report with: list of session IDs, operation type (permanent delete / trash move / restore / purge), affected file count, affected JSONL row count, affected SQLite row count. include shell snapshot refs and global-state refs if present. no chat content.
delete / restore / purge / cleanup operations: confirmation message with: operation type, session IDs affected, timestamp of operation, file/row counts changed. example:
✓ Moved 2 sessions to trash: abc123, def456 | Files: 8 | Rows: 24 | Time: 2026-04-15T14:22:00Z
trash operations: list with: trash ID, original session ID, trashed timestamp, size bytes, project name. or confirmation of restore/purge with same format as delete/restore/purge output above.
error responses: plain text error message with: operation attempted, error code, root cause, suggested next step. example:
Error: Session not found (session_id=xyz789). Run 'list_sessions' to search by project or time range.
user knows the skill worked when:
--trash was used.